在OpenCL 1.1中,我对函数min()的调用是模糊的,我不知道为什么。

时间:2021-09-29 21:07:03

I just upgraded from OpenCL 1.0 to 1.1. When I make my call to the min() function, I get error output:

我刚刚从OpenCL 1.0升级到1.1。当我调用min()函数时,会得到错误输出:

    <program source>:45:44: error: call to 'min' is ambiguous
            int nFramesThisKernelIngests = min(nFramesToIngest  - nAvg*nPP*get_global_id(2), nAvg*nPP);

<built-in>:3569:27: note: candidate function
double16 __OVERLOADABLE__ min(double16, double16);                                               
                           ^
<built-in>:3568:26: note: candidate function
double8 __OVERLOADABLE__ min(double8, double8);   

The error output continues for more lines with different types.

错误输出将继续增加不同类型的行。

When I tried to isolate the problem, get_global_id(2) appears to be the problem. I thought that casting get_global_id(2) to an int from a uint (I believe it returns a uint) would solve the problem but it doesn't. Does anybody know what is going on? I looked at the 1.0 and 1.1 specs and I am still confused as to why this is happening.

当我试图隔离这个问题时,get_global_id(2)似乎是问题所在。我认为将get_global_id(2)从一个uint(我相信它返回一个uint)的int类型转换到一个int类型(我相信它返回一个uint)会解决这个问题,但它没有。有人知道发生了什么吗?我查看了1.0和1.1规范,我仍然困惑于为什么会出现这种情况。

2 个解决方案

#1


6  

The OpenCL 1.0 and 1.1 specifications define min to have the following function signatures:

OpenCL 1.0和1.1规范定义了以下功能签名:

gentype min (gentype x, gentype y) 
gentype min (gentype x, sgentype y)

As such, the argument types must be the same, or 1 vector and a scalar matching the vector element type e.g.

因此,参数类型必须是相同的,或1个向量和一个标量匹配向量元素类型。

int4 a,b;
int c; 
min(a,b); // All arguments have the same type
min(a,c); // 2nd element may be scalar, matching the 
          // element type of the 1st argument ( a vector type )

Note also that the return type of get_global_id is size_t, which may be 32 or 64bits in size.

还要注意,get_global_id的返回类型是size_t,它的大小可能是32或64位。

You will have to cast the expression results to select a specific overload of min.

您将不得不将表达式结果转换为选择一个特定的min过载。

There are many overloads of min (as the compiler error message is somewhat unhelpfully indicating) e.g.

有很多的min(因为编译器错误消息有些不太有用)。

min(float  a, float  b);
min(float2 a, float2 b);
min(float2 a, float  b);
min(float3 a, float3 b);
min(float3 a, float  b);
min(float4 a, float4 b);
... // and vector sizes 4,8,16
min(double a, double b); // With an OpenCL 64bit floating point extension enabled
min(double2 a, double b); // With an OpenCL 64bit floating point extension enabled
... // and integral scalar and vector types (char, schar, short, ushort, int, etc)

...

#2


1  

I don't really know OpenCL, but it looks like the compiler doesn't know if it should promote min's arguments to double8 or double16. Since those types are vectors and not scalars, I guess min is not the function you're looking for. Try fmin instead.

我不知道OpenCL,但是看起来编译器不知道它是否应该将min的参数推广到double8或double16。因为这些类型是向量而不是标量,我想min不是你要找的函数。尝试fmin代替。

EDIT: Do you see the following in the error messages?

编辑:您在错误消息中看到以下内容吗?

<built-in>:xxxx:yy: note: candidate function
int __OVERLOADABLE__ min(int, int);

JAB IN THE DARK: Cast everything to int:

在黑暗中猛击:把一切都投给int:

int nFramesThisKernelIngests = (int) min(
    (int) (nFramesToIngest - nAvg * nPP * get_global_id(2)),
    (int) (nAvg * nPP));

If that compiles, remove the casts in descending order of silliness (e.g. the first cast is probably meaningless, but YMMV).

如果编译成功,则按下递减顺序删除(例如,第一个cast可能没有意义,但是YMMV)。

#1


6  

The OpenCL 1.0 and 1.1 specifications define min to have the following function signatures:

OpenCL 1.0和1.1规范定义了以下功能签名:

gentype min (gentype x, gentype y) 
gentype min (gentype x, sgentype y)

As such, the argument types must be the same, or 1 vector and a scalar matching the vector element type e.g.

因此,参数类型必须是相同的,或1个向量和一个标量匹配向量元素类型。

int4 a,b;
int c; 
min(a,b); // All arguments have the same type
min(a,c); // 2nd element may be scalar, matching the 
          // element type of the 1st argument ( a vector type )

Note also that the return type of get_global_id is size_t, which may be 32 or 64bits in size.

还要注意,get_global_id的返回类型是size_t,它的大小可能是32或64位。

You will have to cast the expression results to select a specific overload of min.

您将不得不将表达式结果转换为选择一个特定的min过载。

There are many overloads of min (as the compiler error message is somewhat unhelpfully indicating) e.g.

有很多的min(因为编译器错误消息有些不太有用)。

min(float  a, float  b);
min(float2 a, float2 b);
min(float2 a, float  b);
min(float3 a, float3 b);
min(float3 a, float  b);
min(float4 a, float4 b);
... // and vector sizes 4,8,16
min(double a, double b); // With an OpenCL 64bit floating point extension enabled
min(double2 a, double b); // With an OpenCL 64bit floating point extension enabled
... // and integral scalar and vector types (char, schar, short, ushort, int, etc)

...

#2


1  

I don't really know OpenCL, but it looks like the compiler doesn't know if it should promote min's arguments to double8 or double16. Since those types are vectors and not scalars, I guess min is not the function you're looking for. Try fmin instead.

我不知道OpenCL,但是看起来编译器不知道它是否应该将min的参数推广到double8或double16。因为这些类型是向量而不是标量,我想min不是你要找的函数。尝试fmin代替。

EDIT: Do you see the following in the error messages?

编辑:您在错误消息中看到以下内容吗?

<built-in>:xxxx:yy: note: candidate function
int __OVERLOADABLE__ min(int, int);

JAB IN THE DARK: Cast everything to int:

在黑暗中猛击:把一切都投给int:

int nFramesThisKernelIngests = (int) min(
    (int) (nFramesToIngest - nAvg * nPP * get_global_id(2)),
    (int) (nAvg * nPP));

If that compiles, remove the casts in descending order of silliness (e.g. the first cast is probably meaningless, but YMMV).

如果编译成功,则按下递减顺序删除(例如,第一个cast可能没有意义,但是YMMV)。