Skip to content
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] Extended usm fill to bigger patterns than 1 byte #1489

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions source/adapters/native_cpu/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,41 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
UR_ASSERT(size % patternSize == 0 || patternSize > size,
UR_RESULT_ERROR_INVALID_SIZE);

memset(ptr, *static_cast<const uint8_t *>(pPattern), size * patternSize);

switch (patternSize) {
case 1:
memset(ptr, *static_cast<const uint8_t *>(pPattern), size * patternSize);
break;
case 2: {
const auto pattern = *static_cast<const uint16_t *>(pPattern);
auto *start = reinterpret_cast<uint16_t *>(ptr);
auto *end =
reinterpret_cast<uint16_t *>(reinterpret_cast<uint16_t *>(ptr) + size);
std::fill(start, end, pattern);
break;
}
case 4: {
const auto pattern = *static_cast<const uint32_t *>(pPattern);
auto *start = reinterpret_cast<uint32_t *>(ptr);
auto *end =
reinterpret_cast<uint32_t *>(reinterpret_cast<uint32_t *>(ptr) + size);
std::fill(start, end, pattern);
break;
}
case 8: {
const auto pattern = *static_cast<const uint64_t *>(pPattern);
auto *start = reinterpret_cast<uint64_t *>(ptr);
auto *end =
reinterpret_cast<uint64_t *>(reinterpret_cast<uint64_t *>(ptr) + size);
std::fill(start, end, pattern);
break;
}
default:
for (unsigned int step{0}; step < size; ++step) {
auto *dest = reinterpret_cast<void *>(reinterpret_cast<uint8_t *>(ptr) +
step * patternSize);
memcpy(dest, pPattern, patternSize);
}
}
return UR_RESULT_SUCCESS;
}

Expand Down