Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do pass data to a shared variable in CUDA?
    text
    copied!<p>I have a kernel which passes 3 arrays, the first array d_A1 has no data and is used only to write back data, the other two arrays d_D1 and d_ST1 have data.</p> <p>The size of the first array is:</p> <p>d_A1[13000000]</p> <p>The size of the second array is:</p> <p>d_D1[421]</p> <p>The size of the third array is:</p> <p>d_ST1[21]</p> <p>N is 13000000</p> <p>TestArray&lt;&lt;>>(d_A1,N, d_D1, d_ST1);</p> <p>Now I want only pass the data of d_D1[421] and d_ST1[21] to shared arrays so I created the shared arrays as:</p> <pre><code>__global__ void TestArray(int* A1, unsigned int N, int* D1, unsigned int* ST1) { unsigned int __align__(16) tid = threadIdx.x; unsigned int __align__(16) idx = __umul24(blockDim.x, blockIdx.x) + threadIdx.x; __shared__ unsigned int __align__(16) s_D1[441]; //Shared array for d_D1 __shared__ unsigned int __align__(16) s_ST1[21]; //Shared array for d_ST1 if (idx &lt; N) //13000000 { </code></pre> <p>Q. How do I pass the data of d_D1[441] and d_ST1[21] to s_D1[441] and s_ST1[21]? I tried:</p> <pre><code> while (idx &lt; 441) s_D1[tid] = d_D1[idx] __syncthreads(); while (idx &lt; 21) s_ST1[tid] = d_ST1[idx] __syncthreads(); </code></pre> <p>but the computer freezes and I have to restart it. I also tried one at the time,namely, only the fist while and then only the second while, with no luck.</p> <p>If I use the global memory, namely, d_D1, d_ST1 everything works. So the question is: How do you pass data to a shared variable/array when the size of the array is not N? </p> <pre><code> } //End of kernel processing } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload