title: Creating global variables in CUDA
body: <p>How can I create global variables in CUDA??
  Could you please give me an example?</p>
  
  <p>How can create arrays inside a CUDA function for example</p>
  
  <pre><code>__global__ void test()
  {
    int *a = new int[10];
  }
  </code></pre>
  
  <p>or How can I create a global array and access it from this function. for example</p>
  
  <pre><code>__device__ int *a;
  __global__ void test()
  {
    a[0] = 2;
  }
  </code></pre>
  
  <p>Or How can I use like the following..</p>
  
  <pre><code>__global__ void ProcessData(int img)
  {
     int *neighborhood = new int[8]; 
     getNeighbourhood(img, neighbourhood);
  }
  </code></pre>
  
  <hr>
  
  <p>Still I have some problem with this. I found that compare to </p>
  
  <pre><code>__device__
  </code></pre>
  
  <p>if I define </p>
  
  <pre><code>"__device__ __constant__" (read only)
  </code></pre>
  
  <p>will improve the memory access. 
  But my problem is I have an array in host memory say </p>
  
  <pre><code> float *arr = new float[sizeOfTheArray]; 
  </code></pre>
  
  <p>I want to make it as a variable array in device and I need to modify this in device memory and I need to copy this back to host. How can I do it??</p>