deNorma

Ternary operation for vector (select)

Discussion created by deNorma on Jun 30, 2010
Latest reply on Jun 30, 2010 by Illusio
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.

Outcomes