llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AMDGPU] Review intrinsic flags for `int_amdgcn_s_sendmsg`

Open raiseirql opened this issue 1 year ago • 6 comments

This intrinsic and others in the immediate area are not setting the IntrNoCallback flag. Not having this intrinsic prevents PostOrderFunctionAttrsPass from marking a function that uses the intrinsic from having the norecurse flag applied. Ultimately, that then causes the amdhsa_uses_dynamic_stack flag to be set for the kernel.

The use case for this is in our implementation of print() for Mojo that uses the intrinsic to build a native hostcall() implementation. Fixing the intrinsic to have this flag set fixes the problem locally. Other intrinsics such as int_amdgcn_s_sleep do not have the same problem because they derive from DefaultAttrsIntrinsic. Other options are likely available in our LLVM pipeline config, but fixing the intrinsic so far has been the easiest path.

cc: @arsenm

raiseirql avatar Jan 28 '25 17:01 raiseirql

@llvm/issue-subscribers-backend-amdgpu

Author: Tracy Sharpe (raiseirql)

This intrinsic and others in the immediate area are not setting the `IntrNoCallback` flag. Not having this intrinsic prevents `PostOrderFunctionAttrsPass` from marking a function that uses the intrinsic from having the `norecurse` flag applied. Ultimately, that then causes the `amdhsa_uses_dynamic_stack` flag to be set for the kernel.

The use case for this is in our implementation of print() for Mojo that uses the intrinsic to build a native hostcall() implementation. Fixing the intrinsic to have this flag set fixes the problem locally. Other intrinsics such as int_amdgcn_s_sleep do not have the same problem because they derive from DefaultAttrsIntrinsic. Other options are likely available in our LLVM pipeline config, but fixing the intrinsic so far has been the easiest path.

cc: @arsenm

llvmbot avatar Jan 28 '25 17:01 llvmbot

I'm not sure we can do this unconditionally. You can use sendmsg to cause code to execute on the host. We might be able to analyze the specific field values used to set a callsite attribute

arsenm avatar Jan 28 '25 17:01 arsenm

I'm not sure we can do this unconditionally. You can use sendmsg to cause code to execute on the host. We might be able to analyze the specific field values used to set a callsite attribute

Yeah, the specific case is to do the hostcall based on https://github.com/ROCm/llvm-project/blob/656552edc693e2bb4abc9258399c39d190fce2b3/amd/device-libs/ockl/src/hostcall_impl.cl#L57.

raiseirql avatar Jan 28 '25 17:01 raiseirql

Since the implementation there is OpenCL anyway, norecurse is assumed. I guess that doesn't make it to the intrinsic callsite, and gets lost when the original function is inlined?

arsenm avatar Jan 29 '25 03:01 arsenm

In our use case, the hostcall_impl.cl code has been reimplemented in Mojo to avoid link/dependency issues. I imagine there are changes in marking the wrappers as norecurse to fix the problem, but I also wanted to open this issue in case there was a problem with the intrinsic itself.

raiseirql avatar Jan 29 '25 03:01 raiseirql

I don't think we can mark this with nocallback, or nosync. But I think we can directly mark it with norecurse and willreturn. However, tablegen does not currently have an IntrinsicProperty wired up to directly represent norecurse

arsenm avatar Jan 30 '25 02:01 arsenm