This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] add support for hostcall buffer pointer as hidden kernel argument
ClosedPublic

Authored by sameerds on Nov 8 2019, 7:07 PM.

Details

Summary

Hostcall is a service that allows a kernel to submit requests to the
host using shared buffers, and block until a response is
received. This will eventually replace the shared buffer currently
used for printf, and repurposes the same hidden kernel argument. This
change introduces a new ValueKind in the HSA metadata to represent the
hostcall buffer.

Event Timeline

sameerds created this revision.Nov 8 2019, 7:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2019, 7:08 PM
arsenm added inline comments.Nov 11 2019, 9:18 PM
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
872–873

Is this metadata really necessary if the runtime can just check if the symbol is used?

sameerds updated this revision to Diff 229744.Nov 17 2019, 10:00 PM
  • add error for printf in hostcall tests
sameerds marked an inline comment as done.Nov 17 2019, 10:09 PM
sameerds added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
872–873

The metadata itself is necessary because the runtime is not aware of the sequence of hidden arguments. It depends on the metadata to identify each of them.
I tried moving the check for the function name "__ockl_hostcall_internal" to the runtime. This would have nicely avoided having to hard-code a library function name into the backend. But such a check needs us to modify the internalize pass so that this name remains visible to the runtime. For that pass to recognize this function, we have to either hardcode it there (which defeats the purpose) or introduce a new variable similar to llvm.used, which is a non-trivial separate task. So the conclusion was to keep the current check exactly as we see it here.

arsenm added inline comments.Nov 18 2019, 8:59 PM
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
425

I would reorder these to try hostcall first, but it's not important

427

This should probably be using the LLVMContext error, instead of the MCContext error to at least report the function context in the error, e.g:

DiagnosticInfoUnsupported NoGraphicsHSA(
    Fn, "unsupported non-compute shaders with HSA", DL.getDebugLoc());
DAG.getContext()->diagnose(NoGraphicsHSA);

There should also be a testcase hitting this error

sameerds updated this revision to Diff 229989.Nov 19 2019, 12:42 AM

Moved the printf/hostcall check to the printf runtime binding pass

sameerds marked an inline comment as done.Nov 19 2019, 12:45 AM
sameerds added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
427

Moved this whole check to the printf runtime binding pass. This is more appropriate since the check is happening where the printf feature is actually processed.

There already was a test for the error check, replaced it with a newer test.

sameerds updated this revision to Diff 230011.Nov 19 2019, 2:22 AM

Cleaned up the changes to minimize the diff

arsenm added inline comments.Nov 19 2019, 4:31 AM
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
427

Asserting here instead of the error is worse from a MIR testing perspective

llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
587 ↗(On Diff #230011)

Should use CallBase in case an invoke is is ever used

588 ↗(On Diff #230011)

I think this goes over 80?

sameerds marked an inline comment as done.Nov 19 2019, 5:21 AM
sameerds added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
427

Why is MIR testing relevant here? printf and hostcall are high-level language features that we are grudgingly handling in the backend for now. Using them both in the same low-level module is undefined, and there is no reason to even write an MIR based test for them.

Also, if asserting is bad, are you asking to keep the error or only remove the assert?

sameerds marked an inline comment as done.Nov 19 2019, 5:26 AM
sameerds added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
587 ↗(On Diff #230011)

I don't really see how we could possibly see an invoke for __ockl_hostcall_internal(). If possible, we would probably mark it as nothrow or something in the library sources. I don't have much of a preference either way, but it seems cleaner to keep the CallInst precisely to document the fact that we don't expect to see an invoke here, and also to match the nearby check for calls to printf itself.

sameerds updated this revision to Diff 230050.Nov 19 2019, 5:30 AM

fixed the line length under 80

arsenm accepted this revision.Nov 19 2019, 9:40 PM
arsenm added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
427

Because the property enforced by this pass might not be enforced in a MIR run. Asserting on a not-bug edge case MIR sometimes wastes time debugging

llvm/test/CodeGen/AMDGPU/opencl-printf-no-hostcall.ll
16 ↗(On Diff #230050)

Drop the argument names here which I'm surprised even parse?

This revision is now accepted and ready to land.Nov 19 2019, 9:40 PM
This revision was automatically updated to reflect the committed changes.
sameerds marked 2 inline comments as done.
sameerds marked 2 inline comments as done.Nov 20 2019, 2:32 AM
sameerds added inline comments.
llvm/test/CodeGen/AMDGPU/opencl-printf-no-hostcall.ll
16 ↗(On Diff #230050)

Fixed this in the commit.