Skip to content

Commit 0f261e5

Browse files
committed
Fix issue with pointer being passed to API without any underlying memory and fix char to unsigned char conversion issue
1 parent b9bfd6c commit 0f261e5

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

sycl/test-e2e/Adapters/luid-cuda.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ int main() {
2727

2828
CUdevice cudaDevice = sycl::get_native<sycl::backend::ext_oneapi_cuda>(dev);
2929

30-
char *luidCuda = nullptr;
30+
std::array<char, 8> luidCuda{};
3131

32-
cuDeviceGetLuid(luidCuda, nullptr, cudaDevice);
32+
cuDeviceGetLuid(luidCuda.data(), nullptr, cudaDevice);
33+
34+
// Cuda returns luid as char, not unsigned char so convert that here.
35+
std::array<unsigned char, 8> luidCudaConverted{};
36+
std::copy(luidCuda.begin(), luidCuda.end(), luidCudaConverted.begin());
3337

3438
std::stringstream luidCudaHex;
3539
for (int i = 0; i < 8; ++i)
3640
luidCudaHex << std::hex << std::setw(2) << std::setfill('0')
37-
<< int(luidCuda[i]);
41+
<< int(luidCudaConverted[i]);
3842
std::cout << "CUDA : " << luidCudaHex.str() << std::endl;
3943

4044
if (luidSYCLHex.str() != luidCudaHex.str()) {

sycl/test-e2e/Adapters/luid-opencl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ int main() {
2525

2626
auto openclDevice = sycl::get_native<sycl::backend::opencl>(dev);
2727

28-
char *luidOpencl = nullptr;
28+
std::array<unsigned char, CL_LUID_SIZE_KHR> luidOpencl{};
2929

3030
clGetDeviceInfo(openclDevice, CL_DEVICE_LUID_KHR,
31-
sizeof(char) * CL_LUID_SIZE_KHR, luidOpencl, nullptr);
31+
sizeof(char) * CL_LUID_SIZE_KHR, luidOpencl.data(), nullptr);
3232

3333
std::stringstream luidOpenclHex;
3434
for (int i = 0; i < 8; ++i)

sycl/test-e2e/Adapters/node_mask-cuda.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616

1717
int main() {
1818
sycl::device dev;
19-
auto nodeMaskSYCL = dev.get_info<sycl::ext::intel::info::device::node_mask>();
19+
uint32_t nodeMaskSYCL =
20+
dev.get_info<sycl::ext::intel::info::device::node_mask>();
2021

2122
std::cout << "SYCL: " << nodeMaskSYCL << std::endl;
2223

2324
CUdevice cudaDevice = sycl::get_native<sycl::backend::ext_oneapi_cuda>(dev);
2425

25-
uint32_t *nodeMaskCuda = nullptr;
26+
uint32_t nodeMaskCuda = 0;
2627

27-
cuDeviceGetLuid(nullptr, nodeMaskCuda, cudaDevice);
28+
cuDeviceGetLuid(nullptr, &nodeMaskCuda, cudaDevice);
2829

29-
std::cout << "CUDA : " << *nodeMaskCuda << std::endl;
30+
std::cout << "CUDA : " << nodeMaskCuda << std::endl;
3031

31-
if (nodeMaskSYCL != *nodeMaskCuda) {
32+
if (nodeMaskSYCL != nodeMaskCuda) {
3233
std::cout << "FAILED" << std::endl;
3334
return -1;
3435
}

sycl/test-e2e/Adapters/node_mask-opencl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ int main() {
2020

2121
auto openclDevice = sycl::get_native<sycl::backend::opencl>(dev);
2222

23-
uint32_t *nodeMaskOpencl = nullptr;
23+
uint32_t nodeMaskOpencl = 0;
2424

2525
clGetDeviceInfo(openclDevice, CL_DEVICE_NODE_MASK_KHR, sizeof(uint32_t),
26-
nodeMaskOpencl, nullptr);
26+
&nodeMaskOpencl, nullptr);
2727

28-
std::cout << "OpenCL : " << *nodeMaskOpencl << std::endl;
28+
std::cout << "OpenCL : " << nodeMaskOpencl << std::endl;
2929

30-
if (nodeMaskSYCL != *nodeMaskOpencl) {
30+
if (nodeMaskSYCL != nodeMaskOpencl) {
3131
std::cout << "FAILED" << std::endl;
3232
return -1;
3333
}

unified-runtime/source/adapters/cuda/device.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,31 +1191,38 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11911191
// Intel extension for device LUID. This returns the LUID as
11921192
// std::array<std::byte, 8>. For details about this extension,
11931193
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1194-
char *LUID = nullptr;
1195-
cuDeviceGetLuid(LUID, nullptr, hDevice->get());
1194+
std::array<char, 8> LUID{};
1195+
cuDeviceGetLuid(LUID.data(), nullptr, hDevice->get());
11961196

1197-
std::array<unsigned char, 8> Name = {};
1197+
bool isAllZeros = true;
1198+
for (char num : LUID) {
1199+
if (num != 0) {
1200+
isAllZeros = false;
1201+
}
1202+
}
11981203

1199-
if (LUID == nullptr) {
1204+
if (isAllZeros) {
12001205
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
12011206
}
12021207

1203-
std::copy(LUID, LUID + 8, Name.begin());
1208+
std::array<unsigned char, 8> Name{};
1209+
std::copy(LUID.begin(), LUID.end(), Name.begin());
12041210
return ReturnValue(Name.data(), 8);
12051211
}
12061212
case UR_DEVICE_INFO_NODE_MASK: {
12071213
// Device node mask is only available on Windows.
12081214
// Intel extension for device node mask. This returns the node mask as
12091215
// uint32_t. For details about this extension,
12101216
// see sycl/doc/extensions/supported/sycl_ext_intel_device_info.md.
1211-
uint32_t *nodeMask = nullptr;
1212-
cuDeviceGetLuid(nullptr, nodeMask, hDevice->get());
1217+
uint32_t nodeMask = 0;
1218+
cuDeviceGetLuid(nullptr, &nodeMask, hDevice->get());
12131219

1214-
if (nodeMask == nullptr) {
1220+
// If nodeMask has not changed, return unsupported.
1221+
if (nodeMask == 0) {
12151222
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
12161223
}
12171224

1218-
return ReturnValue(*nodeMask);
1225+
return ReturnValue(nodeMask);
12191226
}
12201227
default:
12211228
break;

unified-runtime/source/adapters/opencl/device.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,17 +1463,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
14631463
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
14641464
}
14651465

1466-
cl_int *nodeMask = nullptr;
1466+
cl_int nodeMask = 0;
14671467

14681468
CL_RETURN_ON_FAILURE(clGetDeviceInfo(hDevice->CLDevice,
14691469
CL_DEVICE_NODE_MASK_KHR,
1470-
sizeof(cl_int), nodeMask, nullptr));
1470+
sizeof(cl_int), &nodeMask, nullptr));
14711471

1472-
if (nodeMask == nullptr) {
1473-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1474-
}
1475-
1476-
return ReturnValue(*nodeMask);
1472+
return ReturnValue(nodeMask);
14771473
}
14781474
// TODO: We can't query to check if these are supported, they will need to be
14791475
// manually updated if support is ever implemented.

0 commit comments

Comments
 (0)