CUDA
Info
- How is 2D Shared Memory arranged in CUDA
Written Bugs
-
wait forever due to
s_changed
if-else case__shared__ int s_data[BLOCKWIDTH][BLOCKWIDTH]; if(val == 0) return; // make sure maybe its connected int label = Block1DAddress; while(1) { // Pass 1 of the CCL algorithm s_labels[Block1DAddress] = label; if(Block1DAddress == 0) s_changed[0] = 0; __syncthreads(); ... if(s_changed[0] == 0) break; }
上述程序,我让
val == 0
的线程全部return
了,但是下面while
里面写了如果Block1DAddress==0
的话才break
,这样导致了如果一个block里面的第0个thread的值是0,s_changed
就永远无法初始化为0
Solutions
__syncthreads
的用法,防止wait forever的情况