0

I want to multiply two 2x2 matrix on a GPU, but I am getting this error. Here is my code and the error.

#include <cublas_v2.h>
#include <iostream>
#include <cuda.h>
#include <curand.h>
#include <curand_kernel.h>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>

int main(){
  int nr_rows_A, nr_cols_A, nr_rows_B, nr_cols_B, nr_rows_C, nr_cols_C;
  // for simplicity we are going to use square arrays
  nr_rows_A = nr_cols_A = nr_rows_B = nr_cols_B = nr_rows_C = nr_cols_C = 2;
  int m, n, k, lda, ldb, ldc; 
  m = n = k = lda = ldb = ldc= nr_rows_A;

  thrust::device_vector<float> d_A(nr_rows_A * nr_cols_A), d_B(nr_rows_B * nr_cols_B), d_C(nr_rows_C * nr_cols_C);
  thrust::sequence(d_A.begin(), d_A.end(),1);
  thrust::sequence(d_B.begin(), d_B.end(),5);

  const float * dv_ptra = thrust::raw_pointer_cast(&d_A[0]);
  const float * dv_ptrb = thrust::raw_pointer_cast(&d_B[0]); 
  float * dv_ptrc = thrust::raw_pointer_cast(&d_C[0]); 


  cublasHandle_t handle;
  cublasCreate(&handle);

  float alpha = 1;
  float beta =0;

  cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, k, &alpha, dv_ptra, lda, dv_ptrb, ldb, &beta, dv_ptrc, ldc);

  cublasDestroy(handle);

  for(int i = 0; i < nr_rows_A * nr_cols_A; i++){
    std::cout<<d_C[i]<<std::endl;
  }


 }

Here is the error I am getting:

 Creating library a.lib and object a.exp
 tmpxft_000020a4_00000000-19_inverse.obj : error LNK2019: unresolved external symbol cublasCreate_v2 
 referenced in function main
 tmpxft_000020a4_00000000-19_inverse.obj : error LNK2019: unresolved external symbol cublasDestroy_v2 
 referenced in function main
 tmpxft_000020a4_00000000-19_inverse.obj : error LNK2019: unresolved external symbol cublasSgemm_v2 
 referenced in function main
 a.exe : fatal error LNK1120: 3 unresolved externals
talonmies
  • 70,661
  • 34
  • 192
  • 269
  • 4
    The error isn't in your code it is in your Visual Studio project settings. You are not linking the CUBLAS library – talonmies Apr 28 '21 at 07:55
  • How do you compile your code? Look at this: https://stackoverflow.com/questions/64113574/undefined-reference-to-cublascreate-v2-in-tmp-tmpxft-0000120b-0000000-10-my – Ho1 Apr 28 '21 at 09:23

0 Answers0