在下面的作业代码中,我需要找出平铺矩阵乘法工作还需要哪些边界条件。请帮助我,我已经尝试了一个星期来找出问题所在?
#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;
}