Flooring without if statement

I want to have a function something like

float func (float data, float floor)
{
float s = 0.0;
for (int i=0; i<10; i++) {
float v = process(data[i]);
if (v<floor[i]) v=floor[i];
s += log(v);
}
return s;
}

based on CUDA.
As you can see, it has “if” statement. I expect that I can become it faster if I can remove if statement.
Does anyone have good ideas to remove “if” statement from this?

Thank you very much.

What do you need floor[i] for? floor[i] == i. So your statement is:

if (v < i) v = i;

Which I assume is identical in effect to v = max(v,i)

If statements like that are very fast on CUDA. CUDA’s predicate system will handle this in a single clock, perhaps even 0.
This is confirmed by actual throughput measurements.
No need to worry about the cost in your case at all, unless you’re just curious.

As an aside, the use of “floor” as a variable name is likely a bad idea, since floor() is also a very common math function name.

floor[i] are minimum values of v. You’re right, it’s identical to v = max(v,floor[i]);

Thank you very much for your reply. I just started learning CUDA and have never measured about this.

I’m very happy to hear your answer, I’ll just use the straight-forward implement.