-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AMDGPU] Update code object metadata for kernarg preload #134666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kerbowa
wants to merge
4
commits into
main
Choose a base branch
from
users/kerbowa/preload-kernarg-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+862
−178
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1742b90
[AMDGPU] Update code object metadata for kernarg preload
kerbowa c4bc0cd
Add suggested formatting changes, factor out common parts of emitKenr…
kerbowa d00833e
Factor common emit hidden kernel args metadata.
kerbowa 82c8a97
Rebase on changes to move preloading lowering to its own pass.
kerbowa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,7 +11,10 @@ | |||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
#include "MCTargetDesc/AMDGPUMCTargetDesc.h" | ||||||||||||||||||||||||||||||||||||
#include "llvm/ADT/DenseMap.h" | ||||||||||||||||||||||||||||||||||||
#include "llvm/Analysis/ValueTracking.h" | ||||||||||||||||||||||||||||||||||||
#include "llvm/CodeGen/Register.h" | ||||||||||||||||||||||||||||||||||||
#include "llvm/IR/LLVMContext.h" | ||||||||||||||||||||||||||||||||||||
#include "llvm/IR/Type.h" | ||||||||||||||||||||||||||||||||||||
#include "llvm/Pass.h" | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
namespace llvm { | ||||||||||||||||||||||||||||||||||||
|
@@ -95,11 +98,79 @@ inline raw_ostream &operator<<(raw_ostream &OS, const ArgDescriptor &Arg) { | |||||||||||||||||||||||||||||||||||
return OS; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
struct KernArgPreloadDescriptor : public ArgDescriptor { | ||||||||||||||||||||||||||||||||||||
KernArgPreloadDescriptor() {} | ||||||||||||||||||||||||||||||||||||
SmallVector<MCRegister> Regs; | ||||||||||||||||||||||||||||||||||||
namespace KernArgPreload { | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
enum HiddenArg { | ||||||||||||||||||||||||||||||||||||
HIDDEN_BLOCK_COUNT_X, | ||||||||||||||||||||||||||||||||||||
HIDDEN_BLOCK_COUNT_Y, | ||||||||||||||||||||||||||||||||||||
HIDDEN_BLOCK_COUNT_Z, | ||||||||||||||||||||||||||||||||||||
HIDDEN_GROUP_SIZE_X, | ||||||||||||||||||||||||||||||||||||
HIDDEN_GROUP_SIZE_Y, | ||||||||||||||||||||||||||||||||||||
HIDDEN_GROUP_SIZE_Z, | ||||||||||||||||||||||||||||||||||||
HIDDEN_REMAINDER_X, | ||||||||||||||||||||||||||||||||||||
HIDDEN_REMAINDER_Y, | ||||||||||||||||||||||||||||||||||||
HIDDEN_REMAINDER_Z, | ||||||||||||||||||||||||||||||||||||
END_HIDDEN_ARGS | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Stores information about a specific hidden argument. | ||||||||||||||||||||||||||||||||||||
struct HiddenArgInfo { | ||||||||||||||||||||||||||||||||||||
// Offset in bytes from the location in the kernearg segment pointed to by | ||||||||||||||||||||||||||||||||||||
// the implicitarg pointer. | ||||||||||||||||||||||||||||||||||||
uint8_t Offset; | ||||||||||||||||||||||||||||||||||||
// The size of the hidden argument in bytes. | ||||||||||||||||||||||||||||||||||||
uint8_t Size; | ||||||||||||||||||||||||||||||||||||
// The name of the hidden argument in the kernel signature. | ||||||||||||||||||||||||||||||||||||
const char *Name; | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
Comment on lines
+117
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
struct HiddenArgUtils { | ||||||||||||||||||||||||||||||||||||
static constexpr HiddenArgInfo HiddenArgs[END_HIDDEN_ARGS] = { | ||||||||||||||||||||||||||||||||||||
{0, 4, "_hidden_block_count_x"}, {4, 4, "_hidden_block_count_y"}, | ||||||||||||||||||||||||||||||||||||
{8, 4, "_hidden_block_count_z"}, {12, 2, "_hidden_group_size_x"}, | ||||||||||||||||||||||||||||||||||||
{14, 2, "_hidden_group_size_y"}, {16, 2, "_hidden_group_size_z"}, | ||||||||||||||||||||||||||||||||||||
{18, 2, "_hidden_remainder_x"}, {20, 2, "_hidden_remainder_y"}, | ||||||||||||||||||||||||||||||||||||
{22, 2, "_hidden_remainder_z"}}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static HiddenArg getHiddenArgFromOffset(unsigned Offset) { | ||||||||||||||||||||||||||||||||||||
for (unsigned I = 0; I < END_HIDDEN_ARGS; ++I) { | ||||||||||||||||||||||||||||||||||||
if (HiddenArgs[I].Offset == Offset) | ||||||||||||||||||||||||||||||||||||
return static_cast<HiddenArg>(I); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return END_HIDDEN_ARGS; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static Type *getHiddenArgType(LLVMContext &Ctx, HiddenArg HA) { | ||||||||||||||||||||||||||||||||||||
if (HA < END_HIDDEN_ARGS) | ||||||||||||||||||||||||||||||||||||
return Type::getIntNTy(Ctx, HiddenArgs[HA].Size * 8); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
llvm_unreachable("unexpected hidden argument"); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static const char *getHiddenArgName(HiddenArg HA) { | ||||||||||||||||||||||||||||||||||||
if (HA < END_HIDDEN_ARGS) | ||||||||||||||||||||||||||||||||||||
return HiddenArgs[HA].Name; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
llvm_unreachable("unexpected hidden argument"); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
struct KernArgPreloadDescriptor { | ||||||||||||||||||||||||||||||||||||
// Id of the original argument in the IR kernel function argument list. | ||||||||||||||||||||||||||||||||||||
unsigned OrigArgIdx = 0; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// If this IR argument was split into multiple parts, this is the index of the | ||||||||||||||||||||||||||||||||||||
// part in the original argument. | ||||||||||||||||||||||||||||||||||||
unsigned PartIdx = 0; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// The registers that the argument is preloaded into. The argument may be | ||||||||||||||||||||||||||||||||||||
// split accross multilpe registers. | ||||||||||||||||||||||||||||||||||||
SmallVector<MCRegister, 2> Regs; | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
} // namespace KernArgPreload | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
struct AMDGPUFunctionArgInfo { | ||||||||||||||||||||||||||||||||||||
// clang-format off | ||||||||||||||||||||||||||||||||||||
enum PreloadedValue { | ||||||||||||||||||||||||||||||||||||
|
@@ -161,14 +232,27 @@ struct AMDGPUFunctionArgInfo { | |||||||||||||||||||||||||||||||||||
ArgDescriptor WorkItemIDZ; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Map the index of preloaded kernel arguments to its descriptor. | ||||||||||||||||||||||||||||||||||||
SmallDenseMap<int, KernArgPreloadDescriptor> PreloadKernArgs{}; | ||||||||||||||||||||||||||||||||||||
SmallDenseMap<int, KernArgPreload::KernArgPreloadDescriptor> | ||||||||||||||||||||||||||||||||||||
PreloadKernArgs{}; | ||||||||||||||||||||||||||||||||||||
// Map hidden argument to the index of it's descriptor. | ||||||||||||||||||||||||||||||||||||
SmallDenseMap<KernArgPreload::HiddenArg, int> PreloadHiddenArgsIndexMap{}; | ||||||||||||||||||||||||||||||||||||
// The first user SGPR allocated for kernarg preloading. | ||||||||||||||||||||||||||||||||||||
Register FirstKernArgPreloadReg; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
std::tuple<const ArgDescriptor *, const TargetRegisterClass *, LLT> | ||||||||||||||||||||||||||||||||||||
getPreloadedValue(PreloadedValue Value) const; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static AMDGPUFunctionArgInfo fixedABILayout(); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Returns preload argument descriptors for an IR argument index. Isel may | ||||||||||||||||||||||||||||||||||||
// split IR arguments into multiple parts, the return vector holds all parts | ||||||||||||||||||||||||||||||||||||
// associated with an IR argument in the kernel signature. | ||||||||||||||||||||||||||||||||||||
SmallVector<const KernArgPreload::KernArgPreloadDescriptor *, 4> | ||||||||||||||||||||||||||||||||||||
getPreloadDescriptorsForArgIdx(unsigned ArgIdx) const; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Returns the hidden arguments `KernArgPreloadDescriptor` if it is preloaded. | ||||||||||||||||||||||||||||||||||||
const KernArgPreload::KernArgPreloadDescriptor * | ||||||||||||||||||||||||||||||||||||
getHiddenArgPreloadDescriptor(KernArgPreload::HiddenArg HA) const; | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
class AMDGPUArgumentUsageInfo : public ImmutablePass { | ||||||||||||||||||||||||||||||||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: