-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_mcnIm2row.m
66 lines (57 loc) · 2.73 KB
/
compile_mcnIm2row.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function compile_mcnIm2row(varargin)
% COMPILE_MCNIM2ROW compile the C++/CUDA components of the mcnIm2row module
tokens = {vl_rootnn, 'matlab', 'mex', '.build', 'last_compile_opts.mat'} ;
last_args_path = fullfile(tokens{:}) ; opts = {} ;
if exist(last_args_path, 'file'), opts = {load(last_args_path)} ; end
opts = selectCompileOpts(opts) ;
vl_compilenn(opts{:}, varargin{:}, 'preCompileFn', @preCompileFn) ;
% -------------------------------------
function opts = selectCompileOpts(opts)
% -------------------------------------
% really need a better fix at some point
keep = {'enableGpu', 'enableImreadJpeg', 'enableCudnn', 'enableDouble', ...
'imageLibrary', 'imageLibraryCompileFlags', ...
'imageLibraryLinkFlags', 'verbose', 'debug', 'cudaMethod', ...
'cudaRoot', 'cudaArch', 'defCudaArch', 'cudnnRoot', 'preCompileFn'} ;
s = opts{1} ;
f = fieldnames(s) ;
for i = 1:numel(f)
if ~ismember(f{i}, keep)
s = rmfield(s, f{i}) ;
end
end
opts = {s} ;
% -----------------------------------------------------------------------------
function [opts, mex_src, lib_src, flags] = preCompileFn(opts, mex_src, lib_src, flags)
% -----------------------------------------------------------------------------
mcn_root = vl_rootnn() ;
root = fullfile(fileparts(mfilename('fullpath')), 'matlab') ;
% Build inside the module path
flags.src_dir = fullfile(root, 'src') ;
flags.mex_dir = fullfile(root, 'mex') ;
flags.bld_dir = fullfile(flags.mex_dir, '.build') ;
implDir = fullfile(flags.bld_dir,'bits/impl') ;
if ~exist(implDir, 'dir'), mkdir(implDir) ; end
mex_src = {} ; lib_src = {} ;
if opts.enableGpu, ext = 'cu' ; else, ext = 'cpp' ; end
% Add mcn dependencies
lib_src{end+1} = fullfile(mcn_root, 'matlab/src/bits', ['data.' ext]) ;
lib_src{end+1} = fullfile(mcn_root, 'matlab/src/bits', ['datamex.' ext]) ;
lib_src{end+1} = fullfile(mcn_root,'matlab/src/bits/impl/copy_cpu.cpp') ;
lib_src{end+1} = fullfile(mcn_root,'matlab/src/bits/impl/im2row_cpu.cpp') ;
if opts.enableGpu
lib_src{end+1} = fullfile(mcn_root,'matlab/src/bits/datacu.cu') ;
lib_src{end+1} = fullfile(mcn_root,'matlab/src/bits/impl/copy_gpu.cu') ;
lib_src{end+1} = fullfile(mcn_root,'matlab/src/bits/impl/im2row_gpu.cu') ;
end
% ----------------------
% include required files
% ----------------------
% old style include - leave as comment in case users have different setup
%if ~isfield(flags, 'cc'), flags.cc = {inc} ; else, flags.cc{end+1} = inc ; end
% new style include
inc = sprintf('-I"%s"', fullfile(mcn_root,'matlab','src')) ;
inc_local = sprintf('-I"%s"', fullfile(root, 'src')) ;
flags.base{end+1} = inc ; flags.base{end+1} = inc_local ;
% Add module files
mex_src{end+1} = fullfile(root,'src',['vl_nnim2row.' ext]) ;