我无法使用 gcc 在 CUDA 5.0 中重现此问题。如果我使用您的设备功能进行完整的复制案例:
#include <vector_functions.h>
#include <device_functions.h>
inline __device__ float2 uintd_to_floatd( uint2 a )
{
return make_float2( uint2float(a.x), uint2float(a.y) );
}
inline __device__ float3 uintd_to_floatd( uint3 a )
{
return make_float3( uint2float(a.x), uint2float(a.y),
uint2float(a.z) );
}
inline __device__ float4 uintd_to_floatd( uint4 a )
{
return make_float4( uint2float(a.x), uint2float(a.y),
uint2float(a.z), uint2float(a.w) );
}
template<typename Tin, typename Tout>
__global__
void kernel(Tin *in, Tout *out) {
out[threadIdx.x] = uintd_to_floatd(in[threadIdx.x]);
}
template __global__ void kernel<uint2,float2>(uint2 *, float2 *);
template __global__ void kernel<uint3,float3>(uint3 *, float3 *);
template __global__ void kernel<uint4,float4>(uint4 *, float4 *);
并编译它:
$ nvcc -c -arch=sm_20 -Xptxas="-v" uint2float.cu
ptxas info : 0 bytes gmem
ptxas info : Compiling entry function '_Z6kernelI5uint36float3EvPT_PT0_' for 'sm_20'
ptxas info : Function properties for _Z6kernelI5uint36float3EvPT_PT0_
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Used 7 registers, 40 bytes cmem[0]
ptxas info : Compiling entry function '_Z6kernelI5uint46float4EvPT_PT0_' for 'sm_20'
ptxas info : Function properties for _Z6kernelI5uint46float4EvPT_PT0_
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Used 8 registers, 40 bytes cmem[0]
ptxas info : Compiling entry function '_Z6kernelI5uint26float2EvPT_PT0_' for 'sm_20'
ptxas info : Function properties for _Z6kernelI5uint26float2EvPT_PT0_
0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
ptxas info : Used 6 registers, 40 bytes cmem[0]
它构建时没有任何编译错误。这要么意味着您未向我们展示的某些代码中存在另一个错误,要么这是 Visual Studio 或 MS C++ 编译器特有的问题。已知使用某些向量类型的推力代码在使用VS 工具链编译时会中断。可能是您看到了相同问题的症状。如果您迫切需要短期修复,您可以尝试定义自己的向量类型版本并重写您的 __device__ 函数以使用这些类型。