Compile fails using g++ 4.8 with "kernel launches from templates are not allowed in system files"
Build fails using g++ 4.8 with error message "kernel launches from templates are not allowed in system files". Using g++ 4.6 instead works.
Here is the compiler error.
/opt/nvidia/cuda/bin/nvcc -ccbin=/usr/bin/g++ -Xcompiler -fPIC -DNDEBUG -O2 -I/usr/include/python2.7 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include -I./include -I/opt/nvidia/cuda/include -I/opt/intel/mkl/include -gencode arch=compute_20,code=sm_20 -gencode arch=compute_20,code=sm_21 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -c src/caffe/layers/pooling_layer.cu -o build/src/caffe/layers/pooling_layer.cuo src/caffe/layers/pooling_layer.cu(164): error: kernel launches from templates are not allowed in system files
src/caffe/layers/pooling_layer.cu(171): error: kernel launches from templates are not allowed in system files
src/caffe/layers/pooling_layer.cu(291): error: kernel launches from templates are not allowed in system files
src/caffe/layers/pooling_layer.cu(298): error: kernel launches from templates are not allowed in system files
src/caffe/layers/pooling_layer.cu(305): error: kernel launches from templates are not allowed in system files
5 errors detected in the compilation of "/tmp/tmpxft_00006a5e_00000000-10_pooling_layer.cpp4.ii". make: *** [build/src/caffe/layers/pooling_layer.cuo] Error 2
I met the same issue.
sqwang@sqwang-Z820:~/workspace/project/open-source/caffe$ make
/usr/local/cuda/bin/nvcc -ccbin=/usr/bin/g++ -Xcompiler -fPIC -DNDEBUG -O2 -I/home/sqwang/anaconda/include -I/home/sqwang/anaconda/include/python2.7 -I/home/sqwang/anaconda/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include -I/opt/opencv/opencv-2.4.9/include -Ibuild/src -I./src -I./include -I/usr/local/cuda/include -gencode arch=compute_20,code=sm_20 -gencode arch=compute_20,code=sm_21 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -c src/caffe/layers/softmax_layer.cu -o build/src/caffe/layers/softmax_layer.cuo
src/caffe/layers/softmax_layer.cu(59): error: kernel launches from templates are not allowed in system files
src/caffe/layers/softmax_layer.cu(66): error: kernel launches from templates are not allowed in system files
src/caffe/layers/softmax_layer.cu(73): error: kernel launches from templates are not allowed in system files
3 errors detected in the compilation of "/tmp/tmpxft_00006d79_00000000-10_softmax_layer.cpp4.ii".
Possible duplicate of #27
The trick that I used to fix the similar problem in #27 on Ubuntu 12.04(.*) does not work on Ubuntu 14.04 whose gcc/g++ version is 4.8+. The only way is to use an older compiler that CUDA supports.
sudo apt-get install gcc-4.6 g++-4.6 gcc-4.6-multilib g++-4.6-multilib
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
I compiled (successfully passing all tests and running the MNIST example) on Ubuntu 14.04 by simply installing gcc/g++ 4.6 (first apt-get install by kloudkl above) and then changing the Makefile to point to the appropriate compiler:
CXX := /usr/bin/g++-4.6
This way you don't have to globally set your alternatives to a retrograde gcc/g++ version.
CXX := /usr/bin/g++-4.6 does not work with the current Makefile bcs the compiler choice is hardcoded right now in Makefile, see Line 155
ifeq ($(LINUX), 1) CXX := /usr/bin/g++ endif
so you need to change this in the makefile right now (to g++-4.6 as weinman said ) ... anybody wants to open a minor issue, so that CXX is used from Makefile.config again ?
@AlexBinder if you agree and you didn't submit it, I will submit this minor issue. I consider that it is important that people choose gcc compiler due to previous errors. It is my third attempt to compile Caffe and I got this error again XD!!! Fortunately and thanks to caffe community, I can overcome it.
Can be fixed easily by modifying it as, CXX ?= /usr/bin/g++
I agree. I modified two lines of my Makefile as you mention and I include CXX in Makefile.config. As Alex said, it is just a trivial issue but it could help rookie linux users.
@escorciav I think it is a good idea that you fixed that. I just did not wanted to open an issue on that or change compilation settings when I was not sure whether there was some reason which I was unaware of.
Ok, it has sense and I didn't think about that.
#611 fixes the issue with setting a custom compiler raised and discussed by @AlexBinder @escorciav @yrevar
@AndrewLavin @shiquanwang @kloudkl
I compiled and tested Caffe with
- Ubuntu 14.04
- CUDA 6.0.37
- driver 331.75
- g++ 4.8
and did not encounter the "kernel launches from templates are not allowed in system files" error. However, Caffe performance was poor as noted elsewhere (backward pass was 3.4x slower than normal).
Hi Evan,
thanks for the report. Noted ... to solve this problem one should build Cuda from source (rather than using the ubuntu package which is as of today is still only 5.5) so that it works with g++-4.8 .
The default which ubuntu 14.04 offers today is apt search nvidia-cuda-toolkit Sorting... Done Full Text Search... Done nvidia-cuda-toolkit/trusty,now 5.5.22-3ubuntu1 amd64 [installed] NVIDIA CUDA toolkit With that older version it produces with g++4.8 still the kernel launch problem.
That should explain the difference between your result and the result of the others. Best, Alex
I think that g++4.8 is still somewhat experimental.
Thank you shelmaher. I have not tested neither speed nor CUDA 6.0 standard release but it is sure that compiler var could help as much as include and library var. I recommend to check which is the compiler suggested for your CUDA version and to use the latest driver, if it is possible. If you are using Fedora (active development), it is extremely useful.
I also encountered this problem after upgrading to Ubuntu 13.10 . Reverting to g++ 4.7 solved the problem. This should be noted in the installation documentation.
I am also getting this error when I tried compiling caffe after compiling MATLAB wrapper.
To compile matlab wrapper I used the following command instead of 'make matcaffe' g++ -shared -fPIC matcaffe.cpp -o matcaffe
because I was getting the following error with 'make matcaffe'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function _start': (.text+0x20): undefined reference tomain'
I did not get any error when compiled caffe without using matlab wrapper.I succesfully passed all the test cases.
Kindly help ASAP.
@sachinky https://github.com/BVLC/caffe/issues/885#issuecomment-51850376
Would be great to have this information available on the installation page. http://caffe.berkeleyvision.org/installation.html
I avoided this by setting CUSTOM_CXX := g++-4.7 in the Makefile.config.
ubuntu 14.10 cuda 5.5 arch = compute_30 g++ = 4.7 driver 331.89