CUDA 中用于模板化代码的 static const int
static const int in CUDA for a templated code
我有以下代码片段:
class Mesh{
public:
static const int DIM = 3;
// several more static constants here
}
template <class M>
Coords{
public:
int c[M::DIM];
// some more members using static constants of M here
}
我会实例化一些坐标:
Coords<Mesh> coords;
现在这基本上对我有用。
根据文档,CUDA 6.5 根本不支持 static
成员(编程指南,E.2.6.1。数据成员,没有 link 可用)。 CUDA 7.0 添加了对 static const
成员 (http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#const-variables) 的支持。
只要我使用 CUDA 6.5,如何替换 和 static const int
? #define
可能不是一个好的选择,因为模板化将不再按预期工作。
试试枚举?
class Mesh{
public:
enum { DIM = 3 };
// several more constants declared as enums here
}
template <class M>
Coords{
public:
int c[M::DIM];
// some more members using enums of M here
}
我有以下代码片段:
class Mesh{
public:
static const int DIM = 3;
// several more static constants here
}
template <class M>
Coords{
public:
int c[M::DIM];
// some more members using static constants of M here
}
我会实例化一些坐标:
Coords<Mesh> coords;
现在这基本上对我有用。
根据文档,CUDA 6.5 根本不支持 static
成员(编程指南,E.2.6.1。数据成员,没有 link 可用)。 CUDA 7.0 添加了对 static const
成员 (http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#const-variables) 的支持。
只要我使用 CUDA 6.5,如何替换 和 static const int
? #define
可能不是一个好的选择,因为模板化将不再按预期工作。
试试枚举?
class Mesh{
public:
enum { DIM = 3 };
// several more constants declared as enums here
}
template <class M>
Coords{
public:
int c[M::DIM];
// some more members using enums of M here
}