Skip to content

Commit be1d2b2

Browse files
[SYCL] Switch to using blocking free on non-GPU OpenCL devices (#6310)
Due to a bug in OpenCL runtime the initial switch to blocking free was limited to GPU. Now that the bug is addressed, this patch removes this workaround.
1 parent c4f326a commit be1d2b2

File tree

1 file changed

+4
-47
lines changed

1 file changed

+4
-47
lines changed

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ template <class To, class From> To cast(From value) {
5656
CONSTFIX char clHostMemAllocName[] = "clHostMemAllocINTEL";
5757
CONSTFIX char clDeviceMemAllocName[] = "clDeviceMemAllocINTEL";
5858
CONSTFIX char clSharedMemAllocName[] = "clSharedMemAllocINTEL";
59-
CONSTFIX char clMemFreeName[] = "clMemFreeINTEL";
6059
CONSTFIX char clMemBlockingFreeName[] = "clMemBlockingFreeINTEL";
6160
CONSTFIX char clCreateBufferWithPropertiesName[] =
6261
"clCreateBufferWithPropertiesINTEL";
@@ -1017,7 +1016,7 @@ pi_result piextUSMSharedAlloc(void **result_ptr, pi_context context,
10171016
return RetVal;
10181017
}
10191018

1020-
/// Frees allocated USM memory
1019+
/// Frees allocated USM memory in a blocking manner
10211020
///
10221021
/// \param context is the pi_context of the allocation
10231022
/// \param ptr is the memory to be freed
@@ -1026,52 +1025,10 @@ pi_result piextUSMFree(pi_context context, void *ptr) {
10261025
// might be still running.
10271026
clMemBlockingFreeINTEL_fn FuncPtr = nullptr;
10281027

1029-
// We need to use clMemBlockingFreeINTEL here, however, due to a bug in OpenCL
1030-
// CPU runtime this call fails with CL_INVALID_EVENT on CPU devices in certain
1031-
// cases. As a temporary workaround, this function replicates caching of
1032-
// extension function pointers in getExtFuncFromContext, while choosing
1033-
// clMemBlockingFreeINTEL for GPU and clMemFreeINTEL for other device types.
1034-
// TODO remove this workaround when the new OpenCL CPU runtime version is
1035-
// uplifted in CI.
1036-
static_assert(
1037-
std::is_same<clMemBlockingFreeINTEL_fn, clMemFreeINTEL_fn>::value);
1038-
cl_uint deviceCount;
1039-
cl_int ret_err =
1040-
clGetContextInfo(cast<cl_context>(context), CL_CONTEXT_NUM_DEVICES,
1041-
sizeof(cl_uint), &deviceCount, nullptr);
1042-
1043-
if (ret_err != CL_SUCCESS || deviceCount < 1) {
1044-
return PI_ERROR_INVALID_CONTEXT;
1045-
}
1046-
1047-
std::vector<cl_device_id> devicesInCtx(deviceCount);
1048-
ret_err = clGetContextInfo(cast<cl_context>(context), CL_CONTEXT_DEVICES,
1049-
deviceCount * sizeof(cl_device_id),
1050-
devicesInCtx.data(), nullptr);
1051-
1052-
if (ret_err != CL_SUCCESS) {
1053-
return PI_ERROR_INVALID_CONTEXT;
1054-
}
1055-
1056-
bool useBlockingFree = true;
1057-
for (const cl_device_id &dev : devicesInCtx) {
1058-
cl_device_type devType = CL_DEVICE_TYPE_DEFAULT;
1059-
ret_err = clGetDeviceInfo(dev, CL_DEVICE_TYPE, sizeof(cl_device_type),
1060-
&devType, nullptr);
1061-
if (ret_err != CL_SUCCESS) {
1062-
return PI_ERROR_INVALID_DEVICE;
1063-
}
1064-
useBlockingFree &= devType == CL_DEVICE_TYPE_GPU;
1065-
}
1066-
10671028
pi_result RetVal = PI_ERROR_INVALID_OPERATION;
1068-
if (useBlockingFree)
1069-
RetVal =
1070-
getExtFuncFromContext<clMemBlockingFreeName, clMemBlockingFreeINTEL_fn>(
1071-
context, &FuncPtr);
1072-
else
1073-
RetVal = getExtFuncFromContext<clMemFreeName, clMemFreeINTEL_fn>(context,
1074-
&FuncPtr);
1029+
RetVal =
1030+
getExtFuncFromContext<clMemBlockingFreeName, clMemBlockingFreeINTEL_fn>(
1031+
context, &FuncPtr);
10751032

10761033
if (FuncPtr) {
10771034
RetVal = cast<pi_result>(FuncPtr(cast<cl_context>(context), ptr));

0 commit comments

Comments
 (0)