diff --git a/org/qmckl_blas.org b/org/qmckl_blas.org index 9cd7e18..0a83b34 100644 --- a/org/qmckl_blas.org +++ b/org/qmckl_blas.org @@ -2288,6 +2288,98 @@ qmckl_transpose (qmckl_context context, #+end_src +* cuBLAS interface (optional) +We propose a cuBLAS version of some QMCkl kernels. However, because cuBLAS is written in C, we need to define a Fortran interface for it. We start by defining functions to manage the cuBLAS handle structure from Fortran, before writing interfaces for the specific cuBLAS functions we are interested in. + +TODO These are the C functions that are supposed to be called from Fortran. We still need to write the interfaces themselves. + +#+begin_src c :tangle (eval h_private_func) :comments org +#ifdef HAVE_CUBLAS_OFFLOAD +#include +#endif +#+end_src + +#+begin_src c :tangle (eval h_private_func) :comments org +#ifdef HAVE_CUBLAS_OFFLOAD +cublasHandle_t* get_cublas_handle_interfaced(); +#endif +#+end_src + +#+begin_src c :comments org :tangle (eval c) :exports none +#ifdef HAVE_CUBLAS_OFFLOAD +cublasHandle_t* get_cublas_handle_interfaced() { + cublasHandle_t* handle = malloc(sizeof(cublasHandle_t)); + + cublasStatus_t status = cublasCreate(handle); + if (status != CUBLAS_STATUS_SUCCESS){ + fprintf(stderr, "Error while initializing cuBLAS\n"); + exit(1); + } + + return handle; +} +#endif +#+end_src + +#+begin_src c :tangle (eval h_private_func) :comments org +#ifdef HAVE_CUBLAS_OFFLOAD +void destroy_cublas_handle_interfaced(cublasHandle_t* handle); +#endif +#+end_src + +#+begin_src c :comments org :tangle (eval c) :exports none +#ifdef HAVE_CUBLAS_OFFLOAD +void destroy_cublas_handle_interfaced(cublasHandle_t* handle) { + if(handle != NULL) { + free(handle); + } +} +#endif +#+end_src + +** DGEMM + +#+begin_src c :tangle (eval h_private_func) :comments org +#ifdef HAVE_CUBLAS_OFFLOAD +cublasStatus_t cublasDgemm_f( + cublasHandle_t* handle, + cublasOperation_t* transa, cublasOperation_t* transb, + int* m, int* n, int* k, + const double* alpha, + const double*A, int* lda, + const double* B, int* ldb, + const double* beta, + double*C, int* ldc +); +#endif +#+end_src + +#+begin_src c :comments org :tangle (eval c) :exports none + +#ifdef HAVE_CUBLAS_OFFLOAD +cublasStatus_t cublasDgemm_f( + cublasHandle_t* handle, + cublasOperation_t* transa, cublasOperation_t* transb, + int* m, int* n, int* k, + const double* alpha, + const double*A, int* lda, + const double* B, int* ldb, + const double* beta, + double*C, int* ldc +) { + return cublasDgemm_f( + handle, + transa, transb, + m, n, k, + alpha, A, lda, B,ldb, + beta, C, ldc + ); +} +#endif +#+end_src + + + * End of files :noexport: diff --git a/org/qmckl_jastrow.org b/org/qmckl_jastrow.org index 8e2a00c..e1a7a18 100644 --- a/org/qmckl_jastrow.org +++ b/org/qmckl_jastrow.org @@ -5592,7 +5592,7 @@ integer function qmckl_compute_tmp_c_cublas_offload_f(context, cord_num, elec_nu LDB = size(een_rescaled_n,1) LDC = size(tmp_c,1) - ! Alloc and copy memory on device + ! TODO Replace with calls to cuBLAS do nw=1, walk_num do i=0, cord_num-1