It is possible to index through your flattened Q
matrix the way you propose. Your call to Sgemv should be as follows:
cublasSgemv(handle, CUBLAS_OP_T, N, N, &alpha, d_A, N, (d_Q + K), (Niter), &beta, (d_v+(K*Niter)) , 1);
The pointer to Q
should point to the first element of the column in question, and since your matrix is row-major, this is just d_Q + K
(using pointer arithmetic, not byte arithmetic). Niter
is the stride (in elements, not bytes) between successive elements of the column in question. Note that your code as written would overwrite the results of one matrix-vector multiply with the next, since you are not indexing through d_v
the output vector. So I added some indexing on d_v
.
As @JackOLantern points out, it should also be possible to do this in a single step without your loop, by calling Sgemm:
cublasSgemm(handle, CUBLAS_OP_T, CUBLAS_OP_T N, Niter, N, &alpha, d_A, N, d_Q, (Niter), &beta, d_v, N);
If your code is not working the way you expect, please provide a complete, compilable example.