简体   繁体   中英

Compiler error when including <chrono> in a CUDA program - even with --std=c++11

I try to measure time in a CUDA program.

For that purpose I want to use:

#include <chrono>

I receive an error though:

error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

I have tried to inlcude the options -std=c++11 , -std=c++14 , -std=c++17 .

None of them worked. Any suggestions?

That message isn't coming from the CUDA toolchain, it is coming from gcc (and a rather old version of gcc, probably 4.3). And the message tells you exactly what to do -- you need to pass -std=c++0x as an option to gcc. Any host compiler options are passed from nvcc via the -Xcompiler option so

$ nvcc -Xcompiler="--std=c++0x" .....

should solve the problem of the compiler refusing to import <chrono> .

I'd like to add to @talonmies's correct answer, and caution you to consider carefully whether or not you actually want to write your own code to do the timing. CUDA offers a profiler for timing kernels and CUDA Runtime API calls; and you can also use its C(ish) API to mark segments and points on the program's timeline.

nVIDIA's Mark Harris wrote a blog post/tutorial about using the profile, you might want to check it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM