1

在使用 JOCl(java 版本 opencl)时,我遇到了这个错误。

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)      }  }}

我的内核代码:

  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))  "
            + "     }"
            + "  }"
            + "}";

我认为这是因为 x 和 y 的数据类型。但是当我做一个简单的 pow(1,1) 时,它会导致同样的错误。

我怎样才能解决这个问题?

4

1 回答 1

3

只是一个猜测:

整数类型没有pow重载,因此编译器将尝试在所有可用重载中找到最接近的匹配:

  • 战俘(双,双)
  • 战俘(浮动,浮动)
  • ...

但是由于short可以转换为floatdouble它没有找到要使用的单个重载,因此会出现错误。

要检查这个假设,请尝试明确您要使用 cast 的转换:

(pow((float)x[j],0)*pow((float)y[j],0))
于 2012-12-01T16:08:52.557 回答