hi ,
i have been trying hard to compile my cuda matlab code wit nvmex , but not yet successful ,
is there any alternate method, to complie matlab cuda code ,
please suggests a way…
hi ,
i have been trying hard to compile my cuda matlab code wit nvmex , but not yet successful ,
is there any alternate method, to complie matlab cuda code ,
please suggests a way…
You can use cmake. I’ve posted an example cmake file before on the forum. If you search the forum for cmake matlab cuda, you will probably find it.
Does the tutorial you have posted also applies to MATLAB running on Windows?
thanks Riedijk,
for the reply,
i was jst a noob in cuda, n last tym i tried the make thing i was lost,
i was trying the approach , were we first compile matlab+cuda code , using nvmex and output as .cpp file
and then complie the .cpp with mex complier,
i was able to complie the code form nvmex,
but mex was putting wired errors . . .
Error ftest.cpp: C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h: 52 empty declaration
Error ftest.cpp: C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h: 52 syntax error; found “C” expecting ;' Error ftest.cpp: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\vadefs.h: 52 unrecognized declaration Error ftest.cpp: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\vadefs.h: 52 unrecognized declaration Error ftest.cpp: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\vadefs.h: 52 syntax error; found
uintptr_t’ expecting ;' Error ftest.cpp: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\vadefs.h: 52 unrecognized declaration Error ftest.cpp: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\vadefs.h: 61 empty declaration Error ftest.cpp: C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\vadefs.h: 61 syntax error; found "C" expecting
;’
Error ftest.cpp: C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h: 61 unrecognized declaration
Error ftest.cpp: C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h: 61 unrecognized declaration
Error ftest.cpp: C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h: 61 unrecognized declaration
Error ftest.cpp: c:\cuda\include\vector_types.h: 426 syntax error; found unsigned' expecting
)’
Error ftest.cpp: c:\cuda\include\vector_types.h: 426 undefined size for field incomplete struct dim3 defined at c:\\cuda\\include\\vector_types.h 422' Error ftest.cpp: c:\\cuda\\include\\vector_types.h: 426 syntax error; found
unsigned’ expecting ;' Error ftest.cpp: c:\\cuda\\include\\vector_types.h: 426 duplicate field name
x’ in incomplete struct dim3 defined at c:\\cuda\\include\\vector_types.h 422' Error ftest.cpp: c:\\cuda\\include\\vector_types.h: 426 syntax error; found
=’ expecting ;' Error ftest.cpp: c:\\cuda\\include\\vector_types.h: 426 skipping
=’ 1'
,’
Error ftest.cpp: c:\cuda\include\vector_types.h: 426 duplicate field name y' in
incomplete struct dim3 defined at c:\cuda\include\vector_types.h 422’
Error ftest.cpp: c:\cuda\include\vector_types.h: 426 syntax error; found =' expecting
;’
Error ftest.cpp: c:\cuda\include\vector_types.h: 426 skipping ='
1’ `,’
Error ftest.cpp: c:\cuda\include\vector_types.h: 426 too many errors
sir if u can give ny inputs on that , (i really have very less tym:( )
Yes, it works on linux 32/64 and windows 32/64.
nvmex is doing all the compilation for you, you do not need to compile with mex afterwards.
thanks , ,
ohhh god i have mentioned something wrong …
sorry , i have mentioned NVMEX, instread of NVCC
whti have done was frist i compiled successful code with NVCC
now when i complied that output code with MEX , then i was getting errors…
one more query, as i have used visual studio 2008 in NVCC , do i need the same in MEX as complier(matlab 2007 (not able to configure the MVS2008 in it))…
i am also uploading the code if that helps , , , (test1.cu orignal code
test1.cu (1.68 KB)
, , ftest.cpp after NVCC)
thanks in advance. . .
normally to compile cuda code for use in matlab you use NVMEX, not NVCC directly. But if you have a visual C++ version that is not supported by your MATLAB version that will not work.
So my advise is to just use cmake as I pointed out before. Any other road is probably a very painful one, and I doubt anyone has gone there before succesfully
Personally I’ve never gotten nvmex to work well. Much easier under linux, but what I do is to compile the cuda part as a library (static one preferably) or just an object file, and that compile the result with mex.
thanks laughingrice, and riedijk
i will look at the cmake approchs,
@ laughingrice
sir , can u elaborate the process you described , (some rough NVCC commands, and mex command) , and will this work in windows platform … … .
(earlier i was facing problems with linking object to files too so please introduce linking process in MEX too )
thank in advance,
I’ve got this in a make file (it’s a dumb one that I whipped up for convenience, can be made more generic)
all: loop_det_cu.mexa64
loop_det_cu.mexa64 : loop_det_cu.cpp loop_det_cu_kernel.h loop_det_cu_kernel.o
mex -O loop_det_cu.cpp loop_det_cu_kernel.o -L/usr/local/cuda/lib64/ -lcudart -I/usr/local/cuda/include/
loop_det_cu_kernel.o : loop_det_cu_kernel.cu
nvcc --ptxas-options -v -O3 -c --maxrregcount 64 loop_det_cu_kernel.cu --compiler-options -fPIC -arch sm_13
The kernel stuff is in loop_det_cu_kernel.cu, the mex stuff in loop_det_cu.cpp.
Will also work if you compile the mex stuff into a dynamic library (but will require putting the dll in the same directory as the mex file). Should also work under windows (probably with the same flags to nvcc which would produce a .obj file which you can use in the same manner)
I like this method since I usually test the code in matlab and then send it off to a c++ project so this way I keep the matlab and non-matlab codes separate
Another options is to compile the cuda stuff in visual studio as a static or dynamic library and use that instead of the object file, in which case you will need to use the -l flag to point to the library instead of just putting the object on the command line
thanks @laughingrice
you saved my life , thanks
i was able to make the .dll for matlab (which solved my pourpose)
but sir its wasn’t running :(
nvcc compiling was successfully and it made object file
but in linking the .obj file there were some errors
and while running .dll in matlab it run the MEX part successfully(errors and the mexprinf) but at time of calling cuda function there were many error …
(error i will post in nxt reply )
is it dude to two different compiler used (MVCP 2008 in nvcc )an Lcc in matlab2007 . . …?
thanks once again,
What were the errors, and how did you manage to make a mex file to run if there were link errors?
Did you link against the cuda libraries? you should call mex using something like
mex mexinterface.cpp cudacode.obj -L"C:\Cuda\lib" -lcudart
What if there is nothing in the cuda part (an empty funciton) and the next level, just allocate and free some cuda memory and then memory copies
Another thing, you need to call cudaThreadExit at the end of the mex program as matlab doesn’t cleanup the object and thus doesn’t free cuda resources implicitly (you will be allocating another cuda context on each call of your mex file).
Lastly, you are aware that matlab is column major and c (and thus cuda) row major. Make sure that you are using the correct problem dimensions.