无法重载 make_uint4 函数

发布于 2024-10-22 16:56:32 字数 759 浏览 2 评论 0原文

我尝试按以下方式重载 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

方觉久 2024-10-29 16:56:33

我能够在 VS 2010 和 CUDA 4.0 上获得部分重现(编译器构建代码正常,但 Intellisense 标记了您所看到的错误)。尝试以下操作:

#include "vector_functions.h"

inline __host__ __device__ uint4 make_uint4(uint2 a, uint2 b)    
{        
    return ::make_uint4(a.x, a.y, b.x, b.y);
}

这为我解决了这个问题。

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:

#include "vector_functions.h"

inline __host__ __device__ uint4 make_uint4(uint2 a, uint2 b)    
{        
    return ::make_uint4(a.x, a.y, b.x, b.y);
}

This fixed it for me.

乖乖 2024-10-29 16:56:33

我在 Visual Studio+nvcc 中编译它没有问题。你使用什么编译器?

如果这有任何帮助:make_uint4 在 vector_functions.h 第 170 行定义为

static __inline__ __host__ __device__ uint4 make_uint4(unsigned int x, unsigned int y, unsigned int z, unsigned int w)
{
  uint4 t; t.x = x; t.y = y; t.z = z; t.w = w; return t;
}

更新:
当我尝试在自定义命名空间内重载该函数时,我会遇到类似的错误。你确定你不在其中吗?如果是这样,请尝试将 :: 放在函数调用前面以引用全局范围,即:

return ::make_uint4(a.x, a.y, b.x, b.y);    

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 as

static __inline__ __host__ __device__ uint4 make_uint4(unsigned int x, unsigned int y, unsigned int z, unsigned int w)
{
  uint4 t; t.x = x; t.y = y; t.z = z; t.w = w; return t;
}

Update:
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:

return ::make_uint4(a.x, a.y, b.x, b.y);    
不顾 2024-10-29 16:56:33

我没有库代码,但编译器似乎不喜欢重载的设备函数(因为它们被视为非常奇特的内联宏)。它的作用是用新的 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 new make_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文