How to transpose a matrix in CUDA/cublas?

前端 未结 3 1193
时光取名叫无心
时光取名叫无心 2020-12-17 02:54

Say I have a matrix with a dimension of A*B on GPU, where B (number of columns) is the leading dimension assuming a C style. Is there any method in

3条回答
  •  伪装坚强ぢ
    2020-12-17 03:41

    The CUDA SDK includes a matrix transpose, you can see here examples of code on how to implement one, ranging from a naive implementation to optimized versions.

    For example:

    Naïve transpose

    __global__ void transposeNaive(float *odata, float* idata,
    int width, int height, int nreps)
    {
        int xIndex = blockIdx.x*TILE_DIM + threadIdx.x;
        int yIndex = blockIdx.y*TILE_DIM + threadIdx.y;
        int index_in = xIndex + width * yIndex;
        int index_out = yIndex + height * xIndex;
    
        for (int r=0; r < nreps; r++)
        {
            for (int i=0; i

    Like talonmies had point out you can specify if you want operate the matrix as transposed or not, in cublas matrix operations eg.: for cublasDgemm() where C = a * op(A) * op(B) + b * C, assuming you want to operate A as transposed (A^T), on the parameters you can specify if it is ('N' normal or 'T' transposed)

提交回复
热议问题