CUDA ERROR - 虚拟功能,继承,新运算符

时间:2015-03-26 16:06:22

标签: c++ cuda

使用OOP CUDA代码我在全局功能中对象创建时有奇怪的行为

CUDA设备:Tesla C2075,计算能力:2.0

没有新操作员一切正常

WITH NEW运算符 - >失败:CUDA_ERROR_NO_BINARY_FOR_GPU

参见代码:

BaseClass的:

class Base
{
public: 
    float PositionX;
    float PositionY;
    float PositionZ;


public:
    __device__ Base()
    {
    }

    __device__  void SetPosition(float x, float y, float z) 
    {
        PositionX = x;
        PositionY = y;
        PositionZ = z;
    }


    __device__ virtual void setCode(float r);
    __device__ virtual void getCode(float q);

};

1Derivate:

class  Box : public  Base
{
public:

    bool myIsVisible;
    float code;

public:


    __device__ Box()
    {
    }

    __device__  void setCode(float r) override
    {
        code = r;
    }


    __device__  void getCode(float a) override
    {
        a = code ;
    }

}

2Derivate:

class  Sphere : public  Base
{

public:

    bool myIsVisible;
    float code;

public:


    __device__ Sphere()
    {
    }

    __device__  void setCode(float r) override
    {
        code = r;
    }
    __device__  void getCode(float a) override
    {
        a = code;
    }

}

AAANDe最终我的KERNEL处于错误状态:

 __global__ void CreateSphere(size_t *objectHandle_in)
{   
    Sphere *aObject = new Sphere();  

}

状态良好:

 __global__ void CreateSphere(size_t *objectHandle_in)
{   
    Sphere *aObject ;  

}

来自CUDA编程指南:

  

当派生类中的函数覆盖a中的虚函数时   基类,执行空间限定符(即主机,   覆盖和覆盖函数上的设备)必须匹配。

     
    

不允许将其作为参数传递给全局函数     具有虚函数的类的对象。

  
     

虚函数表放在全局或常量内存中   编译器。

但我只创建了对象,在这种情况下也失败了:

__device__ creatDevSphere()
    {
    Sphere *aObject  = new Sphere();  
    }

  __global__ void CreateSphere(size_t *objectHandle_in)
    {   
        creatDevSphere();

    }

我知道CC 2.0中有新的运算符......或者不是?

1 个答案:

答案 0 :(得分:0)

由于您使用了C ++ 11功能,我猜您使用的是CUDA 7。 需要在setCode课程中实施getCodeBase方法,或者它们必须是纯虚拟的。

这对我有用:

__device__ virtual void setCode(float r) = 0;
__device__ virtual void getCode(float q) = 0;