cuSVM for CUDA 6.0 and Matlab x64
Posted by Hemprasad Y. Badgujar on October 13, 2014
cuSVM for CUDA 6.0 and Matlab x64

This page shows how to build cuSVM, GPU accelerated SVM with dense format. Library has been written by AUSTIN CARPENTER. The procedure use CUDA 6.0, MATLAB x64 and Visual Studio 2012. The code and project files were modified in order to compile and link library, many steps were taken from http://www.parallelcoding.com/2012/02/09/cusvm-in-visual-studio-2010-with-cuda-4-0/
Modifications:
- Addmatlab variables:
- cuSVMTrainIter – contains number of iteration the solver does
- cuSVMTrainObj – contains the final objective function value after the trainning
- In file cuSVMSolver.cu lines 869-874 all calls of cudaMemcpyToSymbol was changed, because of changes made in CUDA 6.0 runtime library –http://stackoverflow.com/questions/12947914/error-in-cudamemcpytosymbol-using-cuda-5
before the change:
mxCUDA_SAFE_CALL(cudaMemcpyToSymbol(„taumin”, &h_taumin, sizeof(float) ));
after the change:
mxCUDA_SAFE_CALL(cudaMemcpyToSymbol(taumin, &h_taumin, sizeof(float) )); - In functions FindBI, FindBJ, FindStoppingJ – change the way reduction in shared memory was done (http://stackoverflow.com/questions/6510427/cuda-finding-max-using-reduction-error)
- The kernel cache size is constrained to 400MB, if you want bigger cache you can modify cuSVMSolver.cu line 24
#define KERNEL_CACHE_SIZE (400*1024*1024)
Build Procedure
All steps describe below are done, you have to check if all paths are set correctly and yours GPU computational capability is set properly.
My setup:
- windows 7 x64
- visual studio 2012
- CUDA 6.0
- Matlab R2014a
- the code was tested on Quadro 5000 and Geforce GTX 580
Prerequisites:
Determine paths:
- Matlab include path, mine is „D:\Program Files\MATLAB\R2014a\extern\include” (Matlab was installed on drive d:\)
- Matlab library path: „D:\Program Files\MATLAB\R2014a\extern\lib\win64\microsoft”
- CUDA toolkit include path: „C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include”
- GPU compute capability, mine is 1.2 in case of GeForce GT 330M(compute_12,sm_12), and 3.0 in case GeForce GTX 690 (compute_30,sm_30)
Changes made in projects properties (the same steps are for both projects: cuSVMPredict, cuSVMTrain):
- Open solution in VS 2010
- Right click on project (cuSVMTrain or cuSVMPredict) and choose „Build Customizations …”, make sure that „CUDA 5.0(.targets, .props)” is checked
- Right click oncuSVMTrain and choose project „Properties”
- Expand „Configuration Properties”
- General->Target Extension: .mexw64
- General->Configuration Type: Dynamic Library (.dll)
- Expand c/c++-
- General->Additional Include Directories: $(SolutionDir)inc\;D:\Program Files\MATLAB\R2014a\extern\include;$(CudaToolkitIncludeDir);%(AdditionalIncludeDirectories)
- ExpandCUDA C/C++
- Common->Additional Include Directories: $(SolutionDir)inc\;D:\Program Files\MATLAB\R2014a\extern\include;$(CudaToolkitIncludeDir);%(AdditionalIncludeDirectories)
- Common->Target Machine Platform: 64-bit (–machine 64)
- Device->Code Generation: compute_30,sm_30– this depends on your GPU compute capability
- Expand Linker
- General->Additional Library Directories: %(AdditionalLibraryDirectories); $(CudaToolkitLibDir); D:\Program Files\MATLAB\R2014a\extern\lib\win64\microsoft
- Input->Additional Dependencies: cuda.lib;cublas.lib;libmex.lib;libmat.lib;libmx.lib;cudart.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
- Input->Module Definition File: TrainModule.def (for cuSVMTrain project, for cuSVMPredict set PredictModule.def)
- Expand Build Events
- Post-Build Event->Command Line:
echo copy „$(CudaToolkitBinDir)\cudart*.dll” „$(OutDir)”
copy „$(CudaToolkitBinDir)\cudart*.dll” „$(OutDir)”
each command in separate line
- Post-Build Event->Command Line:
- Expand „Configuration Properties”
Eventually you can check if it is „Release” or „Debug” build.
How to use cuSVM
The zip package contains two folders:
- cuSVM – Visual Studio 2012 solution
- cuSVMmatlab – contains:
- libsvm,
- compile cuSVMTrain.mexw64 and cuSVMPredict.mexw64 in Libfolder,
- sample datasets in datafolder
- matlab script cuSVMTest.m
- Build cuSVM in Release or Debug mode – important check your GPU compute capability
- Copy cuSVMTrain.mexw64 and cuSVMPredict.mexw64 to Lib folder
- Add Libfolder matlab search path.
- If you want classify some dataset open mfile.


Leave a comment