milakov / nnForge

Convolutional neural networks C++ framework with CPU and GPU (CUDA) backends
http://nnforge.org
178 stars 44 forks source link

Issue with -std=c++11 #21

Closed anshumang closed 9 years ago

anshumang commented 9 years ago

I tried setting CPP11COMPILER to yes after forking nnForge and it seems that line 75 in Main.mk is broken. The rule is - NVCCFLAGS+=-DNNFORGE_CPP11COMPILER -std=c++11 and I get the error - nvcc -c absolute_layer_tester_cuda.cu -use_fast_math -DBOOST_NOINLINE='attribute ((noinline))' -g -lineinfo -DENABLE_CUDA_PROFILING -Xcompiler="-I/usr/lib/x86_64-linux-gnu/include -I/usr/local/cuda-6.0/include -I/home/agoswami/cudnn-6.5-linux-x64-v2-rc2 -I/usr/lib/x86_64-linux-gnu/include -ffast-math -march=native -mfpmath=sse -msse2 -g -DENABLE_CUDA_PROFILING" -DNNFORGE_CPP11COMPILER -std=c++11 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=\"sm_35,compute_35\" -o absolute_layer_tester_cuda.o nvcc fatal : Unknown option 'std' make: *\ [absolute_layer_tester_cuda.o] Error 255

So I tried changing the rule to - NVCCFLAGS+=-DNNFORGE_CPP11COMPILER -Xcompiler="-std=c++11" but that gives a bunch of errors in all *.cu file that uses c++11 (my nvcc and gcc are => Cuda compilation tools, release 6.0, V6.0.1, gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2; also tried Cuda compilation tools, release 7.0, V7.0.17 and Cuda compilation tools, release 6.5, V6.5.12). Errors are - nvcc -c hyperbolic_tangent_layer_updater_cuda.cu -use_fast_math -DBOOST_NOINLINE='attribute ((noinline))' -g -lineinfo -DENABLE_CUDA_PROFILING -Xcompiler="-I/usr/lib/x86_64-linux-gnu/include -I/usr/local/cuda-6.0/include -I/home/agoswami/cudnn-6.5-linux-x64-v2-rc2 -I/usr/lib/x86_64-linux-gnu/include -ffast-math -march=native -mfpmath=sse -msse2 -g -DENABLE_CUDA_PROFILING" -DNNFORGE_CPP11COMPILER -Xcompiler="-std=c++11" -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=\"sm_35,compute_35\" -o hyperbolic_tangent_layer_updater_cuda.o /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: identifier "nullptr" is undefined .......

Then I tried disabling CPP11COMPILER by setting it to "no" which gives the following errors (my BOOST version is 1.54.0) - nvcc -c hyperbolic_tangent_layer_updater_cuda.cu -use_fast_math -DBOOST_NOINLINE='attribute ((noinline))' -g -lineinfo -DENABLE_CUDA_PROFILING -Xcompiler="-I/usr/lib/x86_64-linux-gnu/include/boost/tr1/tr1 -I/usr/lib/x86_64-linux-gnu/include -I/usr/local/cuda/include -I/home/agoswami/cudnn-6.5-linux-x64-v2-rc2 -I/usr/lib/x86_64-linux-gnu/include -ffast-math -march=native -mfpmath=sse -msse2 -g -DENABLE_CUDA_PROFILING" -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=\"sm_35,compute_35\" -o hyperbolic_tangent_layer_updater_cuda.o In file included from /usr/include/c++/4.8/random:35:0, from ../nn_types.h:20, from ../layer_data.h:19, from ../layer.h:21, from layer_tester_cuda.h:19, from absolute_layer_tester_cuda.h:19, from absolute_layer_tester_cuda.cu:17: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

error This file requires compiler and library support for the \

^

Finally I tried with CPP11COMPILER set to "yes" but the NVCCFLAGS modified to drop the -std=c++11, but that gives the same error as above.

Am I missing something?

anshumang commented 9 years ago

Other changes to my Settings.mk are - BUILD_MODE=debug ENABLE_CUDA_PROFILING=yes NETCDF_INSTALLED=no MATIO_INSTALLED=no and updating the paths... I also tried -std=c++0x

milakov commented 9 years ago

You should use CUDA Toolkit 6.5 or later to get C++11 (limited) support. You tried that but it seems you changed something in makefiles as I don't see explicit -std=c++11 in the command line, only -Xcompiler="-std=c++11", which is wrong.

I don't know what is wrong when you set CPP11COMPILER=no, this should be the safest option. Will able able to check in ~10 days only, sorry!

anshumang commented 9 years ago

Thanks @milakov , sorry was traveling for last 2 days, so the delay in responding...got it ! I was missing the point that -std=c++11 should also be passed to nvcc for device code compilation requiring c++11 support...actually although I was updating CUDA_PATH in Settings.mk, yet the NVCC=nvcc was still using the /usr/local/cuda/bin/nvcc which was pointing to CUDA6..I assumed CUDA_PATH would be prepended..my bad !....it seems that -std=c++11 is not recognized by nvcc from CUDA6...I installed CUDA7 today and the build completes successfully...didn't check with 6.5, but should work, I guess....

but the safe option of CPP11COMPILER=no breaking, is still weird.....is g++ 4.8 and boost 1.54.0 the right versions?

milakov commented 9 years ago

Glad to see you got CPP11 path working!

but the safe option of CPP11COMPILER=no breaking, is still weird.....is g++ 4.8 and boost 1.54.0 the right versions?

Yes, they should be fine.

milakov commented 9 years ago

Now back to the issue with CPP11COMPILER=no:

Please check you actually have boost tr1 headers in /usr/lib/x86_64-linux-gnu/include/boost/tr1/tr1

anshumang commented 9 years ago

Yes ! That was the problem.. @milakov "/include/boost/tr1/tr1" was getting appended to whatever I specified for BOOST_PATH. Thanks a lot for following up.