Make nvcc output traces on compile error

一个人想着一个人 提交于 2020-01-14 03:15:14

问题


I have some trouble compiling some code with nvcc. It heavily relies on templates and the like so error messages are hard to read. For example currently I'm getting a message

/usr/include/boost/utility/detail/result_of_iterate.hpp:135:338: error: invalid use of qualified-name ‘std::allocator_traits<_Alloc>::propagate_on_container_swap’

which is not really helpful. No information on where it came from or what the template arguments were. Compiling with e.g. gcc shows some really nice output with candidates and template arguments etc.

Is it anyhow possible to get those with nvcc too? Or at least for the host code? It is impossible to compile with gcc only as cuda functions are used which can't be eliminated.

This question is NOT about that particular error, but on how to get more details from nvcc on ANY error. This one should only serve as an example

Condensed working example (compile with nvcc -std=c++11):

#include <memory>
#include <boost/utility/result_of.hpp>

struct foo{
    int operator()(int x){ return x + 42; }
};
typename boost::result_of < foo(int) >::type
bar(int x){ return foo()(x); }

int main(int argc, char**argv){
  return bar(argc);
}

Or even less code:

template<typename T>
struct TriggerError{

private:
    template<typename _Tp>
    static float helper(_Tp*);
    static int   helper(...);
    typedef decltype(helper((T*)0)) privateWrong;

public:
  typedef privateWrong SomethingWentWrong;
};

#include <boost/utility/result_of.hpp>

struct foo{
    int operator()(int x){ return x + 42; }
};

typename boost::result_of < foo(int) >::type
bar(int x){ return foo()(x); }

int main(int argc, char**argv){
  return bar(argc);
}

It seems, that cudafe++ replaces the "type" token with "TriggerError::SomethingWentWrong" for some reason. So this seems to be a CUDA bug.

nvcc --version: Cuda compilation tools, release 7.0, V7.0.27

gcc --version: gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4


回答1:


On the main question: There is no flag or anything that makes nvcc output more template information than there already is. The error shown is a syntax error rather than a template instantiation error but it is caused by a bug in CUDA 7.0.

Information on the bug for reference:
The bug occurs only in CUDA 7.0. It was not there in CUDA 6.5 and is fixed in CUDA 7.5RC and up. It only affects C++11 compilation mode (trying to compile the above code in C++98 is supposed to fail) The bug also occurs only with boost 1.5x (possibly 1.50 latest 1.52) where the decltype usage for boost::result_of was introduced. A more minimal example: Compilation error with nvcc and c++11, need minimal failing example

There are 3 possible work-arounds:

  1. Use std::result_of (c++11)
  2. Include <boost/utility/result_of.hpp> as the very first include
  3. Use the boost TR1 protocol and define BOOST_RESULT_OF_USE_TR1


来源:https://stackoverflow.com/questions/31940457/make-nvcc-output-traces-on-compile-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!