Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better cuBLAS handle management #1389

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ptrendx
Copy link
Member

@ptrendx ptrendx commented Jan 2, 2025

Description

Create only 1 (per thread) cublasLtHandle in order to not leak memory. We do not want to actually destroy the handle, since it would incur an implicit cudaDeviceSynchronize call (see cuBLAS docs).

Fixes #1372

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactor

Changes

  • Introduced a singleton manager for cuBLAS handles similar to the one used for cuDNN handles.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Member

@ksivaman ksivaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shenzhenghai
Copy link

May I have a question about the commit? If there is multiple devices invoke cublas_gemm(), it seems always use the same cublasLt handle?
The document mentioned "one cuBLASLt handle should be created for each device".

@shenzhenghai
Copy link

May I have a question about the commit? If there is multiple devices invoke cublas_gemm(), it seems always use the same cublasLt handle? The document mentioned "one cuBLASLt handle should be created for each device".

@ptrendx @ksivaman any comment on my concern? Thanks.

@ptrendx
Copy link
Member Author

ptrendx commented Jan 6, 2025

@shenzhenghai Yeah, if your usage is to have multiple devices per thread then you are correct - it would use the same handle, which is wrong. I don't necessarily like the fact that fixing this will require calling cudaGetDevice before every cuBLAS call - this adds overhead and the most typical usage by the DL Frameworks nowadays is 1 GPU per process. But I agree that the functional correctness is the most important - will submit a fix (also will fix the cuDNN handle management, since it has similar problem).

@ptrendx
Copy link
Member Author

ptrendx commented Jan 6, 2025

/te-ci

Signed-off-by: Przemek Tredak <[email protected]>
@ptrendx
Copy link
Member Author

ptrendx commented Jan 7, 2025

/te-ci

Copy link
Collaborator

@timmoon10 timmoon10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ptrendx
Copy link
Member Author

ptrendx commented Jan 7, 2025

/te-ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should cublasLtHandle_t be Destroyed?
4 participants