Member function of a C++ object as a CUDA __global__ function(作为 CUDA __global__ 函数的 C++ 对象的成员函数)
问题描述
我有一个基类:
template <class T>
class A{
public:
// some data
T data;
//some functions like constructs etc.
...
// one virtual function
virtual void evaluate() = 0;
}
还有一个派生类:
template <class T>
class B:public A<T>{
public:
// some functions like constructors etc.
virtual void evaluate();
__global__ void function2(); // **** error message
}
还有,我有
template <class T> void
B<T>::evaluate()
{
dim3 grid(1);dim3 block(1);
void function2<<<grid,block>>>();
}
和
template <class T> __global__ void B<T>::function2() // **** error message
{
// computation here
}
所以本质上我有一个派生类的成员函数,我想在设备上以并行方式执行它.
so essentially I have a member function of a derived class which I would like to execute in a parallel fashion on the device.
不幸的是,我得到了错误:
Unfortunately, I get the error:
error : illegal combination of memory qualifiers on the lines :
1> __global__ void function2(); // **** error message
2> template <class T> __global__ void B<T>::function2() // **** error message
我是 CUDA 的新手.如果有人指出我的错误,那就太好了.我正在 Visual Studio 2010 上开发.
I am new to CUDA. It would be very kind if someone points me to my error. I am developing on Visual Studio 2010.
推荐答案
第一个代码片段中的模板类定义是非法的,因为它包含一个 __global__ 函数(CUDA 内核).根据 语言文档,__global__ 函数不能是静态类成员函数.出于同样的原因,第二个模板类成员函数是非法的.
The template class definition in your first code snippet is illegal because it contains a __global__ function (CUDA kernel). As per the language documentation, __global__ functions cannot be static class member functions. The second templated class member function is illegal for the same reason.
这篇关于作为 CUDA __global__ 函数的 C++ 对象的成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:作为 CUDA __global__ 函数的 C++ 对象的成员函数


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01