Dynamic parallelism from mex/matlab - compile issues

Hello,

I’m trying to compile a project with dynamic parallelism. I have read several old posts (typically 2013) but have not been able to successfully implement them. In particular I am experiencing compilation failures with MEX.

Background:

  1. The nvcc compile appears to work when running to compile processes in the following way:
    [i]
    system(‘nvcc --compile filename.cu -o filename.o --compiler-options -fPIC -rdc=true -gencode arch=compute_35,code=sm_35 -lcudadevrt’)

system(‘nvcc -arch=sm_35 -dlink filename.o -o filename_link.o --compiler-options -fPIC -lcudadevrt’)[/i]

  1. The ‘best?’ suggestion that I have found to compile mex files that include linking is as shown in the following:

mex filename.o filename_link.o -L"path-to-lib64" -lcudart -lcudadevrt

Question:

How are people actually accomplishing this today?

Note:

Matlab seems to have developed a new mex compile method for dynamic parallelism, per: mexcuda -dynamic as shown here [url]https://www.mathworks.com/help/distcomp/mexcuda.html[/url].

The issue that I seem to bump into when using this noted suggestion is that when compiling with g++5.4 and CUDA 8, the mex doesn’t recognize the compiler. My environment is ubuntu 16.04

I believe the issue is that the current version of CUDA does not support gcc-5.4, only up to 5.3.
See Table 1 here: [url]http://docs.nvidia.com/cuda/cuda-installation-guide-linux/[/url]

A few different (possible) solutions:

  1. Install gcc-4.9 (and g+±4.9) and use it with CUDA in place of gcc-5.4 and g++5.4 via update-altervatives. It is similar to this:
    [url]12.04 - How to use GCC 4.7 in place of 4.6? - Ask Ubuntu

(The packages for gcc-5.3 apparently are not being tagged as such on repositories, and each new version of gcc-5.x replaces the package in the gcc-5 tags, a poor choice IMO… so there’s no way to install gcc-5.3 via the package manager that I know of)

  1. Comment out or change the detection in host_config.h CUDA file to override this restriction (YMMV on this, if using new syntax supported by gcc 5.4, CUDA’s nvcc will not be happy or error out):
    [url]https://github.com/BVLC/caffe/wiki/GeForce-GTX-1080,---CUDA-8.0,---Ubuntu-16.04,---Caffe[/url]

  2. A variation of 1… install gcc-5.3 from source, into a separate directory (very important, so as to not replace the glibc libraries – otherwise your system will break) For that, see this thread (and post #3):
    [url][ubuntu] How to downgrade gcc from 5.4 to 5.3?

Edit: You might want to check if you have the latest CUDA 8.0 version installed, which currently is 8.0.61. It’s possible that one is already fixed to include support for gcc 5.4, despite what the installation guide mentions, unsure.

I believe CUDA 8.0.61 works with gcc 5.4. I have installed CUDA 8.0.61 successfully on Fedora 25 using a manually built version of gcc 5.4. (F25 ships with gcc 6.3, and there are no packages for 5.4 that I could find.) It seems to work fine. You don’t have to edit any header files.

Thanks!