各位大神好!我打算做batch次复数矩阵乘法AB,A(mk),B(k*n),于是我就调用了库函数cublasCgemmBatched。
结果出现了两个问题
1.库函数执行时间居然为零(如果执行一个普通的库函数例如cublasCgemm则可以测出时间);
2.执行完库函数后,变量不能释放(若不执行库函数,变量可以正常释放)。
请问这是为啥啊,谢谢指教!
附上完整源代码:
const int n=300;
const int m=200;
const int k=100;
const int batch=8;
cuComplex alpha,beta;
alpha.x=1.0f;alpha.y=0.0f;
beta.x=0.0f;beta.y=0.0f;
cublasHandle_t handle;
cublasCreate(&handle);
cublasStatus_t status;
cudaError_t err;
const cuComplex* (A[batch]);
const cuComplex* (B[batch]);
Complex* (C[batch]);
for(int i=0;i<batch;i++)
err=cudaMalloc((void**)&(A[i]),m*k*sizeof(Complex));
for(int i=0;i<batch;i++)
err=cudaMalloc((void**)&(B[i]),n*k*sizeof(Complex));
for(int i=0;i<batch;i++)
err=cudaMalloc((void**)&(C[i]),n*m*sizeof(Complex));
cudaEvent_t start,stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
float timerr;
cudaEventRecord(start,0);
status=cublasCgemmBatched(handle,CUBLAS_OP_N,CUBLAS_OP_N,m,n,k,&alpha,A,m,B,k,&beta,C,m,batch);
//status=cublasCgemm(handle,CUBLAS_OP_T,CUBLAS_OP_N,m,n,k,&alpha,A[0],k,B[0],k,&beta,C[0],m);//该函数运行后可测出时间
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&timerr,start,stop);
printf("%.4f\n",timerr);
cublasDestroy(handle);
cudaEventDestroy(start);
cudaEventDestroy(stop);
for(int i=0;i<batch;i++)
err=cudaFree((cuComplex*)(A[i]));//释放时出现错误"ErrorUnKnown"
for(int i=0;i<batch;i++)
err=cudaFree((cuComplex*)(B[i]));
for(int i=0;i<batch;i++)
err=cudaFree(C[i]);
getchar();