Page MenuHomePhabricator

[amdgpu] Error, instead of miscompile, anonymous kernels using lds
ClosedPublic

Authored by JonChesterfield on Sep 27 2022, 7:47 AM.

Details

Summary

The association between kernel and struct is done by symbol name.
This doesn't work robustly for anonymous kernels as shown by the modified
test case.

An alternative association between function and struct can be constructed
if necessary, probably though metadata, but on the basis that we currently
miscompile anonymous kernels and that they are difficult to construct from
application code and difficult to call from the runtime, this patch makes
it a fatal error for now.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 7:47 AM
JonChesterfield requested review of this revision.Sep 27 2022, 7:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 7:47 AM

The other option is to generate a name for the anonymous kernels from within the lds pass but that's a gross mixing of concerns. D127052 suggested using Mangler::getNameWithPrefix, but that's a local state thing so an instance created in the lowering pass won't necessarily hand out the same names as an instance created in the backend. So we could use that to name the functions here but we'd have to actually setName them.

Needs test that hits the error

I like the test idea but a credible guess at how to write one is not working. Can you see the mistake in this? not --crash opt < %s has a couple of existing examples in tree.

; RUN: not --crash opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds < %s | FileCheck %s
; RUN: not --crash opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s | FileCheck %s

@var1 = addrspace(3) global i32 undef, align 8

; CHECK: LLVM ERROR: Anonymous kernels cannot use LDS variables
define amdgpu_kernel void @0() {
  %val0 = load i32, i32 addrspace(3)* @var1
  %val1 = add i32 %val0, 4
  store i32 %val1, i32 addrspace(3)* @var1
  ret void
}

Fails with exit code: 2 and the stack trace, though it also prints that error exactly as specified by the check line

  • add not working test case
  • drop align from test
arsenm added inline comments.Sep 28 2022, 7:42 AM
llvm/test/CodeGen/AMDGPU/lds-reject-anonymous-kernels.ll
3

Needs 2>&1 to redirect the error to stdout

3

to stdin

  • redirect stderr
llvm/test/CodeGen/AMDGPU/lds-reject-anonymous-kernels.ll
3

great spot, thanks!

arsenm accepted this revision.Sep 28 2022, 8:12 AM
This revision is now accepted and ready to land.Sep 28 2022, 8:12 AM
This revision was landed with ongoing or failed builds.Sep 28 2022, 8:39 AM
This revision was automatically updated to reflect the committed changes.