This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Emit runtime metadata as a note element in .note section
ClosedPublic

Authored by yaxunl on Oct 19 2016, 11:13 AM.

Details

Summary

Currently runtime metadata is emitted as an ELF section with name .AMDGPU.runtime_metadata.

However there is a standard way to convey vendor specific information about how to run an ELF binary, which is called vendor-specific note element (http://www.netbsd.org/docs/kernel/elf-notes.html).

This patch lets AMDGPU backend emits runtime metadata as a note element in .note section.

Diff Detail

Repository
rL LLVM

Event Timeline

yaxunl updated this revision to Diff 75172.Oct 19 2016, 11:13 AM
yaxunl retitled this revision from to AMDGPU: Emit runtime metadata as a note element in .note section.
yaxunl updated this object.
yaxunl added a subscriber: llvm-commits.
yaxunl updated this revision to Diff 75200.Oct 19 2016, 12:26 PM
yaxunl edited edge metadata.

Revised by Laurent's suggestions.

Fixed size of name and desc. They should not include padding 0's.

Extracted enums of note type as a separate header file so that it can be shared between backend and runtime.

lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
47–84 ↗(On Diff #75200)

These functions belong in AMDGPUTargetStreamer classes.

lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
14 ↗(On Diff #75200)

Are the changes in this file necessary?

kzhuravl added inline comments.Oct 21 2016, 9:37 AM
lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
1130–1131 ↗(On Diff #75200)

Once you move it to AMDGPUTargetStreamer classes as suggested by Tom, use AMDGPUTargetELFStreamer::NoteName instead of defining the name and size (see rL284760 for more info)

lib/Target/AMDGPU/AMDGPUNoteType.h
20–32 ↗(On Diff #75200)

Note types are defined in AMDGPUTargetELFStreamer. Why redefine them?

lib/Target/AMDGPU/AMDGPURuntimeMetadata.h
41 ↗(On Diff #75200)

I do not think we need to include this here.

52 ↗(On Diff #75200)

This seems like a property of an elf, and not RuntimeMD. I would suggest making it static const char * in AMDGPUTargetELFStreamer (probably along with flags, etc.)

yaxunl updated this revision to Diff 75581.Oct 24 2016, 8:02 AM
yaxunl edited edge metadata.
yaxunl marked 6 inline comments as done.

Revised by Tom and Konstantin's comments.

yaxunl added inline comments.Oct 24 2016, 8:03 AM
lib/Target/AMDGPU/AMDGPUNoteType.h
20–32 ↗(On Diff #75200)

Moved to AMDGPUPTNote.h, which is shared between compiler and runtime.

The runtime needs to know the enum value for note type for runtime. To avoid maintaining two copies of enum definitions, I moved these enum definitions to the shared header file.

lib/Target/AMDGPU/AMDGPURuntimeMetadata.h
52 ↗(On Diff #75200)

This needs to be defined in the shared header file between runtime and compiler.

As you said, it is not runtime metadata specific, so I created AMDPTNote.h and moved it there.

lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
14 ↗(On Diff #75200)

We need to share the enums for PT_NOTE sections with runtime.

kzhuravl edited edge metadata.Oct 25 2016, 8:21 PM

The runtime needs to know the enum value for note type for runtime. To avoid maintaining two copies of enum definitions, I moved these enum definitions to the shared header file.

+ @tony-tye .

This is the right direction, but I think we should discuss this in more details. There are a few files that need to be shared between compiler and runtime (some elf stuff, amd_kernel_code_t, amd_queue_t? amd_signal_t?). Creating a file specifically for note stuff seems like an overkill to me IMHO.

I cleaned up files that are shared between compiler and runtime files a while ago, they are here:

They still need more clean up since we switched to code object v2+. But maybe we can take those as a base.

lib/Target/AMDGPU/AMDGPUPTNote.h
26 ↗(On Diff #75581)

AMD\0

lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
111 ↗(On Diff #75581)

.note -> PT_NOTE::NoteName, same in the below one.

496 ↗(On Diff #75581)

I think ELF streaming belongs to AMDGPUTargetELFStreamer?

lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.h
46 ↗(On Diff #75581)

Doxygenify?

yaxunl marked 6 inline comments as done.Oct 27 2016, 8:36 AM

This is the right direction, but I think we should discuss this in more details. There are a few files that need to be shared between compiler and runtime (some elf stuff, amd_kernel_code_t, amd_queue_t? amd_signal_t?). Creating a file specifically for note stuff seems like an overkill to me IMHO.

I cleaned up files that are shared between compiler and runtime files a while ago, they are here:

They still need more clean up since we switched to code object v2+. But maybe we can take those as a base.

I agree. Since it will take time and efforts to clean up and incorporate these header files, I would suggest to leave it to another patch.

lib/Target/AMDGPU/AMDGPUPTNote.h
26 ↗(On Diff #75581)

This is unnecessary since the literal string "AMD" has an implied trailing 0 and sizeof(NoteName) will include that, i.e., sizeof(NoteName)==4.

lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
496 ↗(On Diff #75581)

Normally I should define virtual functions for streaming the runtime metadata in textual and binary form separately in AMGGPUTargetASMStreamer and AMDGPUTargetELFStreamer. However we will replace this runtime metadata format with YAML based runtime metadata format soon, so I feel not worth the efforts to implement the textual format for the current runtime metadata format. After we move to YAML based runtime metadata format, I will come back to a better solution.

yaxunl updated this revision to Diff 76040.Oct 27 2016, 8:44 AM
yaxunl edited edge metadata.
yaxunl marked 2 inline comments as done.

Revised by Konstantin's comments.

Minor formatting + question

lib/Target/AMDGPU/AMDGPUPTNote.h
29–38 ↗(On Diff #76040)

This might have been formatted incorrectly? Seems like '};' at column 2, but 'enum NoteType' at column 0?

lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
496 ↗(On Diff #75581)

Shouldn't we define pure virtual functions in base class, only implement them in AMDGPUTargetELFStreamer subclass, and possibly define same functions in AMGGPUTargetASMStreamer subclass but leave the body empty?

363 ↗(On Diff #76040)

Formatting

yaxunl added inline comments.Nov 8 2016, 7:02 AM
lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
496 ↗(On Diff #75581)

If we do this, there will be no runtime metadata in the llc output. Then how do we test this?

kzhuravl added inline comments.Nov 8 2016, 11:59 AM
lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
496 ↗(On Diff #75581)

-filetype=obj will cause llc to produce elf, which will have runtime metadata. Since it is a temporary solution as you indicated before, I am fine with what is currently done. Please, also, run it by Matt or Tom.

yaxunl added inline comments.Nov 10 2016, 12:16 PM
lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.cpp
496 ↗(On Diff #75581)

This requests rewriting the test in a new way. Currently there is not enough time to make this change. Can we leave this to future?

yaxunl updated this revision to Diff 77543.Nov 10 2016, 1:05 PM
yaxunl edited edge metadata.
yaxunl marked 6 inline comments as done.

Fix format issue.

kzhuravl accepted this revision.Nov 10 2016, 1:09 PM
kzhuravl edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 10 2016, 1:09 PM
This revision was automatically updated to reflect the committed changes.