CUDA 8 support for c++14, Windows/Linux

Hey guys

Recently I am using CUDA 8 for our project development, I am trying to use C++14 features in our code. However, nvcc seem to behave differently between windows and linux platform. It seems like windows version nvcc support it but linux does not. The beneath is the relevant sample code.


using namespace std;

int main()
unique_ptr<int> p1(new int[7]); // C++11

unique_ptr<int> p2 = make_unique<int>(8); //C++14

return 0;

For windows, (windows 7, Visual Studio 2015, CUDA 8)

D:\Cuda_test>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe” -gencode=arch=compute_20,code=“sm_20,compute_20” --use-local-env --cl-version 2015 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -G --keep-dir Debug -maxrregcount=0 --machine 32 --compile -cudart static -g -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o Debug\ “D:\Cuda_test\”
1>CUDACOMPILE : nvcc warning : The ‘compute_20’, ‘sm_20’, and ‘sm_21’ architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
1> Cuda_test.vcxproj -> D:\Cuda_test\Debug\Cuda_test.exe
1> Cuda_test.vcxproj -> D:\Cuda_test\Debug\Cuda_test.pdb (Full PDB)
1> copy “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\cudart*.dll” “D:\Cuda_test\Debug”
1> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\cudart32_80.dll
1> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\cudart64_80.dll
1> 2 file(s) copied.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

It compiles.

But on linux, (Ubuntu 16.04, CUDA 8)

george@dx064:~/Work/software_projects/cuda_test$ nvcc --std=c++11
nvcc warning : The ‘compute_20’, ‘sm_20’, and ‘sm_21’ architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). error: identifier “make_unique” is undefined error: type name is not allowed error: expected an expression

3 errors detected in the compilation of “/tmp/tmpxft_0000634a_00000000-9_cuda_test_cpp14.cpp1.ii”.

george@dx064:~/Work/software_projects/cuda_test$ nvcc --std=c++14 --version
nvcc fatal : Value ‘c++14’ is not defined for option ‘std’

It seems like I can not turn C++14 on or I did it in a wrong way.

So I am just wondering if the cuda 8 linux version support c++ 14 or not.

If anybody knows anything, please just let me know. Thanks a lot.

Best regards
George Liao

nvcc only compiles the CUDA functions, whereas the local compiler (the case of VS it’s cl.exe) compiles the local functions separately … hence why there’s a difference. So you need to look at the local compiler for that answer …

extract from toolkit documentation

1.2. Supported Host Compilers
A general purpose C++ host compiler is needed by nvcc in the following situations:
During non-CUDA phases (except the run phase), because these phases will be forwarded by nvcc to this compiler.
During CUDA phases, for several preprocessing stages and host code compilation (see also The CUDA Compilation Trajectory).
nvcc assumes that the host compiler is installed with the standard method designed by the compiler provider. If the host compiler installation is non-standard, the user must make sure that the environment is set appropriately and use relevant nvcc compile options.

The following documents provide detailed information about supported host compilers:
NVIDIA CUDA Installation Guide for Linux
NVIDIA CUDA Installation Guide for Mac OS X
NVIDIA CUDA Installation Guide for Microsoft Windows
On all platforms, the default host compiler executable (gcc and g++ on Linux, clang and clang++ on Mac OS X, and cl.exe on Windows) found in the current execution search path will be used, unless specified otherwise with appropriate options (see File and Path Specifications).

Read more at:
Follow us: @GPUComputing on Twitter | NVIDIA on Facebook

Hey niceblue

Thanks for your reply.

On the linux platform (Ubuntu 16.04), the default compiler seems to be g++. But my g++ version is 5.4.1

george@dx064:~/Work/software_projects/pbr_build$ g++ --version
g++ (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904
Copyright © 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

G++ 5.4.1 supports c++14 for sure, it can be turned on via -std=c++14/c++1y

george@dx064:~/Work/software_projects/cuda_test$ g++ -std=c++14 cuda_test_cpp14.cpp

Then if nvcc8.0 uses g++ as host compiler, is it supposed to support c++14? if so, how should I turn it on?

george@dx064:~/Work/software_projects/cuda_test$ nvcc --std=c++14
nvcc fatal : Value ‘c++14’ is not defined for option ‘std’

Thanks a lot.

Best regards
George Liao

you need to use c++1y perhaps

have a look at this …

george@dx064:~/Work/software_projects/cuda_test$ nvcc -std=c++1y
nvcc fatal : Value ‘c++1y’ is not defined for option ‘std’

It still does not seem to work. it is not clear to me yet if NVCC 8.0 already support c++14.

[rant]Sigh. The bane of “agile” standard development[/rant]

txbob should correct me if I am making an incorrect statement here. I am reasonably sure that CUDA 8.0 does not support features specific to C++14, and I have seen no announcement if and when C++14 support will be added.

Since new language features are typically introduced into the tool chain gradually, it has proven useful in the past for CUDA developers to file enhancement requests for the specific language feature they need the most. The collected enhancement requests can then be collated and used for prioritization of implementation work.

Enhancement requests should be filed via the bug reporting form linked from the CUDA registered developer website, simply prefix the synopsis with “RFE:” to mark it as an enhancement request rather than a functional bug.

Just agreeing with njuffa and niceblue

CUDA 8 has not announced any official support for C++14.

I don’t want to get in arguments about linux vs. windows. Those topics have already been covered in this thread. (the default support is different in the host compiler on those two platforms)

There is no supported nvcc based methodology to enable c++14 on linux at this time.

c++14 is not officially supported in device code on any platform, so this question only makes sense when we are talking about host code.

With respect to host code, the usual advice applies here:

Segregate your C++14 host code into .cpp modules, and compile those directly with the host compiler.

Any .cu files should at most depend on c++11, which is supported by nvcc, for both host and device code (subject to a few limitations).

The NVIDIA compiler team is well aware that C++14 is coming and is basically here on both windows and linux toolchains, so I expect you’ll see some definitive response to that in the future. It’s not in CUDA 8 though.

Hey njuffa and txbob

Thanks a lot for your reply.

That clear thing up indeed. The reason we thought it might have is that windows has it and we use as latest C++ feature as possible for our project. We started from windows and ported it to linux to make it cross platform, that is where we got a problem.

Code segregation and some syntax degrade to C++11 can solve our problem for sure, I already have some ideas to refactor our code.

Thanks again for all your help.

Best regards
George Liao