Skip to content

Commit bb80c55

Browse files
[SYCL][L0][CUDA][HIP] Allow empty properties in backends (#6225)
Some PI functions take a zero-terminated list of properties, whereas nullptr is considered the same as an empty list. These changes make the L0, CUDA, and HIP backends accept both nullptr and a immediately terminated list as empty lists of properties. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 8c7bb45 commit bb80c55

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,8 @@ pi_result cuda_piMemBufferCreate(pi_context context, pi_mem_flags flags,
20422042
const pi_mem_properties *properties) {
20432043
// Need input memory object
20442044
assert(ret_mem != nullptr);
2045-
assert(properties == nullptr && "no mem properties goes to cuda RT yet");
2045+
assert((properties == nullptr || *properties == 0) &&
2046+
"no mem properties goes to cuda RT yet");
20462047
// Currently, USE_HOST_PTR is not implemented using host register
20472048
// since this triggers a weird segfault after program ends.
20482049
// Setting this constant to true enables testing that behavior.
@@ -4661,7 +4662,7 @@ pi_result cuda_piextUSMHostAlloc(void **result_ptr, pi_context context,
46614662
pi_uint32 alignment) {
46624663
assert(result_ptr != nullptr);
46634664
assert(context != nullptr);
4664-
assert(properties == nullptr);
4665+
assert(properties == nullptr || *properties == 0);
46654666
pi_result result = PI_SUCCESS;
46664667
try {
46674668
ScopedContext active(context);
@@ -4685,7 +4686,7 @@ pi_result cuda_piextUSMDeviceAlloc(void **result_ptr, pi_context context,
46854686
assert(result_ptr != nullptr);
46864687
assert(context != nullptr);
46874688
assert(device != nullptr);
4688-
assert(properties == nullptr);
4689+
assert(properties == nullptr || *properties == 0);
46894690
pi_result result = PI_SUCCESS;
46904691
try {
46914692
ScopedContext active(context);
@@ -4709,7 +4710,7 @@ pi_result cuda_piextUSMSharedAlloc(void **result_ptr, pi_context context,
47094710
assert(result_ptr != nullptr);
47104711
assert(context != nullptr);
47114712
assert(device != nullptr);
4712-
assert(properties == nullptr);
4713+
assert(properties == nullptr || *properties == 0);
47134714
pi_result result = PI_SUCCESS;
47144715
try {
47154716
ScopedContext active(context);

sycl/plugins/hip/pi_hip.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,8 @@ pi_result hip_piMemBufferCreate(pi_context context, pi_mem_flags flags,
19081908
const pi_mem_properties *properties) {
19091909
// Need input memory object
19101910
assert(ret_mem != nullptr);
1911-
assert(properties == nullptr && "no mem properties goes to HIP RT yet");
1911+
assert((properties == nullptr || *properties == 0) &&
1912+
"no mem properties goes to HIP RT yet");
19121913
// Currently, USE_HOST_PTR is not implemented using host register
19131914
// since this triggers a weird segfault after program ends.
19141915
// Setting this constant to true enables testing that behavior.
@@ -4568,7 +4569,7 @@ pi_result hip_piextUSMHostAlloc(void **result_ptr, pi_context context,
45684569
pi_uint32 alignment) {
45694570
assert(result_ptr != nullptr);
45704571
assert(context != nullptr);
4571-
assert(properties == nullptr);
4572+
assert(properties == nullptr || *properties == 0);
45724573
pi_result result = PI_SUCCESS;
45734574
try {
45744575
ScopedContext active(context);
@@ -4592,7 +4593,7 @@ pi_result hip_piextUSMDeviceAlloc(void **result_ptr, pi_context context,
45924593
assert(result_ptr != nullptr);
45934594
assert(context != nullptr);
45944595
assert(device != nullptr);
4595-
assert(properties == nullptr);
4596+
assert(properties == nullptr || *properties == 0);
45964597
pi_result result = PI_SUCCESS;
45974598
try {
45984599
ScopedContext active(context);
@@ -4616,7 +4617,7 @@ pi_result hip_piextUSMSharedAlloc(void **result_ptr, pi_context context,
46164617
assert(result_ptr != nullptr);
46174618
assert(context != nullptr);
46184619
assert(device != nullptr);
4619-
assert(properties == nullptr);
4620+
assert(properties == nullptr || *properties == 0);
46204621
pi_result result = PI_SUCCESS;
46214622
try {
46224623
ScopedContext active(context);

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7435,7 +7435,7 @@ pi_result piextUSMSharedAlloc(void **ResultPtr, pi_context Context,
74357435
// See if the memory is going to be read-only on the device.
74367436
bool DeviceReadOnly = false;
74377437
// Check that incorrect bits are not set in the properties.
7438-
if (Properties) {
7438+
if (Properties && *Properties != 0) {
74397439
PI_ASSERT(*(Properties) == PI_MEM_ALLOC_FLAGS && *(Properties + 2) == 0,
74407440
PI_INVALID_VALUE);
74417441
DeviceReadOnly = *(Properties + 1) & PI_MEM_ALLOC_DEVICE_READ_ONLY;

0 commit comments

Comments
 (0)