Skip to content

Commit 8cfcdb2

Browse files
[SYCL] Fix excessive memory allocation for devices in the OpenCL plugin (#2954)
The plugin used to allocate memory for the number of devices equal to the combined size of returned devices rather than their number.
1 parent 9fe0bd6 commit 8cfcdb2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ static pi_result getExtFuncFromContext(pi_context context, T *fptr) {
8181
return PI_SUCCESS;
8282
}
8383

84-
size_t deviceCount;
85-
cl_int ret_err = clGetContextInfo(
86-
cast<cl_context>(context), CL_CONTEXT_DEVICES, 0, nullptr, &deviceCount);
84+
cl_uint deviceCount;
85+
cl_int ret_err =
86+
clGetContextInfo(cast<cl_context>(context), CL_CONTEXT_NUM_DEVICES,
87+
sizeof(cl_uint), &deviceCount, nullptr);
8788

8889
if (ret_err != CL_SUCCESS || deviceCount < 1) {
8990
return PI_INVALID_CONTEXT;
@@ -354,11 +355,10 @@ pi_result piextQueueCreateWithNativeHandle(pi_native_handle nativeHandle,
354355

355356
pi_result piProgramCreate(pi_context context, const void *il, size_t length,
356357
pi_program *res_program) {
357-
358-
size_t deviceCount;
359-
360-
cl_int ret_err = clGetContextInfo(
361-
cast<cl_context>(context), CL_CONTEXT_DEVICES, 0, nullptr, &deviceCount);
358+
cl_uint deviceCount;
359+
cl_int ret_err =
360+
clGetContextInfo(cast<cl_context>(context), CL_CONTEXT_NUM_DEVICES,
361+
sizeof(cl_uint), &deviceCount, nullptr);
362362

363363
std::vector<cl_device_id> devicesInCtx(deviceCount);
364364

0 commit comments

Comments
 (0)