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++ 对象的成员函数
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
