Results 1 to 4 of 4

Thread: Weird result with unsigned char type

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    27

    Weird result with unsigned char type

    Hello.

    I wrote a very simple kernel that just copies the data from a source to a destination (e.g. image copy).

    Code :
    __kernel void copy_img(
    __global unsigned char *src, 
    __global unsigned char *dst, 
    const int w
    ) 
    {
    	int gid_x = get_global_id(0) ;
    	int gid_y = get_global_id(1) ;
    	int index = gid_x + gid_y * w ;
     
    	dst[index] = src[index] ;
    }

    When I run this kernel with CPU (CL_DEVICE_CPU), it works well. However, the kernel above results in a weird result when it is run on GPU (CL_DEVICE_GPU). Most of the destination array is filled with garbage data..

    An interesting thing is that the kernel work well when I changed the data type of destination array from 'unsigned char *' to 'float *' !!

    Code :
    __kernel void copy_img(
    __global unsigned char *src, 
    __global float *dst, 
    const int w
    ) 
    {
    	int gid_x = get_global_id(0) ;
    	int gid_y = get_global_id(1) ;
    	int index = gid_x + gid_y * w ;
     
    	dst[index] = src[index] ;
    }

    This is very weird..
    Is there anything I have to keep in my mind to work with unsigned char type ??

    Thanks in advance.

  2. #2
    Member
    Join Date
    Nov 2009
    Location
    Scotland
    Posts
    72

    Re: Weird result with unsigned char type

    What datatype are you actually working with? Are you working on an array of unsigned char or an array of float?

    When you use char, each work-item only copies one byte at a time (sizeof(cl_uchar)==1). When using float, each work-item copies four bytes at a time (sizeof(cl_float)==4).

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    27

    Re: Weird result with unsigned char type

    What datatype are you actually working with? Are you working on an array of unsigned char or an array of float?

    Actually, my data is in unsigned char, a gray image with 8 bits per pixel. So my initial kernel function receives unsigned char array as arguments. When I changed the data type to float* in the kernel, I also changed the image data to a float array.

    So there is no confusion in data type....

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Weird result with unsigned char type

    That could a bug in the OpenCL implementation you are using. Since it's so easy to reproduce, why not reporting this bug to the vendor?
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Similar Threads

  1. Replies: 0
    Last Post: 07-18-2012, 11:23 AM
  2. unsigned int or cl_uint?
    By mihzaha in forum OpenCL
    Replies: 1
    Last Post: 08-18-2010, 12:07 AM

Posting Permissions

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