Skip to content

[SYCL][CUDA][NFC] Check alignment of USM allocations #2831

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 4 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4164,6 +4164,9 @@ pi_result cuda_piextUSMHostAlloc(void **result_ptr, pi_context context,
result = error;
}

assert(alignment == 0 ||
(result == PI_SUCCESS &&
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
return result;
}

Expand All @@ -4185,6 +4188,9 @@ pi_result cuda_piextUSMDeviceAlloc(void **result_ptr, pi_context context,
result = error;
}

assert(alignment == 0 ||
(result == PI_SUCCESS &&
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
return result;
}

Expand All @@ -4207,6 +4213,9 @@ pi_result cuda_piextUSMSharedAlloc(void **result_ptr, pi_context context,
result = error;
}

assert(alignment == 0 ||
(result == PI_SUCCESS &&
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
return result;
}

Expand Down
6 changes: 6 additions & 0 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4674,6 +4674,8 @@ pi_result piextUSMHostAlloc(void **ResultPtr, pi_context Context,
ZE_CALL(
zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, Alignment, ResultPtr));

assert(Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0);
return PI_SUCCESS;
}

Expand All @@ -4700,6 +4702,8 @@ pi_result USMDeviceAllocImpl(void **ResultPtr, pi_context Context,
ZE_CALL(zeMemAllocDevice(Context->ZeContext, &ZeDesc, Size, Alignment,
Device->ZeDevice, ResultPtr));

assert(Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0);
return PI_SUCCESS;
}

Expand All @@ -4721,6 +4725,8 @@ pi_result USMSharedAllocImpl(void **ResultPtr, pi_context Context,
ZE_CALL(zeMemAllocShared(Context->ZeContext, &ZeDevDesc, &ZeHostDesc, Size,
Alignment, Device->ZeDevice, ResultPtr));

assert(Alignment == 0 ||
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0);
return PI_SUCCESS;
}

Expand Down
9 changes: 9 additions & 0 deletions sycl/plugins/opencl/pi_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ pi_result piextUSMHostAlloc(void **result_ptr, pi_context context,

*result_ptr = Ptr;

assert(alignment == 0 ||
(RetVal == PI_SUCCESS &&
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
return RetVal;
}

Expand Down Expand Up @@ -746,6 +749,9 @@ pi_result piextUSMDeviceAlloc(void **result_ptr, pi_context context,

*result_ptr = Ptr;

assert(alignment == 0 ||
(RetVal == PI_SUCCESS &&
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
return RetVal;
}

Expand Down Expand Up @@ -779,6 +785,9 @@ pi_result piextUSMSharedAlloc(void **result_ptr, pi_context context,

*result_ptr = Ptr;

assert(alignment == 0 ||
(RetVal == PI_SUCCESS &&
reinterpret_cast<std::uintptr_t>(*result_ptr) % alignment == 0));
return RetVal;
}

Expand Down