views:

37

answers:

1

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?

+2  A: 

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

cublasSscal (m, alpha, B + 2*ldB, 1); //  indices are 0 based
aaa
it works, thanks, but how the host compiler know the layout of device memory?
emailhy
@ema I am not sure I understand your question, can you elaborate
aaa
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?
emailhy
@ema yes, you are correct. raw pointer is just pointer
aaa