genn icon indicating copy to clipboard operation
genn copied to clipboard

NVCC needs to be invoked with -fPIC on Debian Stretch system

Open neworderofjamie opened this issue 6 years ago • 5 comments

More research required as to why but, adding -Xcompiler -fPIC to the generated Makefile solves the problem. The system in question is:

  • x86_64
  • Debian Stretch (current stable)
  • NVIDIA driver installed 384.130-1 (from https://packages.debian.org/stretch/nvidia-kernel-dkms)
  • CUDA 8.0.44-3
  • GCC 6.3.0

Problem seems related to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=861878 - should we simply ALWAYS pass -fPIC to NVCC? Need to test on other Linuxes and Mac and investigate

neworderofjamie avatar Nov 28 '18 17:11 neworderofjamie

-fPIE also works - not clear which we should use

neworderofjamie avatar Nov 28 '18 17:11 neworderofjamie

@tnowotny - I did a bit more investigation into Mikael's issue and it appears that GCC can be configured to have -fPIE set by default (it enables position-indendendent executables which helps security by allowing your programs to be randomly placed in memory). The problem is that, on Mikael's Debian system, this doesn't get passed on to NVCC so it ends up building incompatible code. This is a bug somewhere in Debian as my Ubuntu 18 laptop also has GCC configured this way and it works fine. As far as I can tell there's 3 potential fixes:

  1. Build everything with -fPIE - simple but requires changing a whole load of make files.
  2. Add -fPIE to the NVCCFLAGS in the GeNN-generated-makefile if --enable-default-pieis listed in the output of g++ -v.
  3. Add -fPIE to the NVCCFLAGS in the GeNN-generated-makefile based on #if defined __PIC__ || defined __pic__ || defined PIC || defined pic in generateRunner.cc

I feel 2 is probably a bad idea because it's unclear if the output is the same on all GCCs, let alone clang and my attempts at bash-magic tend to fail on Mac but I'm undecided between the other two.

neworderofjamie avatar Nov 30 '18 15:11 neworderofjamie

@mdjurfeldt - after figuring out a range of hacks we could add to GeNN to fix your issue, I realised your combination of GCC 6 and CUDA 8 isn't actually officially supported by NVIDIA. I then dug somewhat deeper and it seems CUDA 8 on Stretch is problematic in general due to this (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=835940). I honestly think the best solution is for you to install CUDA 9.1 from backports (https://packages.debian.org/stretch-backports/nvidia-cuda-toolkit) and we'll add something to the readme about Debian.

neworderofjamie avatar Dec 03 '18 11:12 neworderofjamie

OK, thanks! I'll try that.

mdjurfeldt avatar Dec 03 '18 11:12 mdjurfeldt

Great! I'm keen not add too many workarounds for OS issues...

neworderofjamie avatar Dec 03 '18 12:12 neworderofjamie