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++ 对象的成员函数
 
				
         
 
            
        - STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
 
						 
						 
						 
						 
						 
				 
				 
				 
				