title: How to share global memory within multiple kernels and multiple GPUs?
body: <pre><code>----------------a.c---------------------
  variable *XX;
  func1(){
    for(...){
      for(i = 0; i &lt; 4; i++)
         cutStartThread(func2,args)
    } 
  }
  ---------------b.cu-------------------
  func2(args){
    cudaSetDevice(i);
    xx = cudaMalloc();
    mykernel&lt;&lt;&lt;...&gt;&gt;&gt;(xx);
  }
  --------------------------------------
  </code></pre>
  
  <p>Recently, I want to use multiple GPU device for my program. There are four Tesla C2075 cards on my node. I use four threads to manage the four GPUs. What's more, the kernel in each thread is launched several times. A simple pseudo code as above. I have two questions: </p>
  
  <ol>
  <li><p>Variable <code>XX</code> is a very long string, and is read only in the kernel. I want to preserve it during the multiple launches of <code>mykernel</code>. Is it ok to call <code>cudaMalloc</code> and pass the pointer to <code>mykernel</code> only when  <code>mykernel</code> is first launched? Or should I use <code>__device__</code> qualifier? </p></li>
  <li><p><code>XX</code> is used in four threads, so I declare it as a global variable in file <code>a.c</code>. Are multiple <code>cudaMalloc</code> of <code>XX</code> correct or should I use an array such as <code>variable *xx[4]</code>?</p></li>
  </ol>