Search code examples
cudacublas

cublas<>gemmBatched with aliased Carray parameter


I'm trying to implement something like scipy.sparse.bsr_matrix operations with cublas<>gemmBatched. Unfortunately I can't do this with cusparse since my BSR matrix isn't square.

I'm new to cublas, I wonder if it's ok (correctness-wise and performance-wise) to use aliased pointer (as in pointer aliasing) array for float * Carray[]

e.g.

/* given float * out as the real output array */
float * Carray[] = {
  out + 1*stride, out + 2*stride, out + 3*stride,
  out + 1*stride, out + 2*stride, out + 3*stride,
  /* and repeat */
};

Also, Although I'm pretty sure it will be correct if I use aliased Aarray or Barray, is there any performance impact?

Thanks!


Solution

  • In general, there is no problem with that sort of aliasing in CUBLAS. In fact, it is the normal way to deal with submatrices, and most LAPACK style solvers use pointer indexing or aliasing extensively to perform sub-block operations on matrices.

    I don't believe there is a performance penalty in working this way, at least for the batch solvers, although the only way to be certain would be via benchmarking, which is probably trivial to test yourself.