I just upgraded from OpenCL 1.0 to 1.1. When I make my call to the min() function, I get error output:
<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 go开发者_运维百科ing on? I looked at the 1.0 and 1.1 specs and I am still confused as to why this is happening.
The OpenCL 1.0 and 1.1 specifications define min to have the following function signatures:
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.
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.
You will have to cast the expression results to select a specific overload of min.
There are many overloads of min (as the compiler error message is somewhat unhelpfully indicating) e.g.
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)
...
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.
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 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).
精彩评论