Skip to content

[SYCL][CUDA] Remove size checks from USM allocations #10034

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 2 commits into from
Jun 28, 2023
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
55 changes: 15 additions & 40 deletions sycl/plugins/unified_runtime/ur/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
[[maybe_unused]] ur_usm_pool_handle_t pool, size_t size, void **ppMem) {
UR_ASSERT(ppMem, UR_RESULT_ERROR_INVALID_NULL_POINTER);
UR_ASSERT(hContext, UR_RESULT_ERROR_INVALID_NULL_HANDLE);

size_t DeviceMaxMemAllocSize = 0;
UR_ASSERT(urDeviceGetInfo(hContext->getDevice(),
UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE, sizeof(size_t),
static_cast<void *>(&DeviceMaxMemAllocSize),
nullptr) == UR_RESULT_SUCCESS,
UR_RESULT_ERROR_INVALID_DEVICE);
UR_ASSERT(size > 0 && size <= DeviceMaxMemAllocSize,
UR_RESULT_ERROR_INVALID_USM_SIZE);
UR_ASSERT(!pUSMDesc || (pUSMDesc->align == 0 ||
((pUSMDesc->align & (pUSMDesc->align - 1)) == 0)),
UR_RESULT_ERROR_INVALID_VALUE);

ur_result_t Result = UR_RESULT_SUCCESS;
try {
Expand All @@ -42,13 +36,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
Result = Err;
}

UR_ASSERT(!pUSMDesc || (pUSMDesc->align == 0 ||
((pUSMDesc->align & (pUSMDesc->align - 1)) == 0)),
UR_RESULT_ERROR_INVALID_VALUE);

assert(Result == UR_RESULT_SUCCESS &&
(!pUSMDesc || pUSMDesc->align == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % pUSMDesc->align == 0));
if (Result == UR_RESULT_SUCCESS) {
assert((!pUSMDesc || pUSMDesc->align == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % pUSMDesc->align == 0));
}

return Result;
}
Expand All @@ -66,15 +57,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
((pUSMDesc->align & (pUSMDesc->align - 1)) == 0)),
UR_RESULT_ERROR_INVALID_VALUE);

size_t DeviceMaxMemAllocSize = 0;
UR_ASSERT(urDeviceGetInfo(hDevice, UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE,
sizeof(size_t),
static_cast<void *>(&DeviceMaxMemAllocSize),
nullptr) == UR_RESULT_SUCCESS,
UR_RESULT_ERROR_INVALID_DEVICE);
UR_ASSERT(size > 0 && size <= DeviceMaxMemAllocSize,
UR_RESULT_ERROR_INVALID_USM_SIZE);

ur_result_t Result = UR_RESULT_SUCCESS;
try {
ScopedContext Active(hContext);
Expand All @@ -83,9 +65,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
return Err;
}

assert(Result == UR_RESULT_SUCCESS &&
(!pUSMDesc || pUSMDesc->align == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % pUSMDesc->align == 0));
if (Result == UR_RESULT_SUCCESS) {
assert((!pUSMDesc || pUSMDesc->align == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % pUSMDesc->align == 0));
}

return Result;
}
Expand All @@ -103,15 +86,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
((pUSMDesc->align & (pUSMDesc->align - 1)) == 0)),
UR_RESULT_ERROR_INVALID_VALUE);

size_t DeviceMaxMemAllocSize = 0;
UR_ASSERT(urDeviceGetInfo(hDevice, UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE,
sizeof(size_t),
static_cast<void *>(&DeviceMaxMemAllocSize),
nullptr) == UR_RESULT_SUCCESS,
UR_RESULT_ERROR_INVALID_DEVICE);
UR_ASSERT(size > 0 && size <= DeviceMaxMemAllocSize,
UR_RESULT_ERROR_INVALID_USM_SIZE);

ur_result_t Result = UR_RESULT_SUCCESS;
try {
ScopedContext Active(hContext);
Expand All @@ -121,9 +95,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
return Err;
}

assert(Result == UR_RESULT_SUCCESS &&
(!pUSMDesc || pUSMDesc->align == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % pUSMDesc->align == 0));
if (Result == UR_RESULT_SUCCESS) {
assert((!pUSMDesc || pUSMDesc->align == 0 ||
reinterpret_cast<std::uintptr_t>(*ppMem) % pUSMDesc->align == 0));
}

return Result;
}
Expand Down