cuda offset device pointer in host code

Tag: pointers , cuda , device Author: cwtcwttc123 Date: 2010-08-01

I first process a matrix in cublas, I have already sent it to device and I want to process some column vector of the matrix, still use cublas function. I first try using pointer arithmetic operation to offset the device pointer from host, but it seems doesn't work. Is there any way I can process vector in matrix without copying it back to host.

for example: cublasSscal (int n, float alpha, float *x, int incx); is used to scale a vector I have a device pointer point to a column major matrix B, i want scale the third column of B and without copy the vector back to host, how to do it?

Best Answer

m is the number of rows, ldB is the leading dimension of B.

cublasSscal (m, alpha, B + 2*ldB, 1); //  indices are 0 based


it works, thanks, but how the host compiler know the layout of device memory?
@ema I am not sure I understand your question, can you elaborate
At first I thought the device pointer can be only operated in kernel code which compiled by nvcc, as there are some "padding techniques" to make it faster. So the pointer shift operation is not safe, However it seems OK to shift the device pointer. and we can just treat it like host memory. It just doesn't allow dereference. Am I right?
@ema yes, you are correct. raw pointer is just pointer