フィルターのクリア

error LNK2019: unresolved external symbol when trying to MEX a C++ file containing CUDA

3 ビュー (過去 30 日間)
Peta
Peta 2016 年 10 月 1 日
編集済み: Bowen Jia 2020 年 2 月 8 日
I’m trying to mex a C++ file that uses CUDA. I have included the folder containing cublas.h etc when calling mex and I’ve linked to the library in my CUDA toolbox folder.
mex -v NIPALS_gpu.cpp -I'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include' -L'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64'
but when I run it, it produces the error:
Error using mex
Creating library NIPALS_gpu.lib and object NIPALS_gpu.exp
NIPALS_gpu.obj : error LNK2019: unresolved external symbol cublasSetVector referenced in function "void __cdecl cublasSnormalize(int,int,float *,float
*,float *)" (?cublasSnormalize@@YAXHHPEAM00@Z)
.
And about 10 other similar LNK2019 errors.
Does anyone have experience in mexing CUDA and know what the error is about? Do I need to include some additional file that I’ve missed? The file I’m trying to mex ( NIPALS_gpu.cpp) is not something I’ve written, its available online and likely does not contain any errors.

回答 (1 件)

Joss Knight
Joss Knight 2016 年 10 月 3 日
mex on its own does not automatically link in the CUDA libraries, so you will have to do that manually using -lcublas or similar. Your -L switch has added a library path but hasn't actually added any libraries.
Easier still is to use the MEX wrapper mexcuda which both automatically links in the CUDA libraries, and links in the GPU mex interface so that you can pass MATLAB gpuArray objects into your mex function. (Obviously, this is only available with Parallel Computing Toolbox.)
  2 件のコメント
Bob Khosh
Bob Khosh 2018 年 9 月 15 日
I do use "mexcuda" but i still get the following error:
Error using mex
Creating library mexMatrixMultiplication.lib and object
mexMatrixMultiplication.exp
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasCreate_v2 referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasDestroy_v2 referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasSetMatrix referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasGetMatrix referenced in function
mexFunction
mexMatrixMultiplication.obj : error LNK2019: unresolved
external symbol cublasDgemm_v2 referenced in function
mexFunction
mexMatrixMultiplication.mexw64 : fatal error LNK1120: 5
unresolved externals
Error in mexcuda (line 157)
[varargout{1:nargout}] = mex(mexArguments{:});
Bowen Jia
Bowen Jia 2020 年 2 月 8 日
編集済み: Bowen Jia 2020 年 2 月 8 日
Hi, Joss. I met the same question as Bob, is there anyway now to resolve this?
okay, I got this. Just like Joss said, add the "-lcublas" like ''mexcuda matrixmultiplacaiton.cu -lcublas''

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Compiler SDK についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by