Results 1 to 2 of 2

Thread: Ternary operation for vector (select)

  1. #1
    Junior Member
    Join Date
    Dec 2009

    Ternary operation for vector (select)

    I want to know how to use the ternary operator for vector in openCL. I think it should be 'select', in the specification:

    page 219

    say, I have a float4 for each work-item(thread)

    float4 a,b,c;
    // I want to do this for every component, i.e. y, z, w
    if (a.x*b.x>0)

    I think writing it like this will slow down the program. I tried to use 'select', to just use one line, but don't know how... Could anyone give me an example?

    Thank you very much.

  2. #2
    Junior Member
    Join Date
    Apr 2010

    Re: Ternary operation for vector (select)

    Code :
    // 4-tuple integer
    int4 myResult;
    // Variable to hold boolean condition
    int4 c;
    // Component wise compare -- 
    //   According to the spec:
    //   These functions shall return a 0 if the specified relation 
    //   is false and a 1 (i.e. all bits set) if the specified relation 
    //   is true for vector argument types.
    //   Most Significant Bit (MSB)
    //   Translation: If true, MSB is set. 
    //                       If false, it is not set.
    c = isgreater( a * b, 0)
    // c should now have each entry with MSB set or unset
    // Can do the ternary comparison now
    // If true then (parameter 1): 2 * a * b
    // If false then (parameter 0): 0
    myResult = select(0, a*b*2, c);

    I didn't check if this would compile. I constructed this from pp 218-219.

Similar Threads

  1. cl::vector vs std::vector: different iterator behaviour
    By rdoubleui in forum OpenCL - parallel programming of heterogeneous systems
    Replies: 0
    Last Post: 01-31-2012, 09:29 AM
  2. vector types not friendly to C++ (specifically, std::vector)
    By coleb in forum OpenCL - parallel programming of heterogeneous systems
    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