我的机子只要运行40964096的矩阵乘法是就会导致死机,屏幕上只有鼠标可以动,点击桌面上的任何程序都没有反应了,但是运行20482048的矩阵乘法就不会有问题,求教版主!
楼主您好,
在等待了相当长的时间内依然没有反应吗?
我怀疑您的kernel运行了超级长的时间,导致短期内无法结束,建议等待下。
请反馈耐心等待后的结果。
感谢来访。
以及我来补充一下玫瑰斑竹,请LZ同时注意检查下kernel中是否存在死循环的现象,导致kernel总是无法运行结束。
4096*4096的矩阵乘法并不算一个特别大规模的计算。
我等了十几分钟用鼠标点击桌面上的程序界面都没有反应,之后问我就强制关机了,好几次都等了十几分钟都不行,谢谢斑竹的回复!
这个真心奇怪了,您确定是卡在等待kernel完成上么?
(例如,卡在后续的cudaDeviceSynchronize()之类的?)
我没有在日常生活中遇到此问题。希望楼主能进一步提供细节。
应该没有死循环,我同学的机子都可以把程序准确的运行结束!代码如下:global void matrixMul(double *C, double *A, double *B, int wA, int wB)
{
// Block index
int bx = blockIdx.x;
int by = blockIdx.y;
// Thread index
int tx = threadIdx.x;
int ty = threadIdx.y;
// Index of the first sub-matrix of A processed by the block
int aBegin = wA * BLOCK_SIZE * by;
// Index of the last sub-matrix of A processed by the block
int aEnd = aBegin + wA - 1;
// Step size used to iterate through the sub-matrices of A
int aStep = BLOCK_SIZE;
// Index of the first sub-matrix of B processed by the block
int bBegin = BLOCK_SIZE * bx;
// Step size used to iterate through the sub-matrices of B
int bStep = BLOCK_SIZE * wB;
// Csub is used to store the element of the block sub-matrix
// that is computed by the thread
double Csub = 0;
// Loop over all the sub-matrices of A and B
// required to compute the block sub-matrix
for (int a = aBegin, b = bBegin;
a <= aEnd;
a += aStep, b += bStep)
{
// Declaration of the shared memory array As used to
// store the sub-matrix of A
shared double As[BLOCK_SIZE][BLOCK_SIZE];
// Declaration of the shared memory array Bs used to
// store the sub-matrix of B
shared double Bs[BLOCK_SIZE][BLOCK_SIZE];
// Load the matrices from device memory
// to shared memory; each thread loads
// one element of each matrix
As[ty][tx] = A[a + wA * ty + tx];
Bs[ty][tx] = B[b + wB * ty + tx];
// Synchronize to make sure the matrices are loaded
__syncthreads();
// Multiply the two matrices together;
// each thread computes one element
// of the block sub-matrix
#pragma unroll
for (int k = 0; k < BLOCK_SIZE; ++k)
{
Csub += As[ty][k] * Bs[k][tx];
}
// Synchronize to make sure that the preceding
// computation is done before loading two new
// sub-matrices of A and B in the next iteration
__syncthreads();
}
// Write the block sub-matrix to device memory;
// each thread writes one element
int c = wB * BLOCK_SIZE * by + BLOCK_SIZE * bx;
C[c + wB * ty + tx] = Csub;
}
我的机子也可以将程序运行结束,只不过程序结束后就死机了,CPU还在那不停的运转!谢谢斑竹的回复!
话说目前没有更好的建议了,
从您的现象描述看,更像是显卡有问题(例如硬件或者显卡驱动)。
建议您先:
(1)更新显卡驱动到最新,看看问题是否解决。
(2)更换一张卡(可以借你同学的卡),看看问题是否解决。
而不要考虑是kernel的问题。