================
@@ -409,6 +409,13 @@ def int_amdgcn_iglp_opt : 
ClangBuiltin<"__builtin_amdgcn_iglp_opt">,
   Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem, 
IntrHasSideEffects, IntrConvergent,
                                 IntrWillReturn, IntrNoCallback, IntrNoFree]>;
 
+// Optional exact-count hint to pad the opposite arm of a supported branch.
+// The hint itself has no hardware counter effect.
+def int_amdgcn_pad_waitcnt : ClangBuiltin<"__builtin_amdgcn_pad_waitcnt">,
+  Intrinsic<[], [llvm_i32_ty, llvm_i32_ty],
+    [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, IntrNoMem, IntrHasSideEffects,
+     IntrConvergent, IntrWillReturn, IntrNoCallback, IntrNoFree]>;
----------------
ssahasra wrote:

> I made the operation convergent because the padding bumps a counter across 
> all threads in a threadgroup, so I was thinking that's _technically_ cross 
> thread communication. I was also following the fact that 
> sched.barrier/iglp.op are both hints and are marked convergent.
> 
> But we really want these padding instructions to move with their 
> corresponding operations, so I guess we shouldn't mark the padding as 
> convergent? What do you think?

I don't think this should be convergent. The fact that a counter is shared 
across a wave is an implementation detail. This padding is an "instruction that 
does nothing but stays in order with preceding instructions that use the same 
counter". That should be interpreted per thread by the programmer, and it 
should be the compiler's job to make sure it is lowered correctly in the 
overall state of wave.

> Another thought just popped in my head: is it possible/reasonable to annotate 
> operations as "please pad me" instead of introducing this intrinsic? I opted 
> for the intrinsic route to mirror how the aforementioned hints are 
> implemented.

I am not sure about that ... can you say more about how that might work? For 
now, my impression is that the ideal situation is to have the compiler 
automatically always balance counter increments. Seems like a very useful idea, 
and it might need us to go and get a proper "stay in order nop" instead of 
having to use target-specific behaviour like the invalidate(0).

But doing it properly in the compiler might not be desirable right now, while 
@Pierre-vh is busy rearchitecting SIInsertWaitcnts. The new design is meant to 
be very flexible, and this feature seems like a good fit for its power.

Until then, the intrinsic sounds like a good idea. It can outlive the compiler 
enhancement, but should lose its utility when the compiler becomes good at 
padding on its own.

https://github.com/llvm/llvm-project/pull/243204
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to