无法重载 make_uint4 函数
我尝试按以下方式重载 make_uint4
:
namespace A {
namespace B {
inline __host__ __device__ uint4 make_uint4(uint2 a, uint2 b) {
return make_uint4(a.x, a.y, b.x, b.y);
}
}
}
但是当我尝试编译它时,nvcc 返回一个错误:
error: no suitable constructor exists to convert from "unsigned int" to "uint2"
error: no suitable constructor exists to convert from "unsigned int" to "uint2"
error: too many arguments in function call
所有这些错误都指向 "return…"
行。
I'm trying to overload make_uint4
in the following manner:
namespace A {
namespace B {
inline __host__ __device__ uint4 make_uint4(uint2 a, uint2 b) {
return make_uint4(a.x, a.y, b.x, b.y);
}
}
}
But when I try to compile it, nvcc returns an error:
error: no suitable constructor exists to convert from "unsigned int" to "uint2"
error: no suitable constructor exists to convert from "unsigned int" to "uint2"
error: too many arguments in function call
All these errors point to the "return…"
line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够在 VS 2010 和 CUDA 4.0 上获得部分重现(编译器构建代码正常,但 Intellisense 标记了您所看到的错误)。尝试以下操作:
这为我解决了这个问题。
I was able to get a partial repro on VS 2010 and CUDA 4.0 (the compiler built the code OK but Intellisense flagged the error you are seeing). Try the following:
This fixed it for me.
我在 Visual Studio+nvcc 中编译它没有问题。你使用什么编译器?
如果这有任何帮助:
make_uint4
在 vector_functions.h 第 170 行定义为更新:
当我尝试在自定义命名空间内重载该函数时,我会遇到类似的错误。你确定你不在其中吗?如果是这样,请尝试将
::
放在函数调用前面以引用全局范围,即:I have no problem compiling it in Visual Studio+nvcc. What compiler are you using?
If that would be of any help:
make_uint4
is defined in vector_functions.h, line 170 asUpdate:
I get similar error when I try to overload the function while being inside my custom namespace. Are you certain you are not inside one? If so, try putting
::
in front of function call to refer to global scope, i.e:我没有库代码,但编译器似乎不喜欢重载的设备函数(因为它们被视为非常奇特的内联宏)。它的作用是用新的
make_uint4(va, vb)
隐藏(隐藏)旧的make_uint4(a,b,c,d)
并尝试调用后者4 个 uint 参数。这不起作用,因为没有从 uint 到 uint2 的转换(如前两个错误消息所示),并且有 4 个参数而不是 2 个参数(最后一个错误消息)。使用稍微不同的函数名称,例如
make_uint4_from_uint2s
就可以了。I don't have the library code, but it seems like the compiler doesn't like overloaded device functions (as they are treated just like really fancy inline macros). What is does is shadow (hide) the old
make_uint4(a,b,c,d)
with your newmake_uint4(va, vb)
and try to call the latter with 4 uint parameters. That doesn't work because there is no conversion from uint to uint2 (as indicated by the first two error messages) and there are 4 instead of 2 arguments (the last error message).Use a slightly different function name like
make_uint4_from_uint2s
and you'll be fine.