589
社区成员




// 源代码如下, VS2022, cuda 12.6,
__global__ void SetBool(volatile int* b)
{
if (ptrdiff_t(b) > 100)
* b = 1;
else
__nanosleep(1);
}
__device__ volatile int fc = 0;
__global__ void fk()
{
size_t pidx = threadIdx.x;
if(0 == pidx) // cudaStreamTailLaunch 放在这,导致随机卡死(3000次就会产生卡死)
SetBool << <1, 1, 0, cudaStreamTailLaunch >> > (&fc);
switch (pidx)
{
case 0: // cudaStreamTailLaunch 放在这,没有发现随机卡死
//SetBool << <1, 1, 0, cudaStreamTailLaunch >> > (&fc);
return SetBool<<<1,1>>>(0);
case 1: return SetBool << <1, 1 >> > ((volatile int*)1);
case 2: return SetBool << <1, 1 >> > ((volatile int*)2);
case 3: return SetBool << <1, 1 >> > ((volatile int*)3);
case 4: return SetBool << <1, 1 >> > ((volatile int*)3);
case 5: return SetBool << <1, 1 >> > ((volatile int*)3);
case 6: return SetBool << <1, 1 >> > ((volatile int*)3);
case 7: return SetBool << <1, 1 >> > ((volatile int*)3);
default:
break;
}
}
__global__ void waitf()
{
fc = 0;
fk << <1, 10 >> > ();
while (!fc)__nanosleep(1);
}
int main(int argc, char** argv)
{
for (size_t i =0; ; i++)
{
auto t = clock();
waitf << <1, 10 >> > ();
cudaDeviceSynchronize(); // 当运行次数很多的时候,会随机卡死在这。
auto e = clock();
printf("%lld: %d, ", i, e - t);
}
}