title: cublasSgemm row-major multiplication
body: <p>I'm trying to use cublasSgemm to multiplicity two non-square matrices that are stored in row-major order. I know that this function has one parameter where you can specify that if you want to transpose the matrices (CUBLAS_OP_T) but the result is stored in column-major order and I need it in row-major too. </p>
  
  <p>Also,the code I have is not capable of multiplying non-square matrices with the parameter CUBLAS_OP_T. Only square or non-square with CUBLAS_OP_N.</p>
  
  <p>Besides, I know that there are the option to declare the matrices in column-order with </p>
  
  <pre><code>define IDX2C(i,j,ld) (((j)*(ld))+(i)) 
  </code></pre>
  
  <p>but this isn't an option because the matrices that I have to use will be set in other program.</p>
  
  <p>I suppose that there is a lot of information on the internet, but I'm not able to find any answer to my question.</p>
  
  <p>my code is the following:</p>
  
  <pre><code>
      int m = 2;
      int k = 3;
      int n = 4;
      int print = 1;
      cudaError_t cudaStat; // cudaMalloc status
      cublasStatus_t stat; // CUBLAS functions status
      cublasHandle_t handle; // CUBLAS context
  
      int i,j;
  
      float *a, *b,*c;
  
      //malloc for a,b,c...
  
      // define a mxk matrix a row by row
      int ind =11;                               
      for(j=0;j&lt;m*k;j++){                     
          a[j]=(float)ind++;                                    
      }                                        
  
      // define a kxn matrix b column by column
      ind =11;                               
      for(j=0;j&lt;k*n;j++){                     
          b[j]=(float)ind++;                                    
      }                                        
  
  
      // DEVICE
      float *d_a, *d_b, *d_c; 
  
      //cudaMalloc for d_a, d_b, d_c...
  
      stat = cublasCreate(&amp;handle); // initialize CUBLAS context
  
      stat = cublasSetMatrix(m,k, sizeof(*a), a, m, d_a, m);
      stat = cublasSetMatrix(k,n, sizeof(*b), b, k, d_b, k); 
  
      float al =1.0f;
      float bet =0.0f; 
  
      stat=cublasSgemm(handle,CUBLAS_OP_T,CUBLAS_OP_T,m,n,k,&amp;al,d_a,m,d_b,k,&amp;bet,d_c,m);
  
      stat = cublasGetMatrix (m,n, sizeof (*c) ,d_c ,m,c,m); // cp d_c - &gt;c
  
      if(print == 1) {
      printf ("\nc after Sgemm :\n");
          for(i=0;i&lt;m*n;i++){
                  printf ("%f ",c[i]); // print c after Sgemm
          }
      }
  
      cudaFree (d_a); 
      cudaFree (d_b); 
      cudaFree (d_c);
      cublasDestroy (handle); // destroy CUBLAS context
      free (a); 
      free (b); 
      free (c); 
  
      return EXIT_SUCCESS ;
  }
  </code></pre>
  
  <p>The output is the transpose of multiplying A * B, that is: (A * B)T.</p>
  
  <p>But what I want is C = A * B in row-major order.</p>
  
  <p>I hope someone can help me.</p>