【问题标题】:CUDA / C++ : error C3861: 'uint2float': identifier not foundCUDA / C++:错误 C3861:'uint2float':找不到标识符
【发布时间】:2013-09-14 22:23:03
【问题描述】:

我在 Visual Studio 2012 中使用 CUDA 5.5 和 Nvidia 提供的文件“FLOAT_UTIL_DEVICE.HCU”中遇到此问题。根据类似的问题,可能是代码结构的问题,但我看不到任何问题:

#include <vector_functions.h>
#include <device_functions.h>

//// ADDED BY ME FOR TEST PURPOSES
//inline __device__ float uint2float( unsigned int a )
//{
//  return (float) a;
//}
//// END

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) );
}

根据 Nvidia 文档,相关方法应在“device_functions.h”中定义。如果我取消注释测试代码(它定义了缺少的函数),我会收到一个新错误:“重载函数“uint2float”的多个实例与参数列表匹配”;因此不知何故它已经被定义了。我错过了什么?

【问题讨论】:

  • 您是否尝试在它们之前添加命名空间?
  • 请发布完整的错误信息。
  • @Peter: "error C3861: 'uint2float': identifier not found" 是完整的错误信息。
  • 真的吗?没有行号?没有说明它在哪个文件中?
  • 第 28 行是什么?您是否尝试从主机代码编译它?你从哪里包括它?您的编译器是否设置为首先通过 NVCC 运行?

标签: c++ cuda


【解决方案1】:

我无法使用 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++ 编译器的问题。使用某些向量类型的推力代码是known to break when compiled with the VS toolchain。可能是您看到了相同问题的症状。如果您迫切需要短期修复,您可以尝试定义自己的向量类型版本并重写您的 __device__ 函数以使用这些类型。

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    相关资源
    最近更新 更多