我正在尝试在 CUDA 中编写程序,但我在线程之间的同一块中遇到同步问题。
这是模型情况:
10 __global__ void gpu_test_sync()
11 {
12 __shared__ int t;
13 int tid = threadIdx.x;
14
15 t = 0;
16 __threadfence();
17 __syncthreads();
18
19 // for(int i=0; i<1000000 && t<tid; i++); // with fuse
20 while(t<tid);
21
22 t++;
23 __threadfence();
24 }
25
26 void f_cpu()
27 {
28 printf("TEST ... ");
29 int blocks = 1;
30 int threads = 2;
31 gpu_test_sync<<< blocks , threads >>>();
32 printf("OK\n");
33 }
Run Code Online (Sandbox Code Playgroud)
如果线程数 …