【问题标题】:Compiler error when including <chrono> in a CUDA program - even with --std=c++11在 CUDA 程序中包含 <chrono> 时出现编译器错误 - 即使使用 --std=c++11
【发布时间】:2017-08-31 21:48:46
【问题描述】:

我尝试在 CUDA 程序中测量时间。

为此我想使用:

#include <chrono>

我收到一个错误:

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.

我已尝试包含选项-std=c++11-std=c++14-std=c++17

他们都没有工作。有什么建议吗?

【问题讨论】:

    标签: c++11 compiler-errors cuda nvcc


    【解决方案1】:

    该消息不是来自 CUDA 工具链,而是来自 gcc(以及一个相当旧的 gcc 版本,可能是 4.3)。该消息确切地告诉您要做什么——您需要将-std=c++0x 作为选项传递给gcc。任何主机编译器选项都通过 -Xcompiler 选项从 nvcc 传递

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

    应该解决编译器拒绝导入&lt;chrono&gt;的问题。

    【讨论】:

    • 这给了我一个巨大的错误列表。部分内容是:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception_ptr.h(114): error: copy constructor for class "std::__exception_ptr::exception_ptr" may not have a parameter of type "std::__exception_ptr::exception_ptr" //...// /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/chrono(184): error: space required between adjacent "&gt;" delimiters of nested template argument lists ("&gt;&gt;" is the right shift operator) Error limit reached. Compilation terminated.
    • 所以你的编译器提供了一个损坏的chrono 实现,或者你使用不正确。 GCC 的官方文档说官方 C++11 支持是在 gcc 4.7 中引入的。您正在使用 gcc 4.4。这些都与 CUDA 无关
    • 你是对的。我有gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
    【解决方案2】:

    我想补充@talonmies 的正确答案,并提醒您仔细考虑是否真的要编写自己的代码来进行计时。 CUDA 提供了一个用于计时内核和 CUDA Runtime API 调用的分析器;您还可以使用它的 C(ish) API 在程序的时间轴上标记段和点。

    nVIDIA 的 Mark Harris 写了一封关于使用配置文件的 blog post/tutorial,您可能想查看一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      相关资源
      最近更新 更多