0
我想用cublasDgemm()替換對「cblas_dgemm()」的調用。下面是從鯊魚機器學習庫中的原始包裝:在OpenAcc中使用cuBLAS
inline void gemm(
CBLAS_ORDER const Order, CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB,
int M, int N, int K,
double alpha, double const *A, int lda,
double const *B, int ldb,
double beta, double *C, int ldc
){
cblas_dgemm(
Order, TransA, TransB,
M, N, K,
alpha,
A, lda,
B, ldb,
beta,
C, ldc
);
}
這裏使用OpenACC的編譯指示修改後的代碼:
inline void gemm(
CBLAS_ORDER const Order, CBLAS_TRANSPOSE TransA, CBLAS_TRANSPOSE TransB,
int M, int N, int K,
double alpha, double const *A, int lda,
double const *B, int ldb,
double beta, double *C, int ldc
){
#ifdef _OPENACC
cublasOperation_t OpT_A, OpT_B;
switch (TransA)
{
case CblasNoTrans:
OpT_A = CUBLAS_OP_N;
break;
case CblasTrans:
OpT_A = CUBLAS_OP_T;
break;
case CblasConjTrans:
OpT_A = CUBLAS_OP_C;
break;
default:
OpT_A = CUBLAS_OP_N;
}
switch (TransB)
{
case CblasNoTrans:
OpT_B = CUBLAS_OP_N;
break;
case CblasTrans:
OpT_B = CUBLAS_OP_T;
break;
case CblasConjTrans:
OpT_B = CUBLAS_OP_C;
break;
default:
OpT_B = CUBLAS_OP_N;
}
cublasHandle_t handle;
#pragma acc data copyin(OpT_A, OpT_B, M, N, K, alpha, A[0:M][0:K], lda, B[0:K][0:N], ldb, beta, ldc) copy(C[0:M][0:N])
{
#pragma acc host_data use_device(handle,OpT_A, OpT_B, A, B, C, M, N, K, lda, ldb, ldc, alpha, beta)
{
cublasDgemm(handle,OpT_A,OpT_B,M,N,K,&alpha,A,lda,B,ldb,&beta,C,ldc);
}
}
#else
cblas_dgemm(
Order, TransA, TransB,
M, N, K,
alpha,
A, lda,
B, ldb,
beta,
C, ldc
);
#endif
}
問題是,當我編譯OpenACC的標誌代碼,的元素結果矩陣,即C,在內核執行之前和之後都是零。我不知道我在這裏失去了什麼。 我感謝任何幫助。