cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

uforob
Journeyman III

Conditional and synchronization instructions in kernel functions

I wrote a code that would be like the one attached but i obtain wrong results. The question are

- for some reason is it better or correct inverting blocks inserting do nothing in the "else" block?

- what's the effect of inlcuding sinchronization instructions inside a block of a conditional?

if(...) { //do nothing } else { //do something ... barrier(CLK_LOCAL_MEM_FENCE); .... barrier(CLK_LOCAL_MEM_FENCE); }

0 Likes
2 Replies
pulec
Journeyman III

ad 1) May I ask why don't you just invert the condition and put the "do something" into the if-block? (And omit the else block)? It is not an error, but I think it'd be better.
If the results are wrong, don't you also need global memory synchronisation?
ad 2) The OpenCL specification:
"If barrier is inside a conditional statement, then all
work-items must enter the conditional if any work-item
enters the conditional statement and executes the
barrier."
So it is dangerous to do that unless you know that either all or none of the work-items enters the block with the barrier.
EDIT: The work-items are meant work-items inside one work-group.
0 Likes
himanshu_gautam
Grandmaster

From OpenCL Spec 1.1:

If barrier is inside a conditional statement, then all
work-items must enter the conditional if any work-item
enters the conditional statement and executes the
barrier.
If barrer is inside a loop, all work-items must execute
the barrier for each iteration of the loop before any are
allowed to continue execution beyond the barrier.

 

Edit: Sorry.I missed the comment from pulec.

0 Likes