-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvmex.m
28 lines (22 loc) · 909 Bytes
/
nvmex.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function nvmex(cuFileName, CUDA_LIB_Location, Host_Compiler_Location, PIC_Option)
%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.
% This portion taken from nvmex.m from 2009 The MathWorks, Inc.
[path, filename, ext] = fileparts(cuFileName);
nvccCommandLine = [ ...
'/usr/local/cuda/bin/nvcc --compile ' cuFileName ' ' Host_Compiler_Location ' ' ...
' -o ' filename '.o ' ...
PIC_Option ...
' -I' matlabroot '/extern/include ' ...
];
mexCommandLine = ['mex (''' filename '.o'', ''-L' CUDA_LIB_Location ''', ''-lcudart'')'];
disp(nvccCommandLine);
status = system(nvccCommandLine);
if status < 0
error 'Error invoking nvcc';
end
disp(mexCommandLine);
eval(mexCommandLine);
end