Results 1 to 2 of 2

Thread: Accessing to bytes in array as to short and int values?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    15

    Accessing to bytes in array as to short and int values?

    Hi GPGPU hackers!

    In my kernel i try to access to __global unsigned char * array as to short and int values and keep having
    weird results with it, for example

    Code :
    __global unsigned short *l2NumPtr = buffer+tolookPos;
    unsigned short l2Num = *l2NumPtr;

    Here i can have l2Num value constructed from tolookPos and tolookPos-1 bit
    (also from position-1 and bits swapped).
    And with:
    Code :
    __global unsigned short *l2NumPtr = buffer+tolookPos-1
    i get the SAME VALUE.
    so in order to acces to any short value correctly, i must have this:
    Code :
    __attribute__((always_inline))
    unsigned short getUShort(__global unsigned char * array, unsigned int position){
     
    	return ((unsigned short)array[position]) << BYTE_SHIFT | array[position+1] ;
    }

    Here, i have 2 operations "wasted" and with Int value, it is already 6 operations.

    Is there any option to have the right access by pointer?

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Accessing to bytes in array as to short and int values?

    You should really read the specification, what you're doing has 'undefined' behaviour (i.e. is not valid code).

    See these sections of the specification:

    6.1.5 Alignment of Types
    6.2.5 Pointer Casting

Similar Threads

  1. Searching for non 0 values in a sparse array
    By vincentfpgarcia in forum OpenCL
    Replies: 1
    Last Post: 01-10-2012, 07:40 PM
  2. options for passing short array
    By noah_r in forum OpenCL
    Replies: 2
    Last Post: 10-22-2011, 05:15 PM

Posting Permissions

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