1

While working with JOCl (java version opencl), I came across this error.

Exception in thread "main" org.jocl.CLException: CL_BUILD_PROGRAM_FAILURE
Build log for device 0:
<program source>:3:255: error: **call to '__cl_pow' is ambiguous**
__kernel void sampleKernel(__global short *x,             __global short *y,           __global uint *stop,           __global uint *moment){private uint a = 1;private uint b = 2;for(uint i =0; i<= 100;i++){ for(uint j = stop[i]; j < stop[i+1]; j++){    pow(a,b)      }  }}

My kernel code :

  private static String programSource =
            "__kernel void "
            + "sampleKernel(__global short *x,"
            + "             __global short *y,"
            + "           __global uint *stop,"
            + "           __global uint *moment)"
            + "{"
            + "for(uint i =0; i<= 100;i++){"
            + " for(uint j = stop[i]; j < stop[i+1]; j++){"
            + "    moment[i] = moment[i] + (pow(x[j],0)*pow(y[j],0))  "
            + "     }"
            + "  }"
            + "}";

I thought it was because of the datatype of x and y. But when I do a simple pow(1,1), it results in the same error.

How can I fix this?

Olivier_s_j
  • 5,490
  • 24
  • 80
  • 126
  • 1
    I am more concerned about the second (exponent) argument of `pow(x[j],0)`. Any number except `0` to the power of `0` is equal to `1`... – Tomasz Nurkiewicz Dec 01 '12 at 16:03
  • @TomaszNurkiewicz yes, well that is how the 0th order image moment is calculated, not something I invented :). – Olivier_s_j Dec 01 '12 at 16:11
  • Sure. What I mean is that if `pow(x[j],0` means `x[j] to the power of 0` and that `0` is hardcoded, you can safely replace the whole thing with `1`. – Tomasz Nurkiewicz Dec 01 '12 at 16:17
  • 1
    I know, but the function will have to work for other ciphers than 0. This is just the first try :) – Olivier_s_j Dec 01 '12 at 16:18

1 Answers1

3

Just a guess :

there is no overload of pow for integral types so the compiler will try to find the closest match amongst all the available overloads :

  • pow(double, double)
  • pow(float, float)
  • ...

But as a short is convertible to a float as well as a double it doesn't find a single overload to use, hence the error.

To check this hypothese try to explicit the conversion you want to use with a cast :

(pow((float)x[j],0)*pow((float)y[j],0))
Pragmateek
  • 13,174
  • 9
  • 74
  • 108