Skip to content

[SYCL][CUDA] Fix alignment of local arguments #5113

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 3 commits into from
Jan 10, 2022
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
17 changes: 16 additions & 1 deletion sycl/plugins/cuda/pi_cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,22 @@ struct _pi_kernel {

void add_local_arg(size_t index, size_t size) {
size_t localOffset = this->get_local_size();
add_arg(index, sizeof(size_t), (const void *)&(localOffset), size);

// maximum required alignment is the size of the largest vector type
const size_t max_alignment = sizeof(double) * 16;

// for arguments smaller than the maximum alignment simply align to the
// size of the argument
const size_t alignment = std::min(max_alignment, size);

// align the argument
size_t alignedLocalOffset = localOffset;
if (localOffset % alignment != 0) {
alignedLocalOffset += alignment - (localOffset % alignment);
}

add_arg(index, sizeof(size_t), (const void *)&(alignedLocalOffset),
size + (alignedLocalOffset - localOffset));
}

void set_implicit_offset(size_t size, std::uint32_t *implicitOffset) {
Expand Down