Skip to content

Commit 25d05f3

Browse files
[SYCL][CUDA] Allow varying program metadata in CUDA backend (#7555)
Recently the program metadata produced for reqd_work_group_size changed to allow between 1 and 3 values instead of guaranteing 3 values. This commit makes the CUDA backend correctly parse reqd_work_group_size metadata with variable number of elements. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent e839d4e commit 25d05f3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,20 @@ pi_result _pi_program::set_metadata(const pi_device_binary_property *metadata,
685685
if (get_kernel_metadata(metadataElementName,
686686
__SYCL_PI_PROGRAM_METADATA_TAG_REQD_WORK_GROUP_SIZE,
687687
kernelName)) {
688-
assert(metadataElement->ValSize ==
689-
sizeof(std::uint64_t) + sizeof(std::uint32_t) * 3 &&
688+
size_t MDElemsSize = metadataElement->ValSize - sizeof(std::uint64_t);
689+
690+
// Expect between 1 and 3 32-bit integer values.
691+
assert(MDElemsSize >= sizeof(std::uint32_t) &&
692+
MDElemsSize <= sizeof(std::uint32_t) * 3 &&
690693
"Unexpected size for reqd_work_group_size metadata");
691694

692695
// Get pointer to data, skipping 64-bit size at the start of the data.
693-
const auto *reqdWorkGroupElements =
694-
reinterpret_cast<const std::uint32_t *>(metadataElement->ValAddr) + 2;
696+
const char *ValuePtr =
697+
reinterpret_cast<const char *>(metadataElement->ValAddr) +
698+
sizeof(std::uint64_t);
699+
// Read values and pad with 1's for values not present.
700+
std::uint32_t reqdWorkGroupElements[] = {1, 1, 1};
701+
std::memcpy(reqdWorkGroupElements, ValuePtr, MDElemsSize);
695702
kernelReqdWorkGroupSizeMD_[kernelName] =
696703
std::make_tuple(reqdWorkGroupElements[0], reqdWorkGroupElements[1],
697704
reqdWorkGroupElements[2]);

0 commit comments

Comments
 (0)