OpenCL bicubic interpolation kernel failed with error CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST

2.9k views Asked by At

Bicubic interpolation is one of the common interpolation method, but I can not find any working implementation on OpenCL. I was decided to write bicubic interpolation on OpenCL myself, but ...

I have some problem with kernel programm.

When I run kernel execution, program failed with error CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST. No any other information about cause of error. I am using javacl binding form google code: http://code.google.com/p/javacl, AMD Accelerated Parallel Processing SDK 2.3 on Ubuntu linux 10.10, hardware AMD Radeon 5xxxHD

I haven`t opencl debugger on ubuntu for AMD APP SDK (

If I uncomment float4 val=read_imagef(signal, sampler, (float2)(x+iX,y+iY)); and comment calculation of bicubic interpolation "float4 val=..." all work without any error(but using bilinear interpolation). I think that this error because of invalid memory access or register memory overflow.

const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP_TO_EDGE;
const float CATMULL_ROM[16]={-0.5F,1.5F,-1.5F,0.5F,1.0F,-2.5F,2.0F,-0.5F,-0.5F,0.0F,0.5F,0.0F,0.0F,1.0F,0.0F,0.0F};
__kernel void bicubicUpscale(int scale,read_only image2d_t signal, write_only image2d_t upscale) {

int x = get_global_id(0)-2, y = get_global_id(1)-2;

float C[16];
float T[16];


for (int i = 0; i < 16; i++)
{
    C[i]=0.0F;
    T[i]=0.0F;
}

for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++)
        {
            T[4*i+j] += read_imagef(signal, sampler, (int2)(x+k,y+i)).x * CATMULL_ROM[4*j+k];
        }
for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++)
        {
            C[4*i+j] += CATMULL_ROM[4*i+k] * T[4*k+j];
        }

for (int i = 0; i < scale; i++)
{
    for (int j = 0; j < scale; j++)
    {
        float iX=(float)j/(float) scale;
        float iY=(float)i/(float) scale;
        //float4 val=read_imagef(signal, sampler, (float2)(x+iX,y+iY));
        float val= iX * (iX * (iX * (iY * (iY * (iY * C[0] + C[1]) + C[2]) + C[3])
        + (iY * (iY * (iY * C[4] + C[5]) + C[6]) + C[7]))
        + (iY * (iY * (iY * C[8] + C[9]) + C[10]) + C[11]))
        + (iY * (iY * (iY * C[12] + C[13]) + C[14]) + C[15]);
        write_imagef(upscale, (int2)(x*scale+j, y*scale+i), val);
    }
}
}

I rewrite this program for using local memory, but it still not working correctly

const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP_TO_EDGE;
const float CATMULL_ROM[]={-0.5F,1.5F,-1.5F,0.5F,1.0F,-2.5F,2.0F,-0.5F,-0.5F,0.0F,0.5F,0.0F,0.0F,1.0F,0.0F,0.0F};
__kernel void bicubicUpscale(local float* sharedBuffer,int scale,read_only image2d_t signal, write_only image2d_t upscale) {
int x = get_global_id(0)-2, y = get_global_id(1)-2;
//int locX=get_local_id(0);

int offsetT = (y+2)*512+(x+2)*32+16;
int offsetC = (y+2)*512+(x+2)*32;

global float* C=&sharedBuffer[offsetT];
global float* T=&sharedBuffer[offsetT];

for (int i = 0; i < 32; i++){
    sharedBuffer[offsetC+ i]=0.0F;
}

for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++){
            //T[4*i+j] = mad(read_imagef(signal, sampler, (int2)(x+k,y+i)).x,CATMULL_ROM[4*j+k],T[4*i+j]);
            T[i+j] += read_imagef(signal, sampler, (int2)(x+k,y+i)).x * CATMULL_ROM[4*j+k];
        }
for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++){
            //C[4*i+j] = mad(CATMULL_ROM[4*i+k],T[4*k+j],C[4*i+j]);
            sharedBuffer[offsetC +4*i+j] += CATMULL_ROM[4*i+k] * sharedBuffer[offsetT + 4*k+j];
        }


barrier (CLK_GLOBAL_MEM_FENCE);


for (int i = 0; i < scale; i++)
    for (int j = 0; j < scale; j++)
        {
            float iX=(float)j/(float) scale;
            float iY=(float)i/(float) scale;
            float4 val= iX * (iX * (iX * (iY * (iY * (iY * C[0] + C[1]) + C[2]) + C[3])
            + (iY * (iY * (iY * C[4] + C[5]) + C[6]) + C[7]))
            + (iY * (iY * (iY * C[8] + C[9]) + C[10]) + C[11]))
            + (iY * (iY * (iY * C[12] + C[13]) + C[14]) + C[15]);
            write_imagef(upscale, (int2)(x*scale+j, y*scale+i), val);
        }
}

Do you know any decision for this problem.

Java sources + maven2 build. Use command "mvn clean compile exec:java" to compile and run demo.

Regards, Igor

1

There are 1 answers

0
Igor Suhorukov On

I am fix it! This kernel is not optimal in performance point of view, but functional correct.

Please use such parameters for enqueueNDRange:

            kernelBicubic.getKernel().setArgs(scaleFactor, inImage, imageOut);
            lastEvent=kernelBicubic.getKernel().enqueueNDRange(queue,
                    new int[]{(int) inImage.getWidth()+1,(int) inImage.getHeight()+1},lastEvent);

Kernel code:

const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP_TO_EDGE;

const float CATMULL_ROM[16]={-0.5F, 1.5F,-1.5F, 0.5F, 1.0F,-2.5F, 2.0F,-0.5F,-0.5F, 0.0F, 0.5F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F};

inlie float calcT(image2d_t signal,int x,int y,int i,int j){
      return read_imagef(signal, sampler, (int2)(x  ,y+i)).x * CATMULL_ROM[4*j]
            +read_imagef(signal, sampler, (int2)(x+1,y+i)).x * CATMULL_ROM[4*j+1]
            +read_imagef(signal, sampler, (int2)(x+2,y+i)).x * CATMULL_ROM[4*j+2]
            +read_imagef(signal, sampler, (int2)(x+3,y+i)).x * CATMULL_ROM[4*j+3];
}

inline float C(image2d_t signal,int x,int y,int i,int j){
      return CATMULL_ROM[4*i  ] * calcT(signal,x,y,0,j)
            +CATMULL_ROM[4*i+1] * calcT(signal,x,y,1,j)
            +CATMULL_ROM[4*i+2] * calcT(signal,x,y,2,j)
            +CATMULL_ROM[4*i+3] * calcT(signal,x,y,3,j);
}


__kernel void bicubicUpscale(int scale,read_only image2d_t signal, write_only image2d_t upscale) {

int x = get_global_id(0)-2, y = get_global_id(1)-2;

float C0 =C(signal,x,y,0,0);
float C1 =C(signal,x,y,0,1);
float C2 =C(signal,x,y,0,2);
float C3 =C(signal,x,y,0,3);
float C4 =C(signal,x,y,1,0);
float C5 =C(signal,x,y,1,1);
float C6 =C(signal,x,y,1,2);
float C7 =C(signal,x,y,1,3);
float C8 =C(signal,x,y,2,0);
float C9 =C(signal,x,y,2,1);
float C10=C(signal,x,y,2,2);
float C11=C(signal,x,y,2,3);
float C12=C(signal,x,y,3,0);
float C13=C(signal,x,y,3,1);
float C14=C(signal,x,y,3,2);
float C15=C(signal,x,y,3,3);

float xOff=scale*1.5F + x*scale;
float yOff=scale*1.5F + y*scale;

 for (int i = 0; i < scale; i++)
 {
    for (int j = 0; j < scale; j++)
    {
        float iY=(float)j/(float) scale;
        float iX=(float)i/(float) scale;
        float val= iX * (iX * (iX * (iY * (iY * (iY * C0 + C1) + C2) + C3)
        + (iY * (iY * (iY * C4 + C5) + C6) + C7))
        + (iY * (iY * (iY * C8 + C9) + C10) + C11))
        + (iY * (iY * (iY * C12 + C13) + C14) + C15);
        write_imagef(upscale, (int2)(xOff+j, yOff+i), val);
    }
 }
}