Results 1 to 3 of 3

Thread: Reverse (.rev) Vector Components

  1. #1
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Reverse (.rev) Vector Components

    I ran into a case where it would be really useful to reverse the vector components. To create fully compliant BLAS functions, one must account for when the steps between elements (e.g., incx), are negative. Since hardware vendors may not support implicitly vectorize, elements may need to be explicitly packed into vector types.

    To treat negative and non-unit increments, I copy the relevent elements from low-to-high global memory addresses to low-to-high local memory. Then I do a vload from local memory into private memory, where I currently shuffle (if needed), compute, and shuffle (again if needed) before doing a vstore to local memory, and then back into global memory.

    Since the OpenCL specification already includes .hi, .lo, .even, .odd, I think .rev would be a natural addition. Of course I can continue to just use the built-in shuffle function, but then I need to create a reverse mask for each vector length. I think .hi, .lo, .even, and .odd being already in the spec. makes a reasonable argument to include .rev as well.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    5

    Re: Reverse (.rev) Vector Components

    Quote Originally Posted by sean.settle
    I can continue to just use the built-in shuffle function, but then I need to create a reverse mask for each vector length.
    Instead of using 'shufle()' you can also just do something like:
    Code :
    float4 a = { 1.0f, 2.0f, 3.0f, 4.0f };
    float4 b;
     
    b = a.wzyx;  //reverses a

    If that doesn't look explicit enough, just write a macro to do the same.

  3. #3
    Senior Member
    Join Date
    Mar 2011
    Location
    Seoul
    Posts
    118

    Re: Reverse (.rev) Vector Components

    Reversing built-in vector types using shuffles and swizzles are explicit, but not readily portable for different vector lengths because function overloading in not included in the OpenCL C kernel language. Of course it's not too difficult manually reverse them, but it seems like it would be a simple thing to add to the specification to make things easier/faster and less prone to error when dealing with swizzles.

Similar Threads

  1. Sum Vector Components in OpenCL (SSE-like)
    By hadesnumb in forum OpenCL
    Replies: 1
    Last Post: 05-30-2012, 02:43 AM
  2. OpenCL 1.1 Rev. 44
    By sean.settle in forum OpenCL
    Replies: 0
    Last Post: 06-11-2011, 09:36 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
  •