Results 1 to 9 of 9

Thread: Not able to read the image using clcreateimage & read_imagei in OpenCL

  1. #1
    Newbie
    Join Date
    Aug 2013
    Posts
    9

    Not able to read the image using clcreateimage & read_imagei in OpenCL

    I want to use ClcreateImage to create the image mem object and then use read_imagei for reading the image in the kernel. But read_imagei is not reading and hence getting "0" values for all the channles- ARGB. Can you let me know what can be wrong ? as i tried all the options but not able to read the image.
    I have created the image mem object using clCreateImage with mem flags as CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR and have given the host ptr as the ptr to the image buffer which i want to read. Its a pointer to int(int *). I also tried it making pointer to char(char *) but still not able to get the values through read_imagei. its allways returning 0 values for all the reads. clCreateImage is successfull. Please let me know why i am not able to read the proper values from read_imagei. And also is there any way by which i can find whether the read_imagei is successfull or not ? Please reply urgently as i am stuck with this issue

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Posts
    165
    It would be helpful to see the image definition and your sampler definition. Without that i can't tell you where you have your problems

  3. #3
    Newbie
    Join Date
    Aug 2013
    Posts
    9
    Thanks for your quick reply. I am not using any sampler.
    channel data type is set to -> CL_SIGNED_INT8; channel order as CL_BGRA.
    for image description: image type as -> CL_MEM_OBJECT_IMAGE2D & have specified width & height. All other parameters are assigned to 0 in image descriptor strcuture.

    In kernel this is the call(img_ptr is of type image2d_t)
    int4 test=read_imagei(img_ptr,coords);
    and then using the values as test.s0-> for r. test.s1 -> for g. test.s2->b which are allways 0

  4. #4
    Senior Member
    Join Date
    Oct 2012
    Posts
    165
    looks fine as i can see.

    Memory for your image is set on the host correctly without any errors?

  5. #5
    Newbie
    Join Date
    Aug 2013
    Posts
    9
    Yes all are returning successfully. But dont know why the values are zeros. Is the accessing in kernel correct ? -> test.s0, test.s1, test.s2 ?

  6. #6
    Newbie
    Join Date
    Aug 2013
    Posts
    9
    Inside kernel when i get the image through read_image. After that can i use scalar operations on the (ARGB) values ? I want to use them as image.s0 to image.s3 and then use scalar operations on them and write back the results in a mem object buffer and not a mem oject image

  7. #7
    Hi,

    Few things to check:
    1. Check the alignment of the host allocated buffer. Appendix C.3 provides the aligment rules.
    2. Note that when using CL_MEM_USE_HOST_PTR, implementations may cache the host data at some "unknown time" - somewhere between creating the image and enqueuing the kernel (see Table 5.3). this is done due to lazy allocation policy on some implementations - image/buffer are not really allocated until used for the first time. The way to control this allocation and ensure desired behaviour is to do the following:
    - Call clCreateImage
    - Call clEnqueueMapImage with blocking
    - Write the image data to the buffer on the host side
    - Call clEnqueueUnmapMemObject
    - Call clEnqueueNDRangeKernel with your kernel

  8. #8
    Newbie
    Join Date
    Aug 2013
    Posts
    9
    Hi All,
    To some extent, problem is resolved. But facing few more issues. The issue was because i was using read_image/write_image in kernel with sampler less calls which are not supported on my device which supports opencl 1.1 only
    But now the problem faced by me is that for first attempt the kernel works fine and for second iteration it crashes in clEnqueueWriteImage. I have two images which are passed through image2d_t to kernel. Both are passed as read only as they both are textures. One of them allways crashes in the second iteration for clEnqueueWriteImage. Any inputs is appreciated.
    Both the image mem object are created with CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR and then buffer is copied to the mem object through clEnqueueWriteImage
    Last edited by mpatil2004; 08-13-2013 at 12:10 AM.

  9. #9
    Newbie
    Join Date
    Aug 2013
    Posts
    9
    Hi All,
    Thanks for spending your time and replying to my query. The problem is resolved now. The main reason as mentioned before was the usage of read_imageui without sampler which is not supported in opencl 1.1. Now i am able to run the code wihtout any issues. Thanks again for your replying

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •