【发布时间】:2020-09-10 02:34:27
【问题描述】:
我有以下工作程序可以正确产生结果,但是我对一些统计数据感到困惑。设置如下:
- 硬件:英特尔至强融核处理器 7210
- 软件:两个 NxN 矩阵的乘法(在我的例子中是 512x512)
- 数据结构:所有 3 个矩阵都分配在高带宽内存中(即在 16GB mcdram 中)
代码是:
void MatrixMultiply(img_in1, img_in2, img_out, myRank, nRanks)
{
for (int i=startingRow ; i<endingRow ; i++) //no of rows of first matrix divided on per process basis
{
for (int j=0 ; j<M1Cdim ; j++) //no of cols of first matrix
{
int temp = 0;
for(int k=0 ; k<M2Rdim ; k++) //no of rows of second matrix
{
temp += in1[i*M1Rdim+k] * in2[k*M2Rdim+j]; //out(i,j) += in1(i,k) * in2(k,j)
}
out[i*M1Rdim+j] = temp;
}
}
}
main()
{
for (int i = 1; i <= 10; i++)
{
MPI_Barrier(MPI_COMM_WORLD);
const double t0 = omp_get_wtime();
MatrixMultiply(img_in1, img_in2, img_out, myRank, nRanks);
MPI_Barrier(MPI_COMM_WORLD);
const double t1 = omp_get_wtime();
const double ts = t1-t0; // time in seconds
const double tms = ts*1.0e3; // time in milliseconds
const double gbps = double(sizeof(P)*2*img_in1.height*img_in1.width*img_in2.height)*1e-9/ts; // bandwidth in GB/s
const double fpps = double(2*img_in1.height*img_in1.width*img_in2.height)*1e-9/ts; // performance in GFLOP/s
if (myRank == 0)
{
printf("%5d %15.3f %15.3f %15.3f %s\n", i, tms, gbps, fpps);
}
}
}
The statistics I am getting are:
Step Time, ms GB/s GFLOP/s
1 2.306 116.408 116.408
2 2.334 115.017 115.017
3 2.297 116.855 116.855
4 2.295 116.964 116.964
5 16.692 16.082 16.082
6 11.468 23.407 23.407
7 2.299 116.758 116.758
8 2.291 117.171 117.171
9 2.295 116.964 116.964
10 10.792 24.874 24.874
所以我的问题是:
为什么迭代 5、6 和 10 的结果比其他迭代更差?
我的怀疑是,即使数据被放置在高带宽内存 (mcdram) 中,但代码本身是从缓存中执行的,因此可能会受到影响。虽然整个程序非常小,如 54KB,但如果在共享服务器上运行,则可能会从指令缓存中逐出一些迭代,从而导致性能下降。
【问题讨论】:
标签: performance benchmarking cpu-architecture cpu-cache xeon-phi