Compilation Error in nvcc and nvmex (fast knn search)

Hello,
In windows 7 64 bit , ı used visual studio 2010 and matlab 2012a. Now , I am responsble to use knn search algorithm with cuda codes. However , while compiling, i face with some problem which i could not find any solutions.

Until now, try :
1 Create nvccbat.bat by means of nvcc function.
2 nvcc knn_cuda_without_indexes.cu -lcuda -Ilibmx.lib -D_CRT_SECURE_NO_DEPRECATE
3 and get following error …

C:\Program Files\MATLAB\R2012a\extern\include>echo off
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
knn_cuda_without_indexes.cu
tmpxft_00000d7c_00000000-5_knn_cuda_without_indexes.cudafe1.gpu
tmpxft_00000d7c_00000000-10_knn_cuda_without_indexes.cudafe2.gpu
knn_cuda_without_indexes.cu
tmpxft_00000d7c_00000000-5_knn_cuda_without_indexes.cudafe1.cpp
tmpxft_00000d7c_00000000-15_knn_cuda_without_indexes.ii
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mexPrintf referenced in function “void __cdecl printErrorMessage(enum cudaError,int)” (?printErrorMessage@@YAXW4cudaError@@H@Z)
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mxGetPr referenced in function mexFunction
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mxCreateNumericMatrix_730 referenced in function mexFunction
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mexErrMsgTxt referenced in function mexFunction
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mxGetScalar referenced in function mexFunction
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mxGetN referenced in function mexFunction
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mxGetM referenced in function mexFunction
tmpxft_00000d7c_00000000-16_knn_cuda_without_indexes.obj : error LNK2019: unresolved external symbol mxGetData referenced in function mexFunction
LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
a.exe : fatal error LNK1120: 9 unresolved externals

I thought that these problems are related to libraries but ı could not solve the problem.
Then , I decided to use nvmex downloaded with knn search codes.

Firstly ,

nvmex -f nvmexopts64.bat knn_cuda_with_indexes.cu -I’C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include’ -L’C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\lib\x64’ -lcufft -lcudart -lcuda -D_CRT_SECURE_NO_DEPRECATE

Compiler gives an error about min function in knn_cuda_with_indexes.cu so I use macro and change two variables types from unsigned int to size_t called memory_total , memory_free. Then, I get following error, (unfortunately)

knn_cuda_without_indexes.cu
knn_cuda_without_indexes.cu
tmpxft_00001480_00000000-11_knn_cuda_without_indexes.compute_20.cudafe1.gpu
tmpxft_00001480_00000000-17_knn_cuda_without_indexes.compute_20.cudafe2.gpu
knn_cuda_without_indexes.cu
tmpxft_00001480_00000000-8_knn_cuda_without_indexes.compute_10.cudafe1.gpu
tmpxft_00001480_00000000-21_knn_cuda_without_indexes.compute_10.cudafe2.gpu
tmpxft_00001480_00000000-5_knn_cuda_without_indexes.compute_13.cudafe1.gpu
tmpxft_00001480_00000000-24_knn_cuda_without_indexes.compute_13.cudafe2.gpu
knn_cuda_without_indexes.cu
knn_cuda_without_indexes.cu
knn_cuda_without_indexes.cu
tmpxft_00001480_00000000-11_knn_cuda_without_indexes.compute_20.cudafe1.cpp
Could Not Find C:\Program Files\MATLAB\R2012a\extern\include\knn_cuda_without_indexes.mexw64.manifest

it creates a .mexw64 file but when call it, it gives a internal problem and closed itself.

I have read and tried to codes lots of suggestion for two days. However, I could not pass over these two errors.

If you can help me about one of two errors , please explain what solution is and how I can solve this problem.

Thanks in advance.

It might be some sort of path issue… can you put your scripts in the local directory you’re compiling? I have a working gmex/nvmex setup I ripped/modified from Accelereyes Jacket SDK… I’ve uploaded it to box here: https://www.box.com/s/7sgzuov3sw2w9r9mzpcd

You’ll need to tweak the files a bit to your specific paths/parameters, specifically gmex.m (args variable) and nvmexopts64.bat (paths at the top)… usage is simple:

Just make sure you put the files in the zip file in the same directory as your code and run gmex from matlab as above. Let me know if it works for you.

Edit: Uploaded new zip file w/ corrected gmex.m file.

Edit2: Another flag you might want to edit is COMPFLAGS in nvmexopts64.bat, as that contains the options that are passed to nvcc – the most important one of those is what compute capability architectures you are creating code for. e.g.:

-gencode=arch=compute_13,code=sm_13 // Tesla CC 1.3 (first arch with double support)
-gencode=arch=compute_20,code=sm_20 // Fermi GF100 CC 2.0
-gencode=arch=compute_20,code=sm_21 // Fermi GF104/106/108 CC 2.1
-gencode=arch=compute_30,code=sm_30 // Kepler CC 3.0
-gencode=arch=compute_35,code=sm_35 // 'Big' Kepler (GK110/GK208) CC 3.5

It works. Let me explain what to do.

I extracted all files into folder where I work on and changed paths in nvmexopts64.bat as you said. Then , I got an error similar to that CUDA lib and inc are not found. I think that I ran with wrong commands.Since I do not know about compilation of .cu ,I prefer to change Cuda lib and inc manually(by adding pathes in code instead of ‘getenv()’) and it works.

Thank you for your help.