Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_NUM_DEVICES:
case UR_CONTEXT_INFO_DEVICES:
case UR_CONTEXT_INFO_REFERENCE_COUNT: {

CL_RETURN_ON_FAILURE(
size_t CheckPropSize = 0;
auto ClResult =
clGetContextInfo(cl_adapter::cast<cl_context>(hContext), CLPropName,
propSize, pPropValue, pPropSizeRet));
propSize, pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
CL_RETURN_ON_FAILURE(ClResult);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
}
return UR_RESULT_SUCCESS;
}
default:
Expand Down
36 changes: 31 additions & 5 deletions source/adapters/opencl/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,

return ReturnValue(URDeviceType);
}
case UR_DEVICE_INFO_DEVICE_ID: {
bool Supported = false;
CL_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
cl_adapter::cast<cl_device_id>(hDevice), {"cl_khr_pci_bus_info"},
Supported));

if (!Supported) {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}

cl_device_pci_bus_info_khr PciInfo = {};
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_PCI_BUS_INFO_KHR,
sizeof(PciInfo), &PciInfo, nullptr));
return ReturnValue(PciInfo.pci_device);
}

case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION: {
oclv::OpenCLVersion Version;
CL_RETURN_ON_FAILURE(cl_adapter::getDeviceVersion(
Expand Down Expand Up @@ -760,6 +777,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,

return ReturnValue(Supported);
}
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT: {
return ReturnValue(false);
}
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
bool Supported = false;
CL_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
cl_adapter::cast<cl_device_id>(hDevice),
{"cl_intel_program_scope_host_pipe"}, Supported));
return ReturnValue(Supported);
}
case UR_DEVICE_INFO_QUEUE_PROPERTIES:
case UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES:
case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES:
Expand All @@ -775,7 +802,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
/* CL type: cl_bitfield / enum
* UR type: ur_flags_t (uint32_t) */

cl_bitfield CLValue;
cl_bitfield CLValue = 0;
CL_RETURN_ON_FAILURE(
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CLPropName,
sizeof(cl_bitfield), &CLValue, nullptr));
Expand Down Expand Up @@ -898,13 +925,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
* sycl/doc/extensions/supported/sycl_ext_intel_device_info.md */
case UR_DEVICE_INFO_UUID:
/* This enums have no equivalent in OpenCL */
case UR_DEVICE_INFO_DEVICE_ID:
case UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP:
case UR_DEVICE_INFO_GLOBAL_MEM_FREE:
case UR_DEVICE_INFO_MEMORY_CLOCK_RATE:
case UR_DEVICE_INFO_MEMORY_BUS_WIDTH:
case UR_DEVICE_INFO_ASYNC_BARRIER:
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
case UR_DEVICE_INFO_ASYNC_BARRIER: {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
default: {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
Expand Down
8 changes: 4 additions & 4 deletions source/adapters/opencl/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe(
return mapCLErrorToUR(CLErr);
}

clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr;
cl_ext::clEnqueueReadHostPipeINTEL_fn FuncPtr = nullptr;
ur_result_t RetVal =
cl_ext::getExtFuncFromContext<clEnqueueReadHostPipeINTEL_fn>(
cl_ext::getExtFuncFromContext<cl_ext::clEnqueueReadHostPipeINTEL_fn>(
CLContext, cl_ext::ExtFuncPtrCache->clEnqueueReadHostPipeINTELCache,
cl_ext::EnqueueReadHostPipeName, &FuncPtr);

Expand Down Expand Up @@ -382,9 +382,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe(
return mapCLErrorToUR(CLErr);
}

clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr;
cl_ext::clEnqueueWriteHostPipeINTEL_fn FuncPtr = nullptr;
ur_result_t RetVal =
cl_ext::getExtFuncFromContext<clEnqueueWriteHostPipeINTEL_fn>(
cl_ext::getExtFuncFromContext<cl_ext::clEnqueueWriteHostPipeINTEL_fn>(
CLContext, cl_ext::ExtFuncPtrCache->clEnqueueWriteHostPipeINTELCache,
cl_ext::EnqueueWriteHostPipeName, &FuncPtr);

Expand Down
96 changes: 82 additions & 14 deletions source/adapters/opencl/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,62 @@ convertURProfilingInfoToCL(const ur_profiling_info_t PropName) {
}
}

const ur_command_t
convertCLCommandTypeToUR(const cl_command_type &CommandType) {
/* Note: the following enums don't have a CL equivalent:
UR_COMMAND_USM_FILL_2D
UR_COMMAND_USM_MEMCPY_2D
UR_COMMAND_DEVICE_GLOBAL_VARIABLE_WRITE
UR_COMMAND_DEVICE_GLOBAL_VARIABLE_READ
UR_COMMAND_READ_HOST_PIPE
UR_COMMAND_WRITE_HOST_PIPE
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP
UR_COMMAND_INTEROP_SEMAPHORE_WAIT_EXP
UR_COMMAND_INTEROP_SEMAPHORE_SIGNAL_EXP */
switch (CommandType) {
case CL_COMMAND_NDRANGE_KERNEL:
return UR_COMMAND_KERNEL_LAUNCH;
case CL_COMMAND_MARKER:
// CL can't distinguish between UR_COMMAND_EVENTS_WAIT_WITH_BARRIER and
// UR_COMMAND_EVENTS_WAIT.
return UR_COMMAND_EVENTS_WAIT;
case CL_COMMAND_READ_BUFFER:
return UR_COMMAND_MEM_BUFFER_READ;
case CL_COMMAND_WRITE_BUFFER:
return UR_COMMAND_MEM_BUFFER_WRITE;
case CL_COMMAND_READ_BUFFER_RECT:
return UR_COMMAND_MEM_BUFFER_READ_RECT;
case CL_COMMAND_WRITE_BUFFER_RECT:
return UR_COMMAND_MEM_BUFFER_WRITE_RECT;
case CL_COMMAND_COPY_BUFFER:
return UR_COMMAND_MEM_BUFFER_COPY;
case CL_COMMAND_COPY_BUFFER_RECT:
return UR_COMMAND_MEM_BUFFER_COPY_RECT;
case CL_COMMAND_FILL_BUFFER:
return UR_COMMAND_MEM_BUFFER_FILL;
case CL_COMMAND_READ_IMAGE:
return UR_COMMAND_MEM_IMAGE_READ;
case CL_COMMAND_WRITE_IMAGE:
return UR_COMMAND_MEM_IMAGE_WRITE;
case CL_COMMAND_COPY_IMAGE:
return UR_COMMAND_MEM_IMAGE_COPY;
case CL_COMMAND_MAP_BUFFER:
return UR_COMMAND_MEM_BUFFER_MAP;
case CL_COMMAND_UNMAP_MEM_OBJECT:
return UR_COMMAND_MEM_UNMAP;
case CL_COMMAND_MEMFILL_INTEL:
return UR_COMMAND_USM_FILL;
case CL_COMMAND_MEMCPY_INTEL:
return UR_COMMAND_USM_MEMCPY;
case CL_COMMAND_MIGRATEMEM_INTEL:
return UR_COMMAND_USM_PREFETCH;
case CL_COMMAND_MEMADVISE_INTEL:
return UR_COMMAND_USM_ADVISE;
default:
return UR_COMMAND_FORCE_UINT32;
}
}

UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
ur_native_handle_t hNativeEvent,
[[maybe_unused]] ur_context_handle_t hContext,
Expand Down Expand Up @@ -90,24 +146,36 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
void *pPropValue,
size_t *pPropSizeRet) {
cl_event_info CLEventInfo = convertUREventInfoToCL(propName);

size_t CheckPropSize = 0;
cl_int RetErr =
clGetEventInfo(cl_adapter::cast<cl_event>(hEvent), CLEventInfo, propSize,
pPropValue, pPropSizeRet);
pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
CL_RETURN_ON_FAILURE(RetErr);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
}

if (RetErr == CL_SUCCESS &&
propName == UR_EVENT_INFO_COMMAND_EXECUTION_STATUS) {
/* If the CL_EVENT_COMMAND_EXECUTION_STATUS info value is CL_QUEUED, change
* it to CL_SUBMITTED. sycl::info::event::event_command_status has no
* equivalent to CL_QUEUED.
*
* FIXME UR Port: This should not be part of the UR adapter. Since PI_QUEUED
* exists, SYCL RT should be changed to handle this situation. In addition,
* SYCL RT is relying on PI_QUEUED status to make sure that the queues are
* flushed. */
const auto param_value_int = static_cast<ur_event_status_t *>(pPropValue);
if (*param_value_int == UR_EVENT_STATUS_QUEUED) {
*param_value_int = UR_EVENT_STATUS_SUBMITTED;
if (pPropValue) {
if (propName == UR_EVENT_INFO_COMMAND_TYPE) {
*reinterpret_cast<ur_command_t *>(pPropValue) = convertCLCommandTypeToUR(
*reinterpret_cast<cl_command_type *>(pPropValue));
} else if (propName == UR_EVENT_INFO_COMMAND_EXECUTION_STATUS) {
/* If the CL_EVENT_COMMAND_EXECUTION_STATUS info value is CL_QUEUED,
* change it to CL_SUBMITTED. sycl::info::event::event_command_status has
* no equivalent to CL_QUEUED.
*
* FIXME UR Port: This should not be part of the UR adapter. Since
* PI_QUEUED exists, SYCL RT should be changed to handle this situation.
* In addition, SYCL RT is relying on PI_QUEUED status to make sure that
* the queues are flushed. */
const auto param_value_int = static_cast<ur_event_status_t *>(pPropValue);
if (*param_value_int == UR_EVENT_STATUS_QUEUED) {
*param_value_int = UR_EVENT_STATUS_SUBMITTED;
}
}
}

Expand Down
50 changes: 44 additions & 6 deletions source/adapters/opencl/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,34 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
size_t propSize,
void *pPropValue,
size_t *pPropSizeRet) {

CL_RETURN_ON_FAILURE(clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
mapURKernelInfoToCL(propName), propSize,
pPropValue, pPropSizeRet));
// We need this little bit of ugliness because the UR NUM_ARGS property is
// size_t whereas the CL one is cl_uint. We should consider changing that see
// #1038
if (propName == UR_KERNEL_INFO_NUM_ARGS) {
if (pPropSizeRet)
*pPropSizeRet = sizeof(size_t);
cl_uint NumArgs = 0;
CL_RETURN_ON_FAILURE(clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
mapURKernelInfoToCL(propName),
sizeof(NumArgs), &NumArgs, nullptr));
if (pPropValue) {
if (propSize != sizeof(size_t))
return UR_RESULT_ERROR_INVALID_SIZE;
*static_cast<size_t *>(pPropValue) = static_cast<size_t>(NumArgs);
}
} else {
size_t CheckPropSize = 0;
cl_int ClResult = clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
mapURKernelInfoToCL(propName), propSize,
pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
CL_RETURN_ON_FAILURE(ClResult);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
}
}

return UR_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -101,7 +125,20 @@ UR_APIEXPORT ur_result_t UR_APICALL
urKernelGetGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
ur_kernel_group_info_t propName, size_t propSize,
void *pPropValue, size_t *pPropSizeRet) {

// From the CL spec for GROUP_INFO_GLOBAL: "If device is not a custom device
// and kernel is not a built-in kernel, clGetKernelWorkGroupInfo returns the
// error CL_INVALID_VALUE.". Unfortunately there doesn't seem to be a nice
// way to query whether a kernel is a builtin kernel but this should suffice
// to deter naive use of the query.
if (propName == UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE) {
cl_device_type ClDeviceType;
CL_RETURN_ON_FAILURE(
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_TYPE,
sizeof(ClDeviceType), &ClDeviceType, nullptr));
if (ClDeviceType != CL_DEVICE_TYPE_CUSTOM) {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
}
CL_RETURN_ON_FAILURE(clGetKernelWorkGroupInfo(
cl_adapter::cast<cl_kernel>(hKernel),
cl_adapter::cast<cl_device_id>(hDevice),
Expand Down Expand Up @@ -199,7 +236,8 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
}
}

*(static_cast<uint32_t *>(pPropValue)) = static_cast<uint32_t>(RetVal);
if (pPropValue)
*(static_cast<uint32_t *>(pPropValue)) = static_cast<uint32_t>(RetVal);
if (pPropSizeRet)
*pPropSizeRet = sizeof(uint32_t);

Expand Down
30 changes: 23 additions & 7 deletions source/adapters/opencl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate(
}
}

void *HostPtr = pProperties ? pProperties->pHost : nullptr;
*phBuffer = reinterpret_cast<ur_mem_handle_t>(clCreateBuffer(
cl_adapter::cast<cl_context>(hContext), static_cast<cl_mem_flags>(flags),
size, pProperties->pHost, cl_adapter::cast<cl_int *>(&RetErr)));
size, HostPtr, cl_adapter::cast<cl_int *>(&RetErr)));
CL_RETURN_ON_FAILURE(RetErr);

return UR_RESULT_SUCCESS;
Expand Down Expand Up @@ -359,9 +360,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory,
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
const cl_int CLPropName = mapURMemInfoToCL(propName);

CL_RETURN_ON_FAILURE(clGetMemObjectInfo(cl_adapter::cast<cl_mem>(hMemory),
CLPropName, propSize, pPropValue,
pPropSizeRet));
size_t CheckPropSize = 0;
auto ClResult =
clGetMemObjectInfo(cl_adapter::cast<cl_mem>(hMemory), CLPropName,
propSize, pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
CL_RETURN_ON_FAILURE(ClResult);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
}
return UR_RESULT_SUCCESS;
}

Expand All @@ -374,9 +383,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
const cl_int CLPropName = mapURMemImageInfoToCL(propName);

CL_RETURN_ON_FAILURE(clGetImageInfo(cl_adapter::cast<cl_mem>(hMemory),
CLPropName, propSize, pPropValue,
pPropSizeRet));
size_t CheckPropSize = 0;
auto ClResult = clGetImageInfo(cl_adapter::cast<cl_mem>(hMemory), CLPropName,
propSize, pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
CL_RETURN_ON_FAILURE(ClResult);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
}
return UR_RESULT_SUCCESS;
}

Expand Down
Loading