Results 1 to 5 of 5

Thread: Iterate over built-in vector type?

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    8

    Iterate over built-in vector type?

    Hi.
    Is there a possibility to iterate over the built-in vector types
    (float4, uint16, etc.) ?
    As far as I've seen in the "quick reference card" it is only possible
    to access the elements using either "v.x; v.y; ... v.w;" or
    "v.s0, v.s1, ....".
    Is it possible to access all elements of a float16 by simply incrementing
    an index? Or do I have to access all elements manually?

  2. #2

    Re: Iterate over built-in vector type?

    Quote Originally Posted by wakko
    Is it possible to access all elements of a float16 by simply incrementing
    an index? Or do I have to access all elements manually?
    The vector types are not arrays, you cannot index them nor take pointers to their members.

  3. #3
    Member
    Join Date
    Mar 2010
    Location
    Raleigh, NC
    Posts
    55

    Re: Iterate over built-in vector type?

    If you need to add two vectors together, OpenCL handles that automatically for you. For example

    Code :
    float4 a;
    float4 b;
    float4 c;
     
    c = a+b;

    this would be equivalent to:
    Code :
    float4 a;
    float4 b;
    float4 c;
     
    c.x = a.x + b.x;
    c.y = a.y + b.y;
    c.z = a.z + b.z;
    c.w = a.w + b.w;

    Check out the handy dandy 'cheat sheet' for OpenCL on math operations that support the vector types. Saves quite a bit of lines of code I find

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    8

    Re: Iterate over built-in vector type?

    Thanks. I am aware of how the built-in vector types work and
    that they are not comparable to arrays. But I have to pass
    lots of uint-arrays with a length of 16 into a kernel and thought that
    using uint16 types on the device could be helpful.
    As each element has to be accessed individually I was hoping that
    there would be a smart way to access all single elements of a "type16"
    vector without having to write at least 16 lines of code.
    Apparently there isn't so I'll have to use arrays instead.

  5. #5

    Re: Iterate over built-in vector type?

    Quote Originally Posted by wakko
    Thanks. I am aware of how the built-in vector types work and
    that they are not comparable to arrays. But I have to pass
    lots of uint-arrays with a length of 16 into a kernel and thought that
    using uint16 types on the device could be helpful.
    As each element has to be accessed individually I was hoping that
    there would be a smart way to access all single elements of a "type16"
    vector without having to write at least 16 lines of code.
    Apparently there isn't so I'll have to use arrays instead.
    Vectors are useful when you want to do the same thing to all elements simultaneously. If you are doing operations on individual elements then you aren't using the vector hardware effectively and the language doesn't try to support operations that cannot be done efficiently.

Similar Threads

  1. Replies: 0
    Last Post: 01-31-2012, 10:29 AM
  2. Replies: 1
    Last Post: 10-01-2009, 05:04 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
  •