title: cublas device api outputs weird result
body: <p>everyone:
  Recently I have tried to utilize the most recent property of cuda 5.5 to program, i.e., dynamic parallelism. But I have some very confusing problem. My code is here:</p>
  <pre><code>    /* Includes, system */
      #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;string.h&gt;
      #include &lt;iostream&gt;
      using namespace std;
      /* Includes, cuda */
      #include &lt;cuda_runtime.h&gt;
      #include &lt;cublas_v2.h&gt;
      
      /* Includes, cuda helper functions */
      #include &lt;helper_cuda.h&gt;
      
      #include &quot;kernels.cu&quot;
      /* Matrix size */
      #define N  (275)
      
      #define LengthSignal (64)
      
      #define AmountSignal (255025)
      
      #define NBLOCKX (32768)
      
      #define NTHREADS_PER_BLOCK (128)
      /* Declaration of the function that computes sgemm using CUBLAS device API */
      
      __global__ void invokeDeviceCublasSgemm(float *d_A, float *Test);
      
      /* Main */
      int main(int argc, char **argv)
      {
        float *h_A;
        float *d_A = 0;
        int n2 = N * N;
      
        h_A = (float *)malloc(n2 * sizeof(h_A[0]));
    /* Fill the matrices with test data */
    for (int i = 0; i &lt; n2; i++)
      {
        h_A[i] = rand() / (float)RAND_MAX;
      }
  
        cudaMalloc((void **)&amp;d_A, n2 * sizeof(h_A[0]));
      
        /* Initialize the device matrices with the host matrices */
        //  cudaMemcpy(d_A, h_A, sizeof(float) * LengthSignal * AmountSignal, cudaMemcpyHostToDevice);
        cudaMemcpy(d_A, h_A, n2 * sizeof(h_A[0]), cudaMemcpyHostToDevice);
      
        int Length = 100;
        float *h_Test = (float *) malloc(sizeof(float) * Length);
        float *d_Test;
        cudaMalloc((void **) &amp;d_Test, sizeof(float) * Length);
        cudaMemset(d_Test, 0, sizeof(float) * Length);
  
    invokeDeviceCublasSgemm&lt;&lt;&lt;NBLOCKX, NTHREADS_PER_BLOCK&gt;&gt;&gt;(d_A, d_Test);
    cudaMemcpy(h_Test, d_Test, sizeof(float) * Length, cudaMemcpyDeviceToHost);
  
    printf(&quot;\n The first 10 elements of d_A in location 1 are: \n&quot;);
    for (int j = 0; j &lt; 10; j ++)
      {
        printf(&quot;%f &quot;, h_Test[j]);
      }
  
    printf(&quot;\n The first 10 elements of d_A in location 2 are: \n&quot;);
    for (int j = 10; j &lt; 20; j ++)
      {
        printf(&quot;%f &quot;, h_Test[j]);
      }
    printf(&quot;\n&quot;);
  
    free(h_Test);
    cudaFree(d_Test);
  
    /* Memory clean up */
    free(h_A);
    cudaFree(d_A);
  }
  </code></pre>
  <hr />
  <pre><code>#ifndef __GLOBAL__CU__
  #define __GLOBAL__CU__
  
  __global__ void invokeDeviceCublasSgemm(float *d_A, float *Test)
  {
    // save the first 10 elements of d_A in location 1
    for (int j = 0; j &lt; 10; j ++)
      {
        Test[j] = d_A[j];
      }
    cublasHandle_t cnpHandle;
    cublasCreate(&amp;cnpHandle);
  
      // save the first 10 elements of d_A in location 2
      for (int j = 10; j &lt; 20; j ++)
        {
          Test[j] = d_A[j - 10];
        }
    cublasDestroy(cnpHandle);
  }
  
  #endif
  </code></pre>
  <hr />
  <p>If I set the configuration parameters as &lt;&lt;&lt;1, 1&gt;&gt;&gt;, everything works well. And the output is like that:</p>
  <p>The first 10 elements of d_A in location 1 are:</p>
  <p>0.840188 0.394383 0.783099 0.798440 0.911647 0.197551 0.335223 0.768230 0.277775 0.553970</p>
  <p>The first 10 elements of d_A in location 2 are:</p>
  <p>0.840188 0.394383 0.783099 0.798440 0.911647 0.197551 0.335223 0.768230 0.277775 0.553970</p>
  <p>However, if I set the configuration parameters as &lt;&lt;&lt;32768, 128&gt;&gt;&gt;, the output is quite weird. And the output is like that:</p>
  <p>The first 10 elements of d_A in location 1 are:</p>
  <p>-0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000</p>
  <p>The first 10 elements of d_A in location 2 are:</p>
  <p>0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000</p>
  <p>I really don't know why! My code is just come from the &quot;samples&quot; with a little change.</p>
  <hr />
  <p>And then I just delete the last code &quot;cublasDestroy(cnpHandle);&quot;, then it becomes normal. And the output is:</p>
  <p>The first 10 elements of d_A in location 1 are:</p>
  <p>0.840188 0.394383 0.783099 0.798440 0.911647 0.197551 0.335223 0.768230 0.277775 0.553970</p>
  <p>The first 10 elements of d_A in location 2 are:</p>
  <p>0.840188 0.394383 0.783099 0.798440 0.911647 0.197551 0.335223 0.768230 0.277775 0.553970</p>
  <hr />
  <p>Did someone have the same problem?</p>
  <p>Thanks!</p>