-
Notifications
You must be signed in to change notification settings - Fork 27
Cublas active #279
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
Open
Breush
wants to merge
6
commits into
master
Choose a base branch
from
cublas-active
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cublas active #279
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f9f549
Activated the usage of cublas
1e27e1d
Merge branch 'cublas-active' of https://github.com/linbox-team/fflas-…
5ee9f2a
Draft version that works but need to be cleaned up for benchmark-dgemm
23abe87
More setup
Breush 9c7fd1a
Removed useless line
5a35861
Wrapped the call of cublas into the fgemm
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| #include "fflas-ffpack/fflas/fflas_igemm/igemm.h" | ||
| #endif | ||
|
|
||
| #include "fflas-ffpack/utils/fflas_io.h" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include to be removed |
||
| namespace FFLAS { | ||
|
|
||
| // F is a field supporting delayed reductions | ||
|
|
@@ -249,12 +250,41 @@ namespace FFLAS { | |
| FFLASFFPACK_check(lda); | ||
| FFLASFFPACK_check(ldb); | ||
| FFLASFFPACK_check(ldc); | ||
| #if defined(__FFLASFFPACK_OPENBLAS_NUM_THREADS) and not defined (__FFLASFFPACK_OPENBLAS_NT_ALREADY_SET) | ||
| openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); | ||
| #endif | ||
| cblas_dgemm (CblasRowMajor, (CBLAS_TRANSPOSE) ta, (CBLAS_TRANSPOSE) tb, | ||
| (int)m, (int)n, (int)k, (Givaro::DoubleDomain::Element) alpha, | ||
| Ad, (int)lda, Bd, (int)ldb, (Givaro::DoubleDomain::Element) beta, Cd, (int)ldc); | ||
|
|
||
| #if defined(__FFLASFFPACK_HAVE_CUBLAS) | ||
| // Allocate device storage for A,B,C | ||
| using Element = Givaro::DoubleDomain::Element; | ||
| Element *d_A, *d_B, *d_C; | ||
| cudaMalloc((void**)&d_A, m*k*sizeof(Element)); | ||
| cudaMalloc((void**)&d_B, k*n*sizeof(Element)); | ||
| cudaMalloc((void**)&d_C, m*n*sizeof(Element)); | ||
|
|
||
| // Create cublas instance | ||
| cublasHandle_t handle; | ||
| cublasCreate(&handle); | ||
|
|
||
| // Set input matrices on device | ||
| cublasSetMatrix(k, m, sizeof(Element), Ad, lda, d_A, k); // @note Device's leading dimensions are for column major matrices. | ||
| cublasSetMatrix(n, k, sizeof(Element), Bd, ldb, d_B, n); | ||
| cublasSetMatrix(n, m, sizeof(Element), Cd, ldc, d_C, n); | ||
|
|
||
| // @note As cublas works in column-major, we inverse the transpose here. | ||
| auto d_ta = (ta == FFLAS_TRANSPOSE::FflasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T; | ||
| auto d_tb = (tb == FFLAS_TRANSPOSE::FflasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T; | ||
|
|
||
| cublasDgemm(handle, d_tb, d_ta, n,m,k, &alpha, d_B, n, d_A, k, &beta, d_C, n); | ||
|
|
||
| // Retrieve result matrix from device | ||
| cublasGetMatrix(n, m, sizeof(Element), d_C, n, Cd, ldc); | ||
| #else | ||
| #if defined(__FFLASFFPACK_OPENBLAS_NUM_THREADS) and not defined (__FFLASFFPACK_OPENBLAS_NT_ALREADY_SET) | ||
| openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); | ||
| #endif | ||
|
|
||
| cblas_dgemm (CblasRowMajor, (CBLAS_TRANSPOSE) ta, (CBLAS_TRANSPOSE) tb, | ||
| (int)m, (int)n, (int)k, (Givaro::DoubleDomain::Element) alpha, | ||
| Ad, (int)lda, Bd, (int)ldb, (Givaro::DoubleDomain::Element) beta, Cd, (int)ldc); | ||
| #endif | ||
| } | ||
|
|
||
| inline void fgemm (const Givaro::FloatDomain& F, | ||
|
|
@@ -272,12 +302,41 @@ namespace FFLAS { | |
| FFLASFFPACK_check(ldb); | ||
| FFLASFFPACK_check(ldc); | ||
|
|
||
| #if defined(__FFLASFFPACK_OPENBLAS_NUM_THREADS) and not defined (__FFLASFFPACK_OPENBLAS_NT_ALREADY_SET) | ||
| openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); | ||
| #endif | ||
| cblas_sgemm (CblasRowMajor, (CBLAS_TRANSPOSE) ta, (CBLAS_TRANSPOSE) tb, | ||
| (int)m, (int)n, (int)k, (Givaro::FloatDomain::Element) alpha, | ||
| Ad, (int)lda, Bd, (int)ldb, (Givaro::FloatDomain::Element) beta,Cd, (int)ldc); | ||
| #if defined(__FFLASFFPACK_HAVE_CUBLAS) | ||
| // Allocate device storage for A,B,C | ||
| using Element = Givaro::FloatDomain::Element; | ||
| Element *d_A, *d_B, *d_C; | ||
| cudaMalloc((void**)&d_A, m*k*sizeof(Element)); | ||
| cudaMalloc((void**)&d_B, k*n*sizeof(Element)); | ||
| cudaMalloc((void**)&d_C, m*n*sizeof(Element)); | ||
|
|
||
| // Create cublas instance | ||
| cublasHandle_t handle; | ||
| cublasCreate(&handle); | ||
|
|
||
| // Set input matrices on device | ||
| cublasSetMatrix(k, m, sizeof(Element), Ad, lda, d_A, k); // @note Device's leading dimensions are for column major matrices. | ||
| cublasSetMatrix(n, k, sizeof(Element), Bd, ldb, d_B, n); | ||
| cublasSetMatrix(n, m, sizeof(Element), Cd, ldc, d_C, n); | ||
|
|
||
| // @note As cublas works in column-major, we inverse the transpose here. | ||
| auto d_ta = (ta == FFLAS_TRANSPOSE::FflasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T; | ||
| auto d_tb = (tb == FFLAS_TRANSPOSE::FflasNoTrans) ? CUBLAS_OP_N : CUBLAS_OP_T; | ||
|
|
||
| cublasSgemm(handle, d_tb, d_ta, n,m,k, &alpha, d_B, n, d_A, k, &beta, d_C, n); | ||
|
|
||
| // Retrieve result matrix from device | ||
| cublasGetMatrix(n, m, sizeof(Element), d_C, n, Cd, ldc); | ||
| #else | ||
| #if defined(__FFLASFFPACK_OPENBLAS_NUM_THREADS) and not defined (__FFLASFFPACK_OPENBLAS_NT_ALREADY_SET) | ||
| openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); | ||
| #endif | ||
| cblas_sgemm (CblasRowMajor, (CBLAS_TRANSPOSE) ta, (CBLAS_TRANSPOSE) tb, | ||
| (int)m, (int)n, (int)k, (Givaro::FloatDomain::Element) alpha, | ||
| Ad, (int)lda, Bd, (int)ldb, (Givaro::FloatDomain::Element) beta,Cd, (int)ldc); | ||
| #endif | ||
|
|
||
|
|
||
| } | ||
|
|
||
| inline void fgemm (const Givaro::ZRing<int64_t>& F, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to this file should be reverted