Can not compile cublas file in windows10

I am newbie to cublas, I want test my cublas code.

#include <cuda_runtime.h>
#include "cublas_v2.h"
#include <stdio.h>
#include <time.h>

int main()
{
    float *a,*b;
    cudaMallocManaged(&a,sizeof(float)*10'0000);
    cudaMallocManaged(&b,sizeof(float)*10'0000);

    srand(time(NULL));
    for(int i=0;i!=10'0000;++i)
    {
        a[i]=(float)rand()/RAND_MAX;
    }
    for(int i=0;i!=10'0000;++i)
    {
        b[i]=(float)rand()/RAND_MAX;
    }
    //cuBLAS handle
    cublasStatus_t cuStat;
    cublasHandle_t cuHandle;

    cuStat=cublasCreate(&cuHandle);
    float alpha=1.0;
    cublasSaxpy(cuHandle,10'0000,&alpha,a,1,b,1 );

    cublasDestroy(cuHandle);
    cudaFree(a);
    cudaFree(b);
    return 0;
}

I use

nvcc .\cublasTest.cu -o cublasTest -lcublas

compile this file, it shows :
"

error LNK2019: Unresolved external symbol cublasCreate_v2,cublasDestroy_v2,cublasSaxpy_v2, referenced in function main

".
How to fix this link error?
And this file work fine in MSVC, it seems nvcc can not link cublas.

I fix this by reinstall cuda toolkit in win10.
Now it worked in nvcc and msvc.

1 Like

Thanks for sharing the solution!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.