-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Libomptarget] Remove __tgt_image_info and use the ELF directly #75720
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
Merged
Merged
Changes from all commits
Commits
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
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
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 |
---|---|---|
|
@@ -1624,6 +1624,26 @@ Error GenericPluginTy::deinitDevice(int32_t DeviceId) { | |
return Plugin::success(); | ||
} | ||
|
||
Expected<bool> GenericPluginTy::checkELFImage(__tgt_device_image &Image) const { | ||
StringRef Buffer(reinterpret_cast<const char *>(Image.ImageStart), | ||
target::getPtrDiff(Image.ImageEnd, Image.ImageStart)); | ||
|
||
// First check if this image is a regular ELF file. | ||
if (!utils::elf::isELF(Buffer)) | ||
return false; | ||
|
||
// Check if this image is an ELF with a matching machine value. | ||
auto MachineOrErr = utils::elf::checkMachine(Buffer, getMagicElfBits()); | ||
if (!MachineOrErr) | ||
return MachineOrErr.takeError(); | ||
|
||
if (!*MachineOrErr) | ||
return false; | ||
|
||
// Perform plugin-dependent checks for the specific architecture if needed. | ||
return isELFCompatible(Buffer); | ||
} | ||
|
||
const bool llvm::omp::target::plugin::libomptargetSupportsRPC() { | ||
#ifdef LIBOMPTARGET_RPC_SUPPORT | ||
return true; | ||
|
@@ -1651,44 +1671,26 @@ int32_t __tgt_rtl_init_plugin() { | |
} | ||
|
||
int32_t __tgt_rtl_is_valid_binary(__tgt_device_image *TgtImage) { | ||
// TODO: We should be able to perform a trivial ELF machine check without | ||
// initializing the plugin first to save time if the plugin is not needed. | ||
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. Right, we need a "static" part and a post-init part. The former should weed out clear mismatches and the latter can check things like version numbers and flag support. |
||
if (!Plugin::isActive()) | ||
return false; | ||
|
||
if (utils::elf::checkMachine(TgtImage, Plugin::get().getMagicElfBits())) | ||
return true; | ||
|
||
return Plugin::get().getJIT().checkBitcodeImage(*TgtImage); | ||
} | ||
|
||
int32_t __tgt_rtl_is_valid_binary_info(__tgt_device_image *TgtImage, | ||
__tgt_image_info *Info) { | ||
if (!Plugin::isActive()) | ||
return false; | ||
|
||
if (!__tgt_rtl_is_valid_binary(TgtImage)) | ||
// Check if this is a valid ELF with a matching machine and processor. | ||
auto MatchOrErr = Plugin::get().checkELFImage(*TgtImage); | ||
if (Error Err = MatchOrErr.takeError()) { | ||
[[maybe_unused]] std::string ErrStr = toString(std::move(Err)); | ||
DP("Failure to check validity of image %p: %s", TgtImage, ErrStr.c_str()); | ||
return false; | ||
|
||
// A subarchitecture was not specified. Assume it is compatible. | ||
if (!Info->Arch) | ||
} else if (*MatchOrErr) { | ||
return true; | ||
|
||
// Check the compatibility with all the available devices. Notice the | ||
// devices may not be initialized yet. | ||
auto CompatibleOrErr = Plugin::get().isImageCompatible(Info); | ||
if (!CompatibleOrErr) { | ||
// This error should not abort the execution, so we just inform the user | ||
// through the debug system. | ||
std::string ErrString = toString(CompatibleOrErr.takeError()); | ||
DP("Failure to check whether image %p is valid: %s\n", TgtImage, | ||
ErrString.data()); | ||
return false; | ||
} | ||
|
||
bool Compatible = *CompatibleOrErr; | ||
DP("Image is %scompatible with current environment: %s\n", | ||
(Compatible) ? "" : "not", Info->Arch); | ||
// Check if this is a valid LLVM-IR file with matching triple. | ||
if (Plugin::get().getJIT().checkBitcodeImage(*TgtImage)) | ||
return true; | ||
|
||
return Compatible; | ||
return false; | ||
} | ||
|
||
int32_t __tgt_rtl_supports_empty_images() { | ||
|
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.
Why not use
amdhsa.target
string from the metadata and pass it is as is to the existing function?https://llvm.org/docs/AMDGPUUsage.html#amdgpu-amdhsa-code-object-metadata-map-table-v4
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.
Does that net us anything? The information seems freely available in the ELF flags which is easier to retrieve than the AMDHSA metadata that's stored in a YAML form if memory serves. This way we don't need to parse anything and it's fast in the common case (No special flags set).
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.
If we get the information from the ELF, it makes sense to use it. Unsure why it's duplicated though.