我正在寻找模板的CUDA内核。 ,而不是SO都特别提出。在这个内核中,我想要一个依赖于typename的typedef。我尝试了以下(假设/希望),它会类似于C++,但它没有。是否可以在CUDA内核中使用std :: conditional?
#include <type_traits> // for std::conditional. Not sure if it's necessary
#include <cuda_runtime.h>
#include <cuComplex.h>
template <typename fType>
__global__ void DummyKernel() {
typedef std::conditional<sizeof(fType) == sizeof(double), cuDoubleComplex, cuFloatComplex>::type cfType;
}
这会产生错误
nontype "std::conditional<_Test, _Ty1, _Ty2>::type [with _Test=<expression>, _Ty1=cuDoubleComplex, _Ty2=cuFloatComplex]" is not a type name
有没有办法做我想要什么?我正在使用CUDA 5.5和VS2012。
您在'typedef'之后缺少'typename'关键字。 – catscradle
@catscradle当我意识到Nvidia编译器是分开的时,我正要说我正在使用VS,并且它不符合标准。我必须打破我愚蠢的懒惰习惯。如果发布,我会接受这个答案。 –