我当时正在编写其他代码,突然我发现了一个问题,该问题会使代码变慢,并且我对其进行了分析,发现即使在下面的简单代码中,它也运行缓慢。由于测量了时间,几乎在0秒内运行的gpu函数突然耗时超过0.5秒,但我不明白。 我还使用了Titan Xp GPU。
this image shows my gpu suddenly slows down
#include ...
__global__ void gpu(double *dev){
dev[(long long)blockIdx.x*(long long)gridDim.y+(long long)blockIdx.y] = 0;
}
double *dev;
int main(){
long long N = 20000;
clock_t clock_begin = clock();
dim3 dim_0 (N,N);
cudaSetDevice(1);
cudaMalloc((void**)&dev,N*N*(long long)sizeof(double));
while(1){
gpu<<<dim_0,1>>>(dev);
printf("gpu : %.15f\n",(double)(clock()-clock_begin)/(double)CLOCKS_PER_SEC);
clock_begin = clock();
}
return 0;
}