matlab函数,大体首先是用nvcc命令生成.o文件,然后用mex链接对应库文件,生成动态链接库(.mexw64等)。推荐阅读:Matlab与C/C++联合编程之从Matlab调用C/C++代码 http://www.linuxidc.com/Linux/2012-08/68148.htm二分类SVM方法Matlab实现 http://www.linuxidc.com/Linux/2013-05/84050.htmMatlab中的取整函数fix, floor, ceil与round http://www.linuxidc.com/Linux/2013-10/91161.htm测试环境:1) Windows x64 + matlab + cuda 5.5 + vs20122) Ubuntu 12.04 amd64 server + matlab + gcc + cuda 5.5windows用户需要根据自身编译器更改函数第10行,改为cl.exe所在文件夹。如果第53行出错,请您在matlab中先mex -setup配置编译器。。。使用方法e.g.nvmex("a.cu");function nvmex(cuFileName) %NVMEX Compiles and links a CUDA file for MATLAB usage % NVMEX(FILENAME) will create a MEX-File (also with the name FILENAME) by % invoking the CUDA compiler, nvcc, and then linking with the MEX % function in MATLAB. if ispc % Windows
Host_Compiler_Location = "-ccbin "C:Program Files (x86)Microsoft Visual Studio 11.0VCinx86_amd64""; CUDA_INC_Location = [""" getenv("CUDA_PATH") "include""]; CUDA_SAMPLES_Location =[""" getenv("NVCUDASAMPLES5_5_ROOT") "commoninc""]; PIC_Option = ""; if ( strcmp(computer("arch"),"win32") ==1) machine_str = " --machine 32 "; CUDA_LIB_Location = [""" getenv("CUDA_PATH") "libWin32""]; elseif ( strcmp(computer("arch"),"win64") ==1) machine_str = " --machine 64 "; CUDA_LIB_Location = [""" getenv("CUDA_PATH") "libx64""]; end else % Mac and Linux (assuming gcc is on the path)