CUDA

Info

  1. How is 2D Shared Memory arranged in CUDA

Written Bugs

  1. 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

  1. __syncthreads的用法,防止wait forever的情况