日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab如何使用cu文件,Matlab编译cuda的.cu文件

發(fā)布時間:2023/12/4 循环神经网络 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab如何使用cu文件,Matlab编译cuda的.cu文件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

matlab函數(shù),大體首先是用nvcc命令生成.o文件,然后用mex鏈接對應(yīng)庫文件,生成動態(tài)鏈接庫(.mexw64等)。

測試環(huán)境:

1) Windows x64 + matlab + cuda 5.5 + vs2012

2) Ubuntu 12.04 amd64 server + matlab + gcc + cuda 5.5

windows用戶需要根據(jù)自身編譯器更改函數(shù)第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.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"'];

end

else % 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';

end

end

% !!! 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 < 0

error 'Error invoking nvcc';

end

disp(mexCommandLine);

eval(mexCommandLine);

end

總結(jié)

以上是生活随笔為你收集整理的matlab如何使用cu文件,Matlab编译cuda的.cu文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。