OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU.
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1718 Discussions

problem with read_imagef

amina_z_
Beginner
709 Views

hello,

I am new with OpenCL

Iam using it with jOCL in java platform

My problem is that I want to read an image pixels using read_imagef, and all the results of it returns 0.0 (.x .y .z .w) knowing that the image is contains red area.

here is my kernel

const sampler_t smp =     CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; 
            
                           
__kernel void basic(__read_only image2d_t input,__global int  *result) 
{
    
   int gidX = get_global_id(0);
    int gidY = get_global_id(1);
	
int2 coord = (int2)(get_global_id(0), get_global_id(1));

int2 posIn = {gidX, gidY};
       
      float4 pixel = read_imagef(input, smp, posIn);
    

result [gidX]= as_int(pixel.x);
	}

what do you think the problem is???

0 Kudos
6 Replies
Joose_S_
Beginner
709 Views
read_imagef() returns floats that are normalized between 0 and 1. So depening on what as_int() does you are probably just casint a float between 0 and 1 to in which will result in a zero.
0 Kudos
amina_z_
Beginner
709 Views

No, I used also float variable and it always returns  0.0

0 Kudos
Joose_S_
Beginner
709 Views
Can you show the buffer allocation on host code including the image format object? You should also try printing the values inside the kernel to see if they get to that point to begin with.
0 Kudos
amina_z_
Beginner
709 Views

Here is my buffer allocation

DataBufferInt dataBufferSrc =
                    (DataBufferInt)image.getRaster().getDataBuffer();
                int dataSrc[] = dataBufferSrc.getData();
                cl_image_format imageFormat = new cl_image_format();
                imageFormat.image_channel_order = CL_RGBA;
                imageFormat.image_channel_data_type =CL_UNORM_INT8;
                		//CL_UNSIGNED_INT8;
                inputImageMem = clCreateImage2D(
                    context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
                    new cl_image_format[]{imageFormat}, sizeX, sizeY,
                    sizeX * Sizeof.cl_uint, Pointer.to(dataSrc), null);
            cl_mem memObjects[] = new cl_mem[2];
            memObjects[0] = clCreateBuffer(context, 
                    CL_MEM_READ_WRITE,   Sizeof.cl_uint * sizeX, null, null);

 

I changed CL_UNORM_INT8 to CL_UNSIGNED_INT8 but there was no difference, I will try to print the result in the kernel 

0 Kudos
amina_z_
Beginner
709 Views

Hello,

I tried to print te result in the OpenC Code  builder but the pplication is blocked

When I build it is OK but when I want tosee the result by analysing it is deprecated 

Could you know the reason???

0 Kudos
Jeffrey_M_Intel1
Employee
709 Views

Could you send more info on what you found was deprecated/blocked?  Which OpenCL release are you using?  On which operating system?

For an example using read_imagef, the Intel SDK for OpenCL applications Codebuilder Visual Studio integration can generate a starting point based on images.  It can often be helpful to begin with a known good starting point.

 

0 Kudos
Reply