I’m trying to create a Matlab MEX function that does a series of calculation on the GPU using cuBLAS. So far using cublasDgemm has been working flawlessly, but when I try to use cublasDgemm Matlab crashes. It does however compile without errors. As far as I can see I’m not doing anything wrong, but I’m relatively new to CUDA and C programming in general so maybe there is something obvious that one of you experts can see that I don’t…
Basically I have a vector, ti, on the device which is of double precision and of dimensions [m x p], where p = 1 so [m x 1]. I want to calculate the norm of the vector using cublasDgemm, and I have tried writing it the following way:
double *ti; cudaMalloc(&ti, sizeof(double) ∗ m ∗ p); … // A bunch of other code here that works… … /* Calculate ti using cublasDgemm */ cublasDgemm(handle,CUBLAS_OP_N,CUBLAS_OP_N,m,p,n,&alpha,deviceX,m,ri,n,&beta,ti,m); /* Create a [1 x 1] variable called normti and allocate memory for it on the GPU */ double *normti; cudaMalloc(&normti, sizeof(double) ∗ p ∗ p); /* Create a cuBLAS handle and attempt to calculate the Euclidian norm using cublasDnrm2 */ cublasCreate(&handle); cublasDnrm2(handle, m, ti, 1, normti);
If I comment out the last line the program works but with the last step Matlab crashes… Any ideas what I’m doing wrong?