FasterTransformer icon indicating copy to clipboard operation
FasterTransformer copied to clipboard

Why is cublasMMWrapper operations protected by mutex

Open chenfucn opened this issue 2 years ago • 3 comments

It seems to me all cublas and cublaslt gemm and matmul operations are protected by a mutex. cublas library documents says its thread safe. Why is it necessary to protect these operations with mutex?

chenfucn avatar Oct 06 '22 00:10 chenfucn

From official document:

The library is thread safe and its functions can be called from multiple host threads, even with the same handle. When multiple threads share the same handle, extreme care needs to be taken when the handle configuration is changed because that change will affect potentially subsequent cuBLAS calls in all threads. It is even more true for the destruction of the handle. So it is not recommended that multiple thread share the same cuBLAS handle.

thread safe is only guaranteed when they don't share handle.

byshiue avatar Oct 06 '22 00:10 byshiue

Thanks! But why some of the cusparselt calls are not protected and some are?

chenfucn avatar Oct 06 '22 16:10 chenfucn

All GEMMs have mutexes except https://github.com/NVIDIA/FasterTransformer/blob/main/src/fastertransformer/utils/cublasMMWrapper.cc#L358, which is not used now. We will fix it ASAP.

byshiue avatar Oct 07 '22 00:10 byshiue