Question

I have a problem with the following code, when executing the call to cublasSrotg it throws an exception: "Access violation writing location 0x05200600", which is the address of the 'dA' pointer. When running the debugger it appears to be skipping the call to cudaMalloc, but I can't figure out what I'm doing wrong.

cublasHandle_t handle;
cublasCreate(&handle);
float hA[SIZE] = { 1.0f, 2.0f, 3.0f, 4.0f };
int sizef = sizeof(float);
float* dA;
cudaMalloc((void**)&dA, SIZE * sizef);
cublasSetVector(SIZE, sizef, hA, 1, dA, 1);
float s, c;
cublasSrotg(handle, dA, dA + N, &c, &s);
cublasSrot(handle, N, dA, 1, dA + N, 1, &c, &s);
cublasGetVector(SIZE, sizef, dA, 1, hA, 1);
...
Was it helpful?

Solution

From the following line of code I gather that SIZE is equal to 4.

float hA[SIZE] = { 1.0f, 2.0f, 3.0f, 4.0f };

But then here, you do two strange things:

cublasSrotg(handle, dA, dA + N, &c, &s);
  1. You mix host and device parameters to the same cublas function (I don't know if this is legal or not). dA is a device pointer and s and c are host variables.

  2. You pass dA and dA + N. Unless N is less than 4, you will be indexing out of bounds, so that could be your problem. Also, note that the first two inputs to cublasSrotg are in/out variables -- their initial value is used, but then overwritten.

Since they are overwritten, it's strange that you would then pass the same pointers to cublasSrot...

See the CUBLAS Documentation for full details.

Edit:

OP reveals that the problem was mixing device and host pointers, as well as not calling cudaMalloc to allocate the c and s values on the device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top