Eduardo
Eduardo

Reputation: 39

What could be the reason to not be able to use Math built-in functions in OpenCL? Should I use some directive to active?

The build returns -11 error. Removing pow function compiles fine. I'm not using embedded profile.

__kernel void VectorAdd(__global int* a)
{
    unsigned int n = get_global_id(0);
    a[n] = pow(2, 2); 
}

Im catching the error but the string is empty

int err = clBuildProgram(OpenCLProgram, 0, NULL, NULL, NULL, NULL);
if (err != CL_SUCCESS)  
{ 
    size_t len;  
    char buffer[2048];                  
    printf("Error: Failed to build program executable!\n");
    clGetProgramBuildInfo(OpenCLProgram, cdDevice, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
    printf("%s\n", buffer);
    exit(1);
}  

Some useful info:
CL_DEVICE_NAME: AMD Radeon HD - FirePro D300 Compute Engine
CL_DRIVER_VERSION: 1.2 (Jan 10 2017 22:25:08)

Upvotes: 1

Views: 293

Answers (2)

Jan-Gerd
Jan-Gerd

Reputation: 1289

If you look at the OpenCL documentation for pow you will notice that it is defined as gentype pow(gentype x, gentype y). The document also states that

The generic type name gentype is used to indicate that the function can take float, float2, float3, float4, float8, float16, double, double2, double3, double4, double8, or double16 as the type for the arguments.

So pow() takes two float or two double values or vectors thereof and returns a value of the same type. Since the compiler cannot determine wether you wanted to call pow(2.0, 2.0) (double precision) or pow(2.0f, 2.0f) (single precision), you get an error instead.

Note that there is also the similar-named function float pown(float x, int y) which takes an integer value for the exponent (e.g. pown(2.0f, 2)) and may provide an optimized implementation of this case.

Upvotes: 4

pmdj
pmdj

Reputation: 23428

  1. What does clGetProgramBuildInfo() with param_name=CL_PROGRAM_BUILD_LOG say? This should give you a much more detailed error message. Update the question with this and I might be able to expand this answer.
  2. What version of OpenCL is this? Note that prior to 1.2, the pow() function was only defined for floating-point types; you're expecting it to work with integers.

Upvotes: 0

Related Questions