Skip to content

Commit e240c6e

Browse files
authored
[UR][OpenCL] Fix handling of urPlatformGet where there are no platforms (#18076)
The logic here was incorrect in cases where no platforms are available (and thus `clGetPlatformIDs` returns `CL_PLATFORM_NOT_FOUND_KHR`).
1 parent e6410a7 commit e240c6e

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,19 @@ urPlatformGet(ur_adapter_handle_t, uint32_t NumEntries,
8282
uint32_t NumPlatforms = 0;
8383
cl_int Res = clGetPlatformIDs(0, nullptr, &NumPlatforms);
8484

85-
std::vector<cl_platform_id> CLPlatforms(NumPlatforms);
86-
Res = clGetPlatformIDs(static_cast<cl_uint>(NumPlatforms),
87-
CLPlatforms.data(), nullptr);
88-
89-
/* Absorb the CL_PLATFORM_NOT_FOUND_KHR and just return 0 in num_platforms
90-
*/
91-
if (Res == CL_PLATFORM_NOT_FOUND_KHR) {
85+
if (NumPlatforms == 0 || Res == CL_PLATFORM_NOT_FOUND_KHR) {
9286
if (pNumPlatforms) {
9387
*pNumPlatforms = 0;
94-
return UR_RESULT_SUCCESS;
9588
}
96-
}
97-
/* INVALID_VALUE is returned when the size is invalid, special case it
98-
* here
99-
*/
100-
if (Res == CL_INVALID_VALUE && phPlatforms != nullptr &&
101-
NumEntries == 0) {
102-
return UR_RESULT_ERROR_INVALID_SIZE;
89+
return UR_RESULT_SUCCESS;
10390
}
10491
CL_RETURN_ON_FAILURE(Res);
92+
93+
std::vector<cl_platform_id> CLPlatforms(NumPlatforms);
94+
Res = clGetPlatformIDs(static_cast<cl_uint>(NumPlatforms),
95+
CLPlatforms.data(), nullptr);
96+
CL_RETURN_ON_FAILURE(Res);
97+
10598
try {
10699
for (uint32_t i = 0; i < NumPlatforms; i++) {
107100
auto URPlatform =

0 commit comments

Comments
 (0)