title: CUDA global (as in C) dynamic arrays allocated to device memory
body: <p>So, im trying to write some code that utilizes Nvidia's CUDA architecture. I noticed that copying to and from the device was really hurting my overall performance, so now I am trying to move a large amount of data onto the device.</p>
  
  <p>As this data is used in numerous functions, I would like it to be global. Yes, I can pass pointers around, but I would really like to know how to work with globals in this instance. </p>
  
  <p>So, I have device functions that want to access a device allocated array.</p>
  
  <p>Ideally, I could do something like:</p>
  
  <pre><code>__device__ float* global_data;
  
  main()
  {
    cudaMalloc(global_data);
    kernel1&lt;&lt;&lt;blah&gt;&gt;&gt;(blah); //access global data
    kernel2&lt;&lt;&lt;blah&gt;&gt;&gt;(blah); //access global data again
  }
  </code></pre>
  
  <p>However, I havent figured out how to create a dynamic array. I figured out a work around by declaring the array as follows:</p>
  
  <pre><code>__device__ float global_data[REALLY_LARGE_NUMBER];
  </code></pre>
  
  <p>And while that doesn't require a cudaMalloc call, I would prefer the dynamic allocation approach.</p>