【问题标题】:Multiplying matrices in CUDA using shared memory tiled technique使用共享内存平铺技术在 CUDA 中乘以矩阵
【发布时间】:2013-01-04 17:45:24
【问题描述】:

在下面的作业代码中,我需要找出平铺矩阵乘法工作还需要哪些边界条件。请帮帮我,我已经尝试了一周以找出问题所在是?

#include    <wb.h>

#define TILE_WIDTH 16


__global__ void matrixMultiplyShared(float * A, float * B, float * C,

                     int numARows, int numAColumns,
                     int numBRows, int numBColumns,
                     int numCRows, int numCColumns) {

//@@ Insert code to implement matrix multiplication here
//@@ You have to use shared memory for this MP
  __shared__ float s_A[TILE_WIDTH][TILE_WIDTH];
  __shared__ float s_B[TILE_WIDTH][TILE_WIDTH];

  int tx= threadIdx.x; int ty = threadIdx.y;
  int bx= blockIdx.x ; int by = blockIdx.y ;

  int Row = by*TILE_WIDTH + ty;
  int Col = bx*TILE_WIDTH + tx;



   if((Row < numARows  ) && (Col < numBColumns )) {


 float Pvalue =0.0;
  for (int m = 0; m < (numAColumns-1)/TILE_WIDTH+1; ++m) {

    if((Row < numARows) && ( (m*TILE_WIDTH+tx) < numAColumns)) {

      s_A[ty][tx] = A[Row*numAColumns +( m*TILE_WIDTH+tx)];
    }
    else
    {
      s_A[ty][tx] = 0.0;
    }
    if(((m*TILE_WIDTH+ty) < numBRows) && (Col < numBColumns)) {

      s_B[ty][tx] = B[(m*TILE_WIDTH+ty)*numBColumns+Col];
    }
    else
    {
      s_B[ty][tx] = 0.0;
    }
    __syncthreads();

   if((Row < numARows  ) && (Col < numBColumns )) {
    for (int k = 0; k < TILE_WIDTH; ++k)
      {

         Pvalue += s_A[ty][k] * s_B[k][tx];

      }
    __syncthreads();

  }
  }
    if((Row < numARows  ) && (Col < numBColumns )) { 
       C[Row*numCColumns+Col] = Pvalue;
    }
}
else
return;
}

【问题讨论】:

  • 你不应该和你的老师一起做这个吗?
  • 您可能会发现一些有用的信息here

标签: c matrix cuda


【解决方案1】:

问题在于进入循环加载TILE的条件,即if((Row here

【讨论】:

    猜你喜欢
    • 2018-05-18
    • 2020-12-22
    • 2013-09-19
    • 2021-06-02
    • 2018-11-17
    • 2017-03-29
    • 2012-12-14
    • 2017-04-06
    • 2020-05-11
    相关资源
    最近更新 更多