diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index ed51912da3491..75707db6aca1f 100755 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -30,9 +30,21 @@ template To cast(From value) { return (To)(value); } +// Names of USM functions that are queried from OpenCL +const char clHostMemAllocName[] = "clHostMemAllocINTEL"; +const char clDeviceMemAllocName[] = "clDeviceMemAllocINTEL"; +const char clSharedMemAllocName[] = "clSharedMemAllocINTEL"; +const char clMemFreeName[] = "clMemFreeINTEL"; +const char clSetKernelArgMemPointerName[] = "clSetKernelArgMemPointerINTEL"; +const char clEnqueueMemsetName[] = "clEnqueueMemsetINTEL"; +const char clEnqueueMemcpyName[] = "clEnqueueMemcpyINTEL"; +const char clEnqueueMigrateMemName[] = "clEnqueueMigrateMemINTEL"; +const char clEnqueueMemAdviseName[] = "clEnqueueMemAdviseINTEL"; +const char clGetMemAllocInfoName[] = "clGetMemAllocInfoINTEL"; + // USM helper function to get an extension function pointer -template -pi_result getExtFuncFromContext(pi_context context, const char *func, T *fptr) { +template +static pi_result getExtFuncFromContext(pi_context context, T *fptr) { // TODO // Potentially redo caching as PI interface changes. thread_local static std::map FuncPtrs; @@ -68,11 +80,11 @@ pi_result getExtFuncFromContext(pi_context context, const char *func, T *fptr) { return PI_INVALID_CONTEXT; } - T FuncPtr = (T) clGetExtensionFunctionAddressForPlatform(curPlatform, - func); - if (!FuncPtr) { + T FuncPtr = + (T)clGetExtensionFunctionAddressForPlatform(curPlatform, FuncName); + + if (!FuncPtr) return PI_INVALID_VALUE; - } *fptr = FuncPtr; FuncPtrs[context] = FuncPtr; @@ -98,24 +110,24 @@ static pi_result USMSetIndirectAccess(pi_kernel kernel) { return cast(CLErr); } - getExtFuncFromContext(cast(CLContext), - "clHostMemAllocINTEL", &HFunc); + getExtFuncFromContext( + cast(CLContext), &HFunc); if (HFunc) { clSetKernelExecInfo(cast(kernel), CL_KERNEL_EXEC_INFO_INDIRECT_HOST_ACCESS_INTEL, sizeof(cl_bool), &TrueVal); } - getExtFuncFromContext( - cast(CLContext), "clDeviceMemAllocINTEL", &DFunc); + getExtFuncFromContext( + cast(CLContext), &DFunc); if (DFunc) { clSetKernelExecInfo(cast(kernel), CL_KERNEL_EXEC_INFO_INDIRECT_DEVICE_ACCESS_INTEL, sizeof(cl_bool), &TrueVal); } - getExtFuncFromContext( - cast(CLContext), "clSharedMemAllocINTEL", &SFunc); + getExtFuncFromContext( + cast(CLContext), &SFunc); if (SFunc) { clSetKernelExecInfo(cast(kernel), CL_KERNEL_EXEC_INFO_INDIRECT_SHARED_ACCESS_INTEL, @@ -569,8 +581,8 @@ pi_result OCL(piextUSMHostAlloc)(void **result_ptr, pi_context context, // First we need to look up the function pointer clHostMemAllocINTEL_fn FuncPtr = nullptr; - RetVal = getExtFuncFromContext( - context, "clHostMemAllocINTEL", &FuncPtr); + RetVal = getExtFuncFromContext( + context, &FuncPtr); if (FuncPtr) { Ptr = FuncPtr(cast(context), @@ -601,8 +613,9 @@ pi_result OCL(piextUSMDeviceAlloc)(void **result_ptr, pi_context context, // First we need to look up the function pointer clDeviceMemAllocINTEL_fn FuncPtr = nullptr; - RetVal = getExtFuncFromContext( - context, "clDeviceMemAllocINTEL", &FuncPtr); + RetVal = + getExtFuncFromContext( + context, &FuncPtr); if (FuncPtr) { Ptr = FuncPtr(cast(context), cast(device), @@ -633,8 +646,9 @@ pi_result OCL(piextUSMSharedAlloc)(void **result_ptr, pi_context context, // First we need to look up the function pointer clSharedMemAllocINTEL_fn FuncPtr = nullptr; - RetVal = getExtFuncFromContext( - context, "clSharedMemAllocINTEL", &FuncPtr); + RetVal = + getExtFuncFromContext( + context, &FuncPtr); if (FuncPtr) { Ptr = FuncPtr(cast(context), cast(device), @@ -655,8 +669,8 @@ pi_result OCL(piextUSMFree)(pi_context context, void *ptr) { clMemFreeINTEL_fn FuncPtr = nullptr; pi_result RetVal = PI_INVALID_OPERATION; - RetVal = getExtFuncFromContext(context, "clMemFreeINTEL", - &FuncPtr); + RetVal = getExtFuncFromContext(context, + &FuncPtr); if (FuncPtr) { RetVal = cast(FuncPtr(cast(context), ptr)); @@ -687,8 +701,9 @@ pi_result OCL(piextKernelSetArgPointer)(pi_kernel kernel, pi_uint32 arg_index, } clSetKernelArgMemPointerINTEL_fn FuncPtr = nullptr; - pi_result RetVal = getExtFuncFromContext( - cast(CLContext), "clSetKernelArgMemPointerINTEL", &FuncPtr); + pi_result RetVal = getExtFuncFromContext( + cast(CLContext), &FuncPtr); if (FuncPtr) { // OpenCL passes pointers by value not by reference @@ -727,8 +742,9 @@ pi_result OCL(piextUSMEnqueueMemset)(pi_queue queue, void *ptr, pi_int32 value, } clEnqueueMemsetINTEL_fn FuncPtr = nullptr; - pi_result RetVal = getExtFuncFromContext( - cast(CLContext), "clEnqueueMemsetINTEL", &FuncPtr); + pi_result RetVal = + getExtFuncFromContext( + cast(CLContext), &FuncPtr); if (FuncPtr) { RetVal = cast(FuncPtr(cast(queue), ptr, value, @@ -767,8 +783,9 @@ pi_result OCL(piextUSMEnqueueMemcpy)(pi_queue queue, pi_bool blocking, } clEnqueueMemcpyINTEL_fn FuncPtr = nullptr; - pi_result RetVal = getExtFuncFromContext( - cast(CLContext), "clEnqueueMemcpyINTEL", &FuncPtr); + pi_result RetVal = + getExtFuncFromContext( + cast(CLContext), &FuncPtr); if (FuncPtr) { RetVal = cast( @@ -893,8 +910,9 @@ pi_result OCL(piextUSMGetMemAllocInfo)(pi_context context, const void *ptr, size_t *param_value_size_ret) { clGetMemAllocInfoINTEL_fn FuncPtr = nullptr; - pi_result RetVal = getExtFuncFromContext( - context, "clGetMemAllocInfoINTEL", &FuncPtr); + pi_result RetVal = + getExtFuncFromContext( + context, &FuncPtr); if (FuncPtr) { RetVal = cast(FuncPtr(cast(context), ptr, param_name,