-
Notifications
You must be signed in to change notification settings - Fork 117
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
[NATIVECPU] Support reqd_work_group_size on Native CPU #1477
Merged
kbenzie
merged 3 commits into
oneapi-src:main
from
PietroGhg:pietro/reqd_work_group_size
May 15, 2024
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 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 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 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 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 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
#include "common.hpp" | ||
#include "program.hpp" | ||
#include <cstdint> | ||
|
||
UR_APIEXPORT ur_result_t UR_APICALL | ||
urProgramCreateWithIL(ur_context_handle_t hContext, const void *pIL, | ||
|
@@ -26,6 +27,39 @@ urProgramCreateWithIL(ur_context_handle_t hContext, const void *pIL, | |
DIE_NO_IMPLEMENTATION | ||
} | ||
|
||
// TODO: taken from CUDA adapter, move this to a common header? | ||
static std::pair<std::string, std::string> | ||
splitMetadataName(const std::string &metadataName) { | ||
size_t splitPos = metadataName.rfind('@'); | ||
if (splitPos == std::string::npos) | ||
return std::make_pair(metadataName, std::string{}); | ||
return std::make_pair(metadataName.substr(0, splitPos), | ||
metadataName.substr(splitPos, metadataName.length())); | ||
} | ||
|
||
static ur_result_t getReqdWGSize(const ur_program_metadata_t &MetadataElement, | ||
native_cpu::ReqdWGSize_t &res) { | ||
size_t MDElemsSize = MetadataElement.size - sizeof(std::uint64_t); | ||
|
||
// Expect between 1 and 3 32-bit integer values. | ||
UR_ASSERT(MDElemsSize == sizeof(std::uint32_t) || | ||
MDElemsSize == sizeof(std::uint32_t) * 2 || | ||
MDElemsSize == sizeof(std::uint32_t) * 3, | ||
UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE); | ||
|
||
// Get pointer to data, skipping 64-bit size at the start of the data. | ||
const char *ValuePtr = | ||
reinterpret_cast<const char *>(MetadataElement.value.pData) + | ||
sizeof(std::uint64_t); | ||
// Read values and pad with 1's for values not present. | ||
std::uint32_t ReqdWorkGroupElements[] = {1, 1, 1}; | ||
std::memcpy(ReqdWorkGroupElements, ValuePtr, MDElemsSize); | ||
std::get<0>(res) = ReqdWorkGroupElements[0]; | ||
std::get<1>(res) = ReqdWorkGroupElements[1]; | ||
std::get<2>(res) = ReqdWorkGroupElements[2]; | ||
return UR_RESULT_SUCCESS; | ||
} | ||
|
||
UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary( | ||
ur_context_handle_t hContext, ur_device_handle_t hDevice, size_t size, | ||
const uint8_t *pBinary, const ur_program_properties_t *pProperties, | ||
|
@@ -40,6 +74,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary( | |
|
||
auto hProgram = new ur_program_handle_t_( | ||
hContext, reinterpret_cast<const unsigned char *>(pBinary)); | ||
if (pProperties != nullptr) { | ||
for (uint32_t i = 0; i < pProperties->count; i++) { | ||
auto mdNode = pProperties->pMetadatas[i]; | ||
std::string mdName(mdNode.pName); | ||
auto [Prefix, Tag] = splitMetadataName(mdName); | ||
if (Tag == __SYCL_UR_PROGRAM_METADATA_TAG_REQD_WORK_GROUP_SIZE) { | ||
native_cpu::ReqdWGSize_t reqdWGSize; | ||
auto res = getReqdWGSize(mdNode, reqdWGSize); | ||
if (res != UR_RESULT_SUCCESS) { | ||
return res; | ||
} | ||
hProgram->KernelReqdWorkGroupSizeMD[Prefix] = std::move(reqdWGSize); | ||
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. Minor (for a later PR): It might be worth diagnosing when an existing prefix gets overwritten with a different |
||
} | ||
} | ||
} | ||
|
||
const nativecpu_entry *nativecpu_it = | ||
reinterpret_cast<const nativecpu_entry *>(pBinary); | ||
|
This file contains 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
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.
Should there also be a
hProgram(other.hProgram)
in the mem initiliser list?