串行版本的矩阵乘法
M
N
P
WIDTH
WIDTH
WIDTH
WIDTH
// 宿主机的双精度矩阵乘法
void MatrixMulOnHost(float* M, float* N, float* P, int Width){
for (int i = 0; i < Width; ++i)
for (int j = 0; j < Width; ++j){
double sum = 0;
for (int k = 0; k < Width; ++k){
double a = M[i * width + k];
double b = N[k * width + j];
sum += a * b;
}
P[i * Width + j] = sum;
}
}
i
k
k
j
*
2022-05-25 10:08:57
436KB
CUDA
1