This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] New intrinsic void llvm.amdgcn.s.sethalt(i32)
ClosedPublic

Authored by foad on Mar 1 2021, 1:58 AM.

Details

Summary

The expected use case is for frontends to insert this into
shaders that are to be run under a debugger. The shader can
then be resumed or single stepped from the point of the call
under debugger control.

Diff Detail

Event Timeline

foad created this revision.Mar 1 2021, 1:58 AM
foad requested review of this revision.Mar 1 2021, 1:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 1:58 AM
arsenm added inline comments.Mar 1 2021, 6:09 AM
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
1288

Is this really willreturn?

llvm/test/CodeGen/AMDGPU/llvm.amdgcn.s.sethalt.ll
4

I prefer to keep the -global-isel as the first argument

foad added inline comments.Mar 1 2021, 6:15 AM
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
1288

Yes, as far as the generated code is concerned. It doesn't really know that it'll be stopped in the debugger for a while, and we definitely want it to function correctly if/when the debugger resumes it.

foad updated this revision to Diff 327098.Mar 1 2021, 6:23 AM

Move -global-isel to front.

arsenm accepted this revision.Mar 1 2021, 6:23 AM
This revision is now accepted and ready to land.Mar 1 2021, 6:23 AM
This revision was landed with ongoing or failed builds.Mar 1 2021, 6:30 AM
This revision was automatically updated to reflect the committed changes.
t-tye added a comment.Mar 1 2021, 6:11 PM

The expected use case is for frontends to insert this into
shaders that are to be run under a debugger. The shader can
then be resumed or single stepped from the point of the call
under debugger control.

Please check with the AMDGPU debugger team before making these assumptions:-) It turns out that the debugger did recently add support for tracking the wave halt state independent of the breakpoint state so this is fine. However, using this does not notify the debugger. A better alternative is to use the llvm.debug intrinsic that will notify the debugger when executed, and also halt the wave for the debugger to resume.

foad added a comment.Mar 2 2021, 2:49 AM

A better alternative is to use the llvm.debug intrinsic

It looks like llvm.debugtrap is only supported on HSA?

that will notify the debugger when executed, and also halt the wave for the debugger to resume.

Right, I realise that llvm.debugtrap/s_trap is a more normal way of breaking into a debugger. But there is more than one debugger, and more than one way of debugging things, and for cases where you want to halt the program and attach a debugger after the fact, llvm.amdgcn.s.sethalt/s_sethalt seems like a useful thing.

t-tye added a comment.Mar 2 2021, 5:48 PM

What other debuggers do you have in mind? There is the rocgdb and the UMR hardware debugger. Do you know of others for AMDGPU? If non-HSA targets would like to support a debugger it would make sense that the also add support for llvm.debugtrap as well:-)

Also, does this patch account for the hardware hazard that you must not have an s_endpgm following an s_halt on asics that do not support it? One approach to avoid the hazard is to always put a s_nop after an s_halt.

foad added a comment.Mar 3 2021, 1:15 AM

What other debuggers do you have in mind?

Windbg and umr.

If non-HSA targets would like to support a debugger it would make sense that the also add support for llvm.debugtrap as well:-)

Makes sense to me. It seems like the lowering of llvm.debugtrap to s_trap is deliberately restricted to HSA, but I don't know the history of that.

Also, does this patch account for the hardware hazard that you must not have an s_endpgm following an s_halt on asics that do not support it? One approach to avoid the hazard is to always put a s_nop after an s_halt.

No I was not aware of that. I'll see what I can do...