Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 standard with CUDA 6.0

I want to use the C++11 standard for my C++ files in my CUDA 6.0 project. When I change the compiler in the CUDA 6.0 Nsight Eclipse settings to the g++ and add the -std=c++11 option then I receive lot of errors like this:

error: namespace "std::__gnu_cxx" has no member "__normal_iterator"

Apperantly I have to "select" the compiler once for CUDA and then for my C++ files.

How can I do it? Installing CUDA 6.5 - which supports undocumented C++11 - is not an option.

like image 554
Peter VARGA Avatar asked Sep 19 '14 19:09

Peter VARGA


People also ask

Does CUDA 7 support C++11?

CUDA 7 has a huge number of improvements and new features, including C++11 support, the new cuSOLVER library, and support for Runtime Compilation. In a previous post I told you about the features of CUDA 7, so I won’t repeat myself here. Instead, I wanted to take a deeper look at C++11 support in device code.

Which version of GCC is not supported by CUDA?

CUDA 5.0: no support for GCC 4.7, no support for C++11 features nvcc does not understand C++11 syntax used in the standard includes of GCC 4.6 stackoverflow.com Error while using CUDA and C++11 c++, gcc, cuda, c++11 asked by user988098 on 09:52PM - 29 Jan 12 UTC

What's new in CUDA 7?

CUDA 7 adds C++11 feature support to nvcc, the CUDA C++ compiler. This means that you can use C++11 features not only in your host code compiled with nvcc, but also in device code. New C++ language features include auto, lambda functions, variadic templates, static_assert, rvalue references, range-based for loops, and more.

What is CUDA C++?

CUDA C++ provides a simple path for users familiar with the C++ programming language to easily write programs for execution by the device. Kernels can be written using the CUDA instruction set architecture, called PTX, which is described in the PTX reference manual.


1 Answers

The problem is CUDA 6.0 does not support the C++11 standard and when passing the -std=c++11 option to the compiler then the compilation of the other source code will fail [especially when using third party .c files JSON, ...].

"Implement" a g++ hack in CUDA 6.0 Eclipse: Project -> Properties -> Build -> Settings -> Tool Settings -> Build Stages -> Compiler Path (-ccbin): Here you enter the path to the shell script described below [Example]: /home/user/g++.hack

The script in /home/user/g++.hack:

# g++ Hack
#

# in CUDA 6.0 the source code is always the last parameter
SourceFile="${@: -1}"

# get the file extension
Extension=${SourceFile##*.}

if [ "$Extension" == "cpp" ]
then
   StdFlag="-std=c++11"
else
   StdFlag=""
fi

# run now the g++ 4.9 in your own path with the personalized std option
/usr/local/bin/g++ $StdFlag $*

Don't forget to run chmod a+x /home/user/g++.hack. Your C++11 Source code must have the extension .cpp - for all other extension the compiler option won't be passed.

I hope it can help until Nvidia officially supports C++11. For me it works and once Nvidia will officially support C++11 I can switch to a "normal" solution.

Note: With this you won't be able to use C++11 code in your CUDA source code but at least the host code can be developed in C++11!

like image 78
Peter VARGA Avatar answered Sep 22 '22 23:09

Peter VARGA