title: Creating Array In SourceModule of PyCuda
body: <p>I am a beginner in pyCUDA and trying to make some tests in SourceModule.
  With the following code:</p>
  <pre><code>import pycuda.driver as drv
  from pycuda.compiler import SourceModule
  
  
  target = SourceModule(r&quot;&quot;&quot;
  __device__ void Array_test()
  {
      float ** PH = (float **)malloc(50 * sizeof(float *));
      for(int i = 0; i &lt; 50; i++)
          PH[i]=(float*)malloc(30000*sizeof(float));
      PH[49][29999] = 1;
  
      for(int i = 0; i &lt; 50; i++)
          free(PH[i]);
      free(PH);  
  }
  
  void __global__ f()
  {
      Array_test();
  }
  &quot;&quot;&quot;)
  
  if __name__ == &quot;__main__&quot;:
      start = drv.Event()
      end = drv.Event()
      start.record()
      test = target.get_function(&quot;f&quot;)
      test(grid=(1,), block=(2, 1, 1))
      end.record()
      end.synchronize()
      secs = start.time_till(end) * 1e-3
      print(secs)
  </code></pre>
  <p>I got the error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/home/cuda_test.py&quot;, line 33, in &lt;module&gt;
      end.synchronize()
  pycuda._driver.LogicError: cuEventSynchronize failed: an illegal memory access was encountered
  PyCUDA WARNING: a clean-up operation failed (dead context maybe?)
  cuEventDestroy failed: an illegal memory access was encountered
  PyCUDA WARNING: a clean-up operation failed (dead context maybe?)
  cuEventDestroy failed: an illegal memory access was encountered
  PyCUDA WARNING: a clean-up operation failed (dead context maybe?)
  cuModuleUnload failed: an illegal memory access was encountered
  </code></pre>
  <p>Is this caused by my misuse of malloc in GPU programming and how can I solve it?
  Thanks a lot!</p>