首页 > 代码库 > 在windows上编译MatConvNet

在windows上编译MatConvNet

有个BT的要求,在windows上使用MatConvNet,并且需要支持GPU。

费了些力气,记录一下过程(暂不支持vl_imreadjpeg函数)

在这里下载MatConvNet,机器预装vs2010,Matlab2014a,CUDA6.5。

  1. 进入Matlab,切换到{matconvnet_root}:
    1. mex -c -largeArrayDims -lmwblas "matlab/src/bits/im2col.cpp"
    2. mex -c -largeArrayDims -lmwblas "matlab/src/bits/pooling.cpp"  
    3. mex -c -largeArrayDims -lmwblas "matlab/src/bits/normalize.cpp"
    4. mex -c -largeArrayDims -lmwblas "matlab/src/bits/subsample.cpp"
  2. 打开VS command prompt,切换到{matconvnet_root}:
    1. nvcc -c -gencode=arch=compute_20,code=sm_21 -gencode=arch=compute_30,code=sm_30 --compiler-options=-fPIC "matlab/src/bits/im2col_gpu.cu"
    2. nvcc -c -gencode=arch=compute_20,code=sm_21 -gencode=arch=compute_30,code=sm_30 --compiler-options=-fPIC "matlab/src/bits/pooling_gpu.cu"

    3. nvcc -c -gencode=arch=compute_20,code=sm_21 -gencode=arch=compute_30,code=sm_30 --compiler-options=-fPIC "matlab/src/bits/normalize_gpu.cu"

    4. nvcc -c -gencode=arch=compute_20,code=sm_21 -gencode=arch=compute_30,code=sm_30 --compiler-options=-fPIC "matlab/src/bits/subsample_gpu.cu"

  3. 再次切换到Matlab:
    1. setenv(‘MW_NVCC_PATH‘,‘C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin‘)
    2. mex "matlab/src/vl_nnconv.cu" "normalize.obj" "normalize_gpu.obj" "pooling.obj" "pooling_gpu.obj" "subsample_gpu.obj" "subsample.obj" "im2col_gpu.obj" -DENABLE_GPU -f mex_CUDA_win64.xml -largeArrayDims -lmwblas -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\lib\x64" -lcublas -lcudart /NODEFAULTLIB:LIBCMT.lib

    3. mex "matlab/src/vl_nnnormalize.cu" "normalize.obj" "normalize_gpu.obj" "pooling.obj" "pooling_gpu.obj" "subsample_gpu.obj" "subsample.obj"  "im2col_gpu.obj" -DENABLE_GPU -f mex_CUDA_win64.xml -largeArrayDims -lmwblas -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\lib\x64" -lcublas -lcudart /NODEFAULTLIB:LIBCMT.lib
    4. mex "matlab/src/vl_nnpool.cu" "normalize.obj" "normalize_gpu.obj" "pooling.obj" "pooling_gpu.obj" "subsample_gpu.obj" "subsample.obj" "im2col_gpu.obj" -DENABLE_GPU -f mex_CUDA_win64.xml -largeArrayDims -lmwblas -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\lib\x64" -lcublas -lcudart /NODEFAULTLIB:LIBCMT.lib

编译完成,运行‘matlab/xtest/vl_test_nnlayers(1)‘通过。大概就是这个样子。

听小J说,有个比较奇怪的地方:在做卷积的时候,在GTX980、GTX970显卡上会报错。仔细验证过,不是CUDA SDK的问题,也不是显卡驱动的问题,使用GTX660这些显卡无异常。初步怀疑可能由于Maxwell架构指令集与Kepler架构指令集不兼容导致。不过这些就不是我要考虑的了。

 

在windows上编译MatConvNet