cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

deNorma
Journeyman III

Ternary operation for vector (select)

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

http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf

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. x,  y, z, w
if (a.x*b.x>0)
{
c.x=2*a.x*b.x;
}
else
{
c.x=0.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.
0 Likes
1 Reply
Illusio
Journeyman III

Something like this?

c = max(2*a*b,zero);

 

0 Likes