Matlab编译cuda的.cu文件
来源:互联网 发布:自动化编程语言 编辑:程序博客网 时间:2024/06/05 00:54
matlab函数,大体首先是用nvcc命令生成.o文件,然后用mex链接对应库文件,生成动态链接库(.mexw64等)。
测试环境:
1) Windows x64 + matlab + cuda 5.5 + vs2012
2) Ubuntu 12.04 amd64 server + matlab + gcc + cuda 5.5
windows用户需要根据自身编译器更改函数第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 % WindowsHost_Compiler_Location = '-ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"';CUDA_INC_Location = ['"' getenv('CUDA_PATH') '\include"']; CUDA_SAMPLES_Location =['"' getenv('NVCUDASAMPLES5_5_ROOT') '\common\inc"']; PIC_Option = ''; if ( strcmp(computer('arch'),'win32') ==1) machine_str = ' --machine 32 '; CUDA_LIB_Location = ['"' getenv('CUDA_PATH') '\lib\Win32"']; elseif ( strcmp(computer('arch'),'win64') ==1) machine_str = ' --machine 64 '; CUDA_LIB_Location = ['"' getenv('CUDA_PATH') '\lib\x64"']; endelse % Mac and Linux (assuming gcc is on the path) CUDA_INC_Location = '/usr/local/cuda/include'; CUDA_SAMPLES_Location = '/usr/local/cuda/samples/common/inc';Host_Compiler_Location = ' ';PIC_Option = ' --compiler-options -fPIC '; machine_str = []; if ( strcmp(computer('arch'),'win32') ==1) CUDA_LIB_Location = '/usr/local/cuda/lib'; elseif ( strcmp(computer('arch'),'win64') ==1) CUDA_LIB_Location = '/usr/local/cuda/lib64'; endend% !!! End of things to modify !!![~, filename] = fileparts(cuFileName);nvccCommandLine = [ ...'nvcc --compile ' Host_Compiler_Location ' ' ...'-o ' filename '.o ' ...machine_str PIC_Option ...' -I' '"' matlabroot '/extern/include "' ...' -I' CUDA_INC_Location ' -I' CUDA_SAMPLES_Location ...' "' cuFileName '" ' ];mexCommandLine = ['mex ' filename '.o' ' -L' CUDA_LIB_Location ' -lcudart'];disp(nvccCommandLine);warning off;status = system(nvccCommandLine);warning on;if status < 0error 'Error invoking nvcc';enddisp(mexCommandLine);eval(mexCommandLine);end
0 0
- Matlab编译cuda的.cu文件
- CUDA: VS中同时编译.cpp文件与.cu文件
- 为cuda设置环境变量,编译.cu文件时,加载库
- matlab中编译cuda文件
- 编译64位cu文件的设置
- 使用matlab函数编译cuda文件
- CUDA常见问题之无法在c文件中调用cu文件中定义的函数
- CUDA 问题解决 ——在 c 文件中调用 cu 文件中定义的函数失败
- 让vs2005支持NVDIA CUDA的cu文件语法高亮显示
- CUDA文件Visual Assist 添加支持*.cu文件
- 编译包含double类型的cuda文件
- 关于matlab使用mex编译CUDA的诸多配置问题
- 【CUDA学习-原创】包含C和.cu的工程实现!
- CUDA: 包含C和.cu的工程实现
- CUDA文件编译命令行
- CUDA文件编译错误
- .cu文件
- NVIDIA CUDA clock.cu 代码
- 关于HBase0.94版本在split region后META Scanner和CatalogJanitor并发操作时存在的问题
- linux内存模型
- uva 10318 - Security Panel(dfs+剪枝)
- android布局管理器之TableLayout
- [Linux] Linux使用中的一些记录
- Matlab编译cuda的.cu文件
- 拓扑排序
- 僵尸进程与孤儿进程
- spring3.1与hibernate4集成配置
- Linux常用命令
- Java Thread.join详解
- 牛人必修 Ant编译android工程 ,并Proguard代码混淆,v4混淆配置
- 《Linux操作系统下C语言编程入门》 - linux 进程
- lucene&solr cache在sort、facet等方面的应用解析