[英]PyCuda C++ kernel "error: this declaration may not have extern "C" linkage"
I tried using std::tuple
in my kernel code, but received many error: this declaration may not have extern "C" linkage
errors that pointed to utility
and tuple
我尝试在我的 kernel 代码中使用
std::tuple
,但收到很多error: this declaration may not have extern "C" linkage
指向utility
和tuple
的外部“C”链接错误
It complains on the include.它抱怨包含。 The following repros for me.
以下是我的重述。
from pycuda.compiler import SourceModule
mod = SourceModule("""#include <tuple>""")
Do I need to do something special in my kernel code or in my Python code to specify I want to use the C++ compiler?我是否需要在我的 kernel 代码或 Python 代码中做一些特殊的事情来指定我想使用 C++ 编译器?
Cuda version: 11.8 Cuda 版本:11.8
PyCuda version: 2022.2.1 PyCuda 版本:2022.2.1
Do I need to do something special in my kernel code or in my Python code to specify I want to use the C++ compiler?
我是否需要在我的 kernel 代码或 Python 代码中做一些特殊的事情来指定我想使用 C++ 编译器?
To be clear, you are using the C++ compiler.明确地说,您使用的是 C++ 编译器。 But PyCUDA automagically wraps the code you pass into a
SourceModule
instance in extern “C”
unless you explicitly tell it not to:但是 PyCUDA 会自动将您传递的代码包装到
extern “C”
中的SourceModule
实例中,除非您明确告诉它不要这样做:
Unless no_extern_c is True, the given source code is wrapped in
extern “C” { … }
to prevent C++ name mangling.除非 no_extern_c 为 True,否则给定的源代码被包装在
extern “C” { … }
中以防止 C++ 名称混淆。
The underlying reason from a C++ perspective is that templated instances of types and functions can't resolve with C linkage, thus the error.从 C++ 的角度来看,根本原因是类型和函数的模板化实例无法通过 C 链接解析,因此出现错误。
However, even after you fix that problem, prepared to be disappointed.但是,即使在您解决了该问题之后,也要做好失望的准备。 CUDA supports a lot of C++ language features, but it doesn't support the standard library and you can't use
std::tuple
within kernel code. CUDA 支持很多 C++ 语言特性,但它不支持标准库,你不能在 kernel 代码中使用
std::tuple
。 NVIDIA does provide their own (very limited) reimplementation of the C++ standard library, and it does have a basic tuple type. NVIDIA 确实提供了他们自己的(非常有限的) C++标准库的重新实现,并且它确实有一个基本的元组类型。 That might work for you.
这可能对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.