The program is an Android application and needs to progress an mp4 image. The initialization can be found in this question: init code
But I found out that the init code works with kernels who do not use for
loops.
When I have a nested for loop as in the example on the bottom of the post, only the first image will be processed and all the others will be black.
Simple example:
1)
init function
execute kernel with for loops
remove opencl function
=> all goes fine
2)
init function
execute kernel **without** for loops
execute kernel **without** for loops on next frame
remove opencl function
=> all goes fine
3)
init function
execute kernel **with** for loops
execute kernel **with** for loops on next frame
remove opencl function
=> first frame is processed, 2th frame is black
edge kernel:
__kernel void edgeKernel(__read_only image2d_t srcImage,
__write_only image2d_t dstImage)
{
const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE |
CLK_ADDRESS_REPEAT |
CLK_FILTER_NEAREST;
int x = get_global_id(0);
int y = get_global_id(1);
int2 coords = (int2) (x,y);
int i = 0;
int j = 0;
float4 bufferPixel,currentPixel;
float sum = 0;
int counter = 0;
const float edgeKernel[9] = {0.0f,1.0f,0.0f,1.0f,-4.0f,1.0f,0.0f,1.0f,0.0f};
currentPixel = read_imagef(srcImage,sampler,coords);
for(i=-1;i<=1;i++)
{
for(j=-1;j<=1;j++)
{
coords = (int2)((x+i),(y+j));
bufferPixel = read_imagef(srcImage,sampler,coords);
//sum = sum + (bufferPixel.y * edgeKernel[counter]);
sum = mad(bufferPixel.y,edgeKernel[counter],sum);
counter++;
}
}
if(sum>255) sum=255;
if(sum<0) sum=0;
currentPixel.x=sum;
currentPixel.y=sum;
currentPixel.z=sum;
write_imagef(dstImage,coords,currentPixel);
}
I can not see what's wrong, I guess it's something with overlapping memory allocation but I'm clueless on what the solution might be.
Edit1:
OpenCL code is the link to the OpenCL code. Look for the initOpenCL
and nativeImage2DOpenCL
function. You should be able to find everything you need there.