title: Python cannot receive the result from cuda ctypes
body: <p>cuda script</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;vector&gt;
  #include&lt;iostream&gt;
  using namespace std;
  
  # define DELLEXPORT extern &quot;C&quot; __declspec(dllexport)
  
  
  __global__ void MatAdd (const double *cellbox, const double *verticess, double *C,
                      const double *halfcells,int rows, int cols)
  {
  
  
      int cellboxidy = threadIdx.y;
      int verticessidx = threadIdx.x;
  
      const double mincell [3] = {cellbox[cellboxidy * 3] - 
  halfcells[0],cellbox[cellboxidy * 3 + 1] - halfcells[1],cellbox[cellboxidy * 3 + 2] - 
  halfcells[2]};
      const double maxcell [3] = {cellbox[cellboxidy * 3] + 
  halfcells[0],cellbox[cellboxidy * 3 + 1] + halfcells[1],cellbox[cellboxidy * 3 + 2] + 
  halfcells[2]};
  
      if (verticess[verticessidx * 3] &gt;= mincell[0] &amp;&amp; verticess[verticessidx * 3] &lt;= 
  maxcell[0]  &amp;&amp; verticess[verticessidx * 3 + 1] &gt;= mincell[1]  &amp;&amp;  verticess[verticessidx 
  * 3 + 1] &lt;= maxcell[1] &amp;&amp; verticess[verticessidx * 3 + 2] &gt;= mincell[2] &amp;&amp; 
  verticess[verticessidx * 3 + 2] &lt;= maxcell[2]){
      
          C[cellboxidy * 3] = 1;
          C[cellboxidy * 3 + 1] = 1;
          C[cellboxidy * 3 + 2] = 1;
  
      }
  
  }
  
  DELLEXPORT void twodarray (double *out , double *celb ,double *ve , double *hfc , 
  double *sizecellbox , double *sizeverticess)
  {    
  
  
      double cellbox [24] = {0};
  
  
      for(int i = 0 ; i&lt;int(*sizecellbox) ; i++){
          cellbox[(i*3)] = celb[(i*3)];
          cellbox[(i*3) + 1] = celb[(i*3) + 1];
          cellbox[(i*3) + 2] = celb[(i*3) + 2];
  
  
      }
  
  
  
      double verticess [24] = {0};
      //cout&lt;&lt;int(*sizeverticess)&lt;&lt;endl;
      for(int i = 0 ; i&lt;int(*sizeverticess) ; i++){
          verticess[(i*3)] = ve[(i*3)];
          verticess[(i*3) + 1] = ve[(i*3) + 1];
          verticess[(i*3) + 2] = ve[(i*3) + 2];
  
      }
  
  
  
      const int N = *sizecellbox;
      int M = *sizeverticess;
  
  
      double halfcells[3] = {};
  
      halfcells[0] = hfc[0];
      halfcells[1] = hfc[1];
      halfcells[2] = hfc[2];
  
  
      double *C;
      double *cellbox_d = 0, *verticess_d = 0 , *halfcells_d = 0 , *C_d = 0;
      int rows = N;
      int cols = M;
  
      dim3 blockDim(*sizecellbox, *sizeverticess);
  
  
      C = (double *)malloc (sizeof(*C)*100);
      cudaMalloc ((void**) &amp;C_d, sizeof(*C_d)*100);
      cudaMalloc ((void**) &amp;cellbox_d, sizeof(*cellbox_d)*100);
      cudaMalloc ((void**) &amp;verticess_d, sizeof(*verticess_d)*100);
      cudaMalloc ((void**) &amp;halfcells_d, sizeof(*halfcells_d)*3);
  
      cudaMemcpy (cellbox_d, cellbox, sizeof(*cellbox_d)*100, cudaMemcpyHostToDevice);
      cudaMemcpy (verticess_d, verticess, sizeof(*verticess_d)*100, 
  cudaMemcpyHostToDevice);
      cudaMemcpy (halfcells_d, &amp;halfcells, sizeof(*halfcells_d)*3, 
  cudaMemcpyHostToDevice);
  
      MatAdd&lt;&lt;&lt;1,blockDim&gt;&gt;&gt;(cellbox_d, verticess_d, C_d, halfcells_d  , rows, cols);
  
      cudaMemcpy (C, C_d, sizeof(*C)*100, cudaMemcpyDeviceToHost);
  
      for (int i=0 ; i&lt;24 ; i++){
          cout&lt;&lt;C[i]&lt;&lt;endl;
      }
      out = C;
  
      cudaFree (cellbox);
      cudaFree (verticess_d);
      cudaFree (C_d);
      cudaFree(halfcells_d);
      free (C);
   }
   //nvcc -Xcompiler -fPIC -shared -o 2darray3.dll 2darray3.cu
  </code></pre>
  <p>python script</p>
  <pre><code>import numpy as np
  import ctypes
  from ctypes import * 
  
  def get_cuda_square():
      dll = ctypes.windll.LoadLibrary(&quot;C:\\Users\\Ali\\Desktop\\test9\\cuda_remember\\with 
  link python\\2darray3.dll&quot;) 
      func = dll.twodarray
      func.argtypes = [POINTER(c_double), POINTER(c_double), POINTER(c_double), 
  POINTER(c_double),POINTER(c_double) , POINTER(c_double)] 
      return func
  
  __cuda_square = get_cuda_square()
  
  size = int(24)
  
  cellbox_array = [[-0.35263609886169434, -0.35263609886169434, -0.35263609886169434] , 
  [0.35263609886169434, -0.35263609886169434, -0.35263609886169434] , 
  [-0.35263609886169434, 0.35263609886169434, -0.35263609886169434] , 
  [0.35263609886169434, 0.35263609886169434, -0.35263609886169434],[-0.35263609886169434, 
  -0.35263609886169434, 0.35263609886169434] , [0.35263609886169434, -0.35263609886169434, 
  0.35263609886169434],[-0.35263609886169434, 0.35263609886169434, 0.35263609886169434] , 
  [0.35263609886169434, 0.35263609886169434, 0.35263609886169434]]
  cellboxsize = c_double(len(cellbox_array))
  
  verticess_array = [0.1, 0.2, 0.3] , [0.4, 0.5, 0.6] ,[0.7, 0.8, 0.9] , [0.10, 0.11, 
  0.12],[0.13, 0.14, 0.15] , [0.16, 0.17, 0.18],[0.19, 0.20, 0.21] , [0.22, 0.23, 0.24]
  verticesssize = c_double(len(verticess_array))
  
  hfc_array = [1.7546,1.4456,1.4545544]
  cellbox = np.array(cellbox_array).astype('double')
  verticess = np.array(verticess_array).astype('double')
  hfc = np.array(hfc_array).astype('double')
  sc = np.array(cellboxsize).astype('double')
  sv = np.array(cellboxsize).astype('double')
  
  output = np.zeros(size).astype('double')
  
  a_p = output.ctypes.data_as(POINTER(c_double))
  c_p = cellbox.ctypes.data_as(POINTER(c_double))
  v_p = verticess.ctypes.data_as(POINTER(c_double))
  h_p = hfc.ctypes.data_as(POINTER(c_double))
  sc_p = sc.ctypes.data_as(POINTER(c_double))
  sv_p = sv.ctypes.data_as(POINTER(c_double))
  
  
  __cuda_square(a_p, c_p, v_p , h_p,sc_p , sv_p)
  print(output)
  </code></pre>
  <p>I can't get the value in python but when I run the tests with the cuda script it returns the correct result.</p>
  <p>for example:</p>
  <p>correct resoult (cuda):
  [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]</p>
  <p>Wrong result (python):
  [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]</p>
  <p>I did some tests on other scripts and found that the problem is probably with determining the appropriate data type for the values, but how can I solve this problem?</p>
  <p>thank you:)</p>
  <p>Note: The 1's in the output are for testing, and after the script is correct, I want to replace the decimal numbers that were the goal of the algorithm with 1's.</p>