1. 程式人生 > >【記錄】 編譯matconvnet on ubuntu16.04 with cuda 9.0

【記錄】 編譯matconvnet on ubuntu16.04 with cuda 9.0

src get erro _for comment gpu ror vlfeat bsp

最近需要用到matconvnet 在Ubuntu16.04下。 因為TensorFlow 1.6 支持了CUDA 9.0 所以新機器就直接裝了9.0 但是編譯matconvnet 時遇到了一些問題 特此記錄一下。

1. Error using mex nvcc fatal : Unsupported gpu architecture ‘compute_20‘

Solution: 這個是因為cuda 8 之後不支持compute_20 了,最低也是compute_30了。 所以需要將vl_compilenn.m中的以下代碼進行修改

opts.defCudaArch = [...
‘-gencode=arch=compute_20,code=\"sm_20,compute_20\" ‘...
‘-gencode=arch=compute_30,code=\"sm_30,compute_30\"‘];

我用的是GTX1080TI, 此處我修改成

opts.defCudaArch = [...
‘-gencode=arch=compute_30,code=\"sm_30,compute_30\" ‘...
‘-gencode=arch=compute_50,code=\"sm_50,compute_50\"‘];

同時還需要將 matconvnet/matlab/src/config/mex_CUDA_glnxa64.xml 裏對應的地方也進行修改

NVCCFLAGS="-D_FORCE_INLINES -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=\"sm_30,compute_30\" $NVCC_FLAGS"

修改後:

NVCCFLAGS="-D_FORCE_INLINES -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=\"sm_30,compute_30\" $NVCC_FLAGS"

2. Error: matlab/src/bits/impl/pooling_gpu.cu(163): error: function "atomicAdd(double , double)" has already been defined

這個的原因是CUDA6.0 後定義了atomicAdd 所以會出現重復定義的錯誤。 一共有兩個文件裏存在這個重復定義的問題,分別在

pooling_gpu.cu, line 163
(commented out atomicadd)

bilinearsampler_gpu.cu, line 25
(commented out atomicadd)

Solution: 這個的解決方式是在這兩個文件裏定義如下的宏

#if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600
#else
<... place here your own pre-pascal atomicAdd definition ...>
#endif

將如上的定義復制到如上文件裏的頭部, 將文件裏定義的atomicadd function 剪切放在<... place here your own pre-pascal atomicAdd definition ...> 中。

Reference: Compiling with cuda8 https://github.com/vlfeat/matconvnet/issues/575

【記錄】 編譯matconvnet on ubuntu16.04 with cuda 9.0