cuSVM is a CUDA implementation of support vector classification and regression. Recently, I had some questions on a post regarding compiling cuSVM using Visual Studio. Out of curiosity, I downloaded cuSVM and went to work myself.
Now, if you just download cuSVM and open up the Visual Studio solution, you will be a bit dissapointed as it does not compile and is not contained in a CUDA project. In order to correct this, I took the steps listed below. While I encourage you to read the steps and complete this process yourself, you may also download the files used in this project by clicking here.
- Create a new CUDA 4.0 Project called "cuSVMPredict"
- Create a new CUDA 4.0 Project called "cuSVMTrain"
- Add the appropriate files from the original cuSVM project. This is done by copying each file into the correct location on the file system, right-clicking on the project and selecting "Add -> Existing Item...". The files needed include:
- For cuSVMPredict: cuSVMPredict.cpp, cuSVMPredictKernel.cu, PredictModule.def
- For cuSVMTrain: cuSVMTrain.cpp, cuSVMSolver.cu, TrainModule.def
- Copy the "inc" directory into the root of the solution
- Open up the file "cuSVMSolver.cu" in the "cuSVMTrain" project
- Add "using namespace std;" on line 17, after the final include statement
- For each project, right-click on the project and select "Properties"
- Make the following changes:
- Under "Configuration Properties -> General":
- Change "Target Extension" to ".mexw32"
- Change "Configuration Type" to "Dynamic Library (.dll)"
- Under "Configuration Properties -> C/C++ -> General -> Additional Include Directories":
- Add your Matlab include directory (MATLABDIR\extern\include)
- Add "..\inc"
- Add the CUDA GPU Computing SDK include directory. On Windows 7 this is "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\inc"
- Under "Configuration Properties -> CUDA C/C++ -> Common -> Additional Include Directories":
- Add your Matlab include directory (MATLABDIR\extern\include)
- Add the CUDA GPU Computing SDK include directory. On Windows 7 this is "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\inc"
- Under "Configuration Properties -> Linker -> General -> Additional Library Directories":
- Add your Matlab include directory (MATLABDIR\extern\lib\win32\microsoft)
- Add the CUDA GPU Computing SDK bin directory. On Windows 7 this is "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\bin"
- Under "Configuration Properties -> Linker -> Input -> Additional Dependencies":
- Add "cuda.lib"
- Add "cublas.lib"
- Add "libmex.lib"
- Add "libmat.lib"
- Add "libmx.lib"
- Under "Configuration Properties -> General":
- Right-click on the solution and select "Build Solution"
Having completed these steps, you should be good to go.
Oh, I don't know how to thank you. I currently trying these steps. but before starting, I have some suggestion to edit this note:
-in step 3 the cuSVMPredict has a .def file too.
-The path of step 4 should replace with the path of step 5.
-In the step 5, some library path should be added, (not include path), they can be matlab lib-folder and gpu computing sdk and cuda toolkit lib-folder.
After completing the above steps, I will report the result.
Thank you.
Hi, Finally I successfully build the .mexw64 version of cuSVM.
My mistakes are the followings:
-I added the library and include directories only in this path: tools->options->...->vc++ directories
-I did not add "using namespace std;" to line 17 of *.cu file
PROBLEM WITH CUDA VERSION:
After I did the required steps, the number errors decrease from 101 to 5.
The error was in line 623, 952. because of cuMemGetInfo:
error: argument of type "unsigned int *" is incompatible with parameter of type "size_t *".
I found from nvidia tech. report for cuda 3.2 that:
Driver API functions that accept or return memory sizes, such as cuMemAlloc() and cuMemGetInfo(), now use size_t for this purpose rather than unsigned int.
so this change must be done in the .cu code:
Incorrect code:
unsigned int free, total;
cuMemGetInfo(&free, &total);
Correct code:
size_t free, total;
cuMemGetInfo(&free, &total);
PROBLEM WITH VISUAL STUDIO 2008
updating the .cu code, I expected the cuSVM now runs, but I got the following error:
fatal error LNK1000: Internal error during IncrBuildImage
downloading the microsoft hotfix for visual studio 2008 can solve this problem:
http://support.microsoft.com/kb/948127
and now .mexw64 is build. I didn't test this file in Matlab yet.
Lily,
Thanks for all your feedback, particularly regarding Visual Studio 2008. Glad this is close to working for you.
it's my pleasure.
Hi,
I test the produced *.mexw64 file, with a sample input training data. unfortunately this error is appeared, and I don't know what is going wrong.
??? One or more output arguments not assigned during call to "cusvm_cuda_mex".
The test code that I wrote is:
load heart_scale.mat;
data = heart_scale_inst;
value = heart_scale_label;
C = 10;
kernel = 0.5;
stopcrit = 0.001;
[alphas, beta, svs] = cusvm_cuda_mex(value, data, C, kernel, [], stopcrit);
I think that output arguments of the mexFunction is allocated properly, for example for plhs[0] we have:
plhs[0]=mxCreateNumericMatrix(numSVs, 1,mxSINGLE_CLASS, mxREAL);
float *SvAlphas=(float*)mxGetData(plhs[0]);
in this link ( http://www.mathworks.com/matlabcentral/newsreader/view_thread/166716 ) I found a similar problem with "mxCreateNumericMatrix" but I don't know what is the correct solution.
After such a long stressing effort I failed to use cuSVM in 64-bit MATLAB.
Lily,
I'm sorry you've been unable to get this to work. I would contact the creator of cuSVM as well.
It's ok.
. Currently the programmer is not member of their team. I will try to solve the problem.
I apologise for bothering you. If I found the solution, I will report the result here for others that may have a similar problem.
Thanks for taking the effort to document this. I ended up adding the ..\inc directory to my additional includes for CUDA to get it to compile. Also, I am using CUDA 4.1, not 4.0. After making the changes the solution builds without error. In matlab, though, I get an error when I try to run.
Mex file entry point is missing. Please check the (case-sensitive)
spelling of mexFunction (for C MEX-files), or the (case-insensitive)
spelling of MEXFUNCTION (for FORTRAN MEX-files).
Invalid MEX-file 'u:\monkey\share\cuSVM\cuSVM\x64\Release\cuSVMPredict.mexw64': The specified module could not be
found.
Usually this means that a dll is missing, right? I opened the .mexw64 file in depends and added all the dlls listed there to the same directory as the .mexw64, but still the same error. Any ideas? I noticed that your build directory just has the cudart* files.
I am still trying to find the solution, I asked the problem in stackoverflow:
http://stackoverflow.com/questions/9530553/missing-dll-running-32-bit-vs2005-cuda-project-using-vs2008-in-64-bit
I doubt that I correctly explained the problem there.
http://www.mathworks.com/support/solutions/en/data/1-6GDQZ6/index.html?product=CO&solution=1-6GDQZ6
Dear jeff
Please check the above link instructions, and see if the problem can be solved. My error is slightly different from you, invalid mex message says that "The specified "PROCEDURE" could not be
found". I still can not solve that.
Thank you.
I found out that I needed to add the module def file to the linker input. My old error does not occur, but Matlab crashes. At least this is progress. Thanks
Dear Lily,
I also have the same problem,followed as "
Mex file entry point is missing. Please check the (case-sensitive)
spelling of mexFunction (for C MEX-files), or the (case-insensitive)
spelling of MEXFUNCTION (for FORTRAN MEX-files)."
have you solved it ?
thank you
Hello friends,
Unfortunately I temporarily gave-up the cuSVM because of the workload of my thesis.
Here is the full description of what I did, in MATLAB answers website:
http://www.mathworks.com/matlabcentral/answers/31109-invalid-mex-file-the-specified-procedure-could-not-be-found-calling-a-cuda-mex-function
I still want to find a solution for the cuSVM problem.