Skip to content

Commit 6a3c63d

Browse files
committed
[OpenCL] Return INVALID_SIZE from GetInfo entry points.
Also includes a few other GetInfo related fixes: * Add missing device info queries * Add mapping of CL command type to UR command type * Correct mapping of UR_QUEUE_INFO_FLAGS * Add mapping of cl_command_queue_properties to ur_queue_flags_t * Add mapping of cl_unified_shared_memory_type_intel to ur_usm_type_t * Add UNSUPPORTED_ENUMERATION path to KernelGeGroupInfo tests. And a fix related to one of the fixed queries: * Populate pfnReadHostPipe and pfnWriteHostPipe ddi table entries.
1 parent 5d88fc7 commit 6a3c63d

File tree

11 files changed

+318
-111
lines changed

11 files changed

+318
-111
lines changed

source/adapters/opencl/context.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,17 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
9393
case UR_CONTEXT_INFO_NUM_DEVICES:
9494
case UR_CONTEXT_INFO_DEVICES:
9595
case UR_CONTEXT_INFO_REFERENCE_COUNT: {
96-
97-
CL_RETURN_ON_FAILURE(
96+
size_t CheckPropSize = 0;
97+
auto ClResult =
9898
clGetContextInfo(cl_adapter::cast<cl_context>(hContext), CLPropName,
99-
propSize, pPropValue, pPropSizeRet));
99+
propSize, pPropValue, &CheckPropSize);
100+
if (pPropValue && CheckPropSize != propSize) {
101+
return UR_RESULT_ERROR_INVALID_SIZE;
102+
}
103+
CL_RETURN_ON_FAILURE(ClResult);
104+
if (pPropSizeRet) {
105+
*pPropSizeRet = CheckPropSize;
106+
}
100107
return UR_RESULT_SUCCESS;
101108
}
102109
default:

source/adapters/opencl/device.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
345345

346346
return ReturnValue(URDeviceType);
347347
}
348+
case UR_DEVICE_INFO_DEVICE_ID: {
349+
bool Supported = false;
350+
CL_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
351+
cl_adapter::cast<cl_device_id>(hDevice), {"cl_khr_pci_bus_info"},
352+
Supported));
353+
354+
if (!Supported) {
355+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
356+
}
357+
358+
cl_device_pci_bus_info_khr PciInfo = {};
359+
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
360+
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_PCI_BUS_INFO_KHR,
361+
sizeof(PciInfo), &PciInfo, nullptr));
362+
return ReturnValue(PciInfo.pci_device);
363+
}
364+
348365
case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION: {
349366
oclv::OpenCLVersion Version;
350367
CL_RETURN_ON_FAILURE(cl_adapter::getDeviceVersion(
@@ -760,6 +777,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
760777

761778
return ReturnValue(Supported);
762779
}
780+
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT: {
781+
return ReturnValue(false);
782+
}
783+
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
784+
bool Supported = false;
785+
CL_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
786+
cl_adapter::cast<cl_device_id>(hDevice),
787+
{"cl_intel_program_scope_host_pipe"}, Supported));
788+
return ReturnValue(Supported);
789+
}
763790
case UR_DEVICE_INFO_QUEUE_PROPERTIES:
764791
case UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES:
765792
case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES:
@@ -775,7 +802,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
775802
/* CL type: cl_bitfield / enum
776803
* UR type: ur_flags_t (uint32_t) */
777804

778-
cl_bitfield CLValue;
805+
cl_bitfield CLValue = 0;
779806
CL_RETURN_ON_FAILURE(
780807
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CLPropName,
781808
sizeof(cl_bitfield), &CLValue, nullptr));
@@ -898,13 +925,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
898925
* sycl/doc/extensions/supported/sycl_ext_intel_device_info.md */
899926
case UR_DEVICE_INFO_UUID:
900927
/* This enums have no equivalent in OpenCL */
901-
case UR_DEVICE_INFO_DEVICE_ID:
928+
case UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP:
902929
case UR_DEVICE_INFO_GLOBAL_MEM_FREE:
903930
case UR_DEVICE_INFO_MEMORY_CLOCK_RATE:
904931
case UR_DEVICE_INFO_MEMORY_BUS_WIDTH:
905-
case UR_DEVICE_INFO_ASYNC_BARRIER:
906-
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
907-
return UR_RESULT_ERROR_INVALID_ENUMERATION;
932+
case UR_DEVICE_INFO_ASYNC_BARRIER: {
933+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
908934
}
909935
default: {
910936
return UR_RESULT_ERROR_INVALID_ENUMERATION;

source/adapters/opencl/event.cpp

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,62 @@ convertURProfilingInfoToCL(const ur_profiling_info_t PropName) {
5454
}
5555
}
5656

57+
const ur_command_t
58+
convertCLCommandTypeToUR(const cl_command_type &CommandType) {
59+
/* Note: the following enums don't have a CL equivalent:
60+
UR_COMMAND_USM_FILL_2D
61+
UR_COMMAND_USM_MEMCPY_2D
62+
UR_COMMAND_DEVICE_GLOBAL_VARIABLE_WRITE
63+
UR_COMMAND_DEVICE_GLOBAL_VARIABLE_READ
64+
UR_COMMAND_READ_HOST_PIPE
65+
UR_COMMAND_WRITE_HOST_PIPE
66+
UR_COMMAND_COMMAND_BUFFER_ENQUEUE_EXP
67+
UR_COMMAND_INTEROP_SEMAPHORE_WAIT_EXP
68+
UR_COMMAND_INTEROP_SEMAPHORE_SIGNAL_EXP */
69+
switch (CommandType) {
70+
case CL_COMMAND_NDRANGE_KERNEL:
71+
return UR_COMMAND_KERNEL_LAUNCH;
72+
case CL_COMMAND_MARKER:
73+
// CL can't distinguish between UR_COMMAND_EVENTS_WAIT_WITH_BARRIER and
74+
// UR_COMMAND_EVENTS_WAIT.
75+
return UR_COMMAND_EVENTS_WAIT;
76+
case CL_COMMAND_READ_BUFFER:
77+
return UR_COMMAND_MEM_BUFFER_READ;
78+
case CL_COMMAND_WRITE_BUFFER:
79+
return UR_COMMAND_MEM_BUFFER_WRITE;
80+
case CL_COMMAND_READ_BUFFER_RECT:
81+
return UR_COMMAND_MEM_BUFFER_READ_RECT;
82+
case CL_COMMAND_WRITE_BUFFER_RECT:
83+
return UR_COMMAND_MEM_BUFFER_WRITE_RECT;
84+
case CL_COMMAND_COPY_BUFFER:
85+
return UR_COMMAND_MEM_BUFFER_COPY;
86+
case CL_COMMAND_COPY_BUFFER_RECT:
87+
return UR_COMMAND_MEM_BUFFER_COPY_RECT;
88+
case CL_COMMAND_FILL_BUFFER:
89+
return UR_COMMAND_MEM_BUFFER_FILL;
90+
case CL_COMMAND_READ_IMAGE:
91+
return UR_COMMAND_MEM_IMAGE_READ;
92+
case CL_COMMAND_WRITE_IMAGE:
93+
return UR_COMMAND_MEM_IMAGE_WRITE;
94+
case CL_COMMAND_COPY_IMAGE:
95+
return UR_COMMAND_MEM_IMAGE_COPY;
96+
case CL_COMMAND_MAP_BUFFER:
97+
return UR_COMMAND_MEM_BUFFER_MAP;
98+
case CL_COMMAND_UNMAP_MEM_OBJECT:
99+
return UR_COMMAND_MEM_UNMAP;
100+
case CL_COMMAND_MEMFILL_INTEL:
101+
return UR_COMMAND_USM_FILL;
102+
case CL_COMMAND_MEMCPY_INTEL:
103+
return UR_COMMAND_USM_MEMCPY;
104+
case CL_COMMAND_MIGRATEMEM_INTEL:
105+
return UR_COMMAND_USM_PREFETCH;
106+
case CL_COMMAND_MEMADVISE_INTEL:
107+
return UR_COMMAND_USM_ADVISE;
108+
default:
109+
return UR_COMMAND_FORCE_UINT32;
110+
}
111+
}
112+
57113
UR_APIEXPORT ur_result_t UR_APICALL
58114
urEventCreateWithNativeHandle(ur_native_handle_t hNativeEvent,
59115
[[maybe_unused]] ur_context_handle_t hContext,
@@ -97,24 +153,36 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
97153
void *pPropValue,
98154
size_t *pPropSizeRet) {
99155
cl_event_info CLEventInfo = convertUREventInfoToCL(propName);
156+
157+
size_t CheckPropSize = 0;
100158
cl_int RetErr =
101159
clGetEventInfo(cl_adapter::cast<cl_event>(hEvent), CLEventInfo, propSize,
102-
pPropValue, pPropSizeRet);
160+
pPropValue, &CheckPropSize);
161+
if (pPropValue && CheckPropSize != propSize) {
162+
return UR_RESULT_ERROR_INVALID_SIZE;
163+
}
103164
CL_RETURN_ON_FAILURE(RetErr);
165+
if (pPropSizeRet) {
166+
*pPropSizeRet = CheckPropSize;
167+
}
104168

105-
if (RetErr == CL_SUCCESS &&
106-
propName == UR_EVENT_INFO_COMMAND_EXECUTION_STATUS) {
107-
/* If the CL_EVENT_COMMAND_EXECUTION_STATUS info value is CL_QUEUED, change
108-
* it to CL_SUBMITTED. sycl::info::event::event_command_status has no
109-
* equivalent to CL_QUEUED.
110-
*
111-
* FIXME UR Port: This should not be part of the UR adapter. Since PI_QUEUED
112-
* exists, SYCL RT should be changed to handle this situation. In addition,
113-
* SYCL RT is relying on PI_QUEUED status to make sure that the queues are
114-
* flushed. */
115-
const auto param_value_int = static_cast<ur_event_status_t *>(pPropValue);
116-
if (*param_value_int == UR_EVENT_STATUS_QUEUED) {
117-
*param_value_int = UR_EVENT_STATUS_SUBMITTED;
169+
if (pPropValue) {
170+
if (propName == UR_EVENT_INFO_COMMAND_TYPE) {
171+
*reinterpret_cast<ur_command_t *>(pPropValue) = convertCLCommandTypeToUR(
172+
*reinterpret_cast<cl_command_type *>(pPropValue));
173+
} else if (propName == UR_EVENT_INFO_COMMAND_EXECUTION_STATUS) {
174+
/* If the CL_EVENT_COMMAND_EXECUTION_STATUS info value is CL_QUEUED,
175+
* change it to CL_SUBMITTED. sycl::info::event::event_command_status has
176+
* no equivalent to CL_QUEUED.
177+
*
178+
* FIXME UR Port: This should not be part of the UR adapter. Since
179+
* PI_QUEUED exists, SYCL RT should be changed to handle this situation.
180+
* In addition, SYCL RT is relying on PI_QUEUED status to make sure that
181+
* the queues are flushed. */
182+
const auto param_value_int = static_cast<ur_event_status_t *>(pPropValue);
183+
if (*param_value_int == UR_EVENT_STATUS_QUEUED) {
184+
*param_value_int = UR_EVENT_STATUS_SUBMITTED;
185+
}
118186
}
119187
}
120188

source/adapters/opencl/kernel.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,34 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
6969
size_t propSize,
7070
void *pPropValue,
7171
size_t *pPropSizeRet) {
72-
73-
CL_RETURN_ON_FAILURE(clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
74-
mapURKernelInfoToCL(propName), propSize,
75-
pPropValue, pPropSizeRet));
72+
// We need this little bit of ugliness because the UR NUM_ARGS property is
73+
// size_t whereas the CL one is cl_uint. We should consider changing that see
74+
// #1038
75+
if (propName == UR_KERNEL_INFO_NUM_ARGS) {
76+
if (pPropSizeRet)
77+
*pPropSizeRet = sizeof(size_t);
78+
cl_uint NumArgs = 0;
79+
CL_RETURN_ON_FAILURE(clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
80+
mapURKernelInfoToCL(propName),
81+
sizeof(NumArgs), &NumArgs, nullptr));
82+
if (pPropValue) {
83+
if (propSize != sizeof(size_t))
84+
return UR_RESULT_ERROR_INVALID_SIZE;
85+
*static_cast<size_t *>(pPropValue) = static_cast<size_t>(NumArgs);
86+
}
87+
} else {
88+
size_t CheckPropSize = 0;
89+
cl_int ClResult = clGetKernelInfo(cl_adapter::cast<cl_kernel>(hKernel),
90+
mapURKernelInfoToCL(propName), propSize,
91+
pPropValue, &CheckPropSize);
92+
if (pPropValue && CheckPropSize != propSize) {
93+
return UR_RESULT_ERROR_INVALID_SIZE;
94+
}
95+
CL_RETURN_ON_FAILURE(ClResult);
96+
if (pPropSizeRet) {
97+
*pPropSizeRet = CheckPropSize;
98+
}
99+
}
76100

77101
return UR_RESULT_SUCCESS;
78102
}
@@ -101,7 +125,20 @@ UR_APIEXPORT ur_result_t UR_APICALL
101125
urKernelGetGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
102126
ur_kernel_group_info_t propName, size_t propSize,
103127
void *pPropValue, size_t *pPropSizeRet) {
104-
128+
// From the CL spec for GROUP_INFO_GLOBAL: "If device is not a custom device
129+
// and kernel is not a built-in kernel, clGetKernelWorkGroupInfo returns the
130+
// error CL_INVALID_VALUE.". Unfortunately there doesn't seem to be a nice
131+
// way to query whether a kernel is a builtin kernel but this should suffice
132+
// to deter naive use of the query.
133+
if (propName == UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE) {
134+
cl_device_type ClDeviceType;
135+
CL_RETURN_ON_FAILURE(
136+
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_TYPE,
137+
sizeof(ClDeviceType), &ClDeviceType, nullptr));
138+
if (ClDeviceType != CL_DEVICE_TYPE_CUSTOM) {
139+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
140+
}
141+
}
105142
CL_RETURN_ON_FAILURE(clGetKernelWorkGroupInfo(
106143
cl_adapter::cast<cl_kernel>(hKernel),
107144
cl_adapter::cast<cl_device_id>(hDevice),

source/adapters/opencl/memory.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory,
362362
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
363363
const cl_int CLPropName = mapURMemInfoToCL(propName);
364364

365-
CL_RETURN_ON_FAILURE(clGetMemObjectInfo(cl_adapter::cast<cl_mem>(hMemory),
366-
CLPropName, propSize, pPropValue,
367-
pPropSizeRet));
365+
size_t CheckPropSize = 0;
366+
auto ClResult =
367+
clGetMemObjectInfo(cl_adapter::cast<cl_mem>(hMemory), CLPropName,
368+
propSize, pPropValue, &CheckPropSize);
369+
if (pPropValue && CheckPropSize != propSize) {
370+
return UR_RESULT_ERROR_INVALID_SIZE;
371+
}
372+
CL_RETURN_ON_FAILURE(ClResult);
373+
if (pPropSizeRet) {
374+
*pPropSizeRet = CheckPropSize;
375+
}
368376
return UR_RESULT_SUCCESS;
369377
}
370378

@@ -377,9 +385,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo(ur_mem_handle_t hMemory,
377385
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
378386
const cl_int CLPropName = mapURMemImageInfoToCL(propName);
379387

380-
CL_RETURN_ON_FAILURE(clGetImageInfo(cl_adapter::cast<cl_mem>(hMemory),
381-
CLPropName, propSize, pPropValue,
382-
pPropSizeRet));
388+
size_t CheckPropSize = 0;
389+
auto ClResult = clGetImageInfo(cl_adapter::cast<cl_mem>(hMemory), CLPropName,
390+
propSize, pPropValue, &CheckPropSize);
391+
if (pPropValue && CheckPropSize != propSize) {
392+
return UR_RESULT_ERROR_INVALID_SIZE;
393+
}
394+
CL_RETURN_ON_FAILURE(ClResult);
395+
if (pPropSizeRet) {
396+
*pPropSizeRet = CheckPropSize;
397+
}
383398
return UR_RESULT_SUCCESS;
384399
}
385400

source/adapters/opencl/program.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,17 @@ static cl_int mapURProgramInfoToCL(ur_program_info_t URPropName) {
176176
UR_APIEXPORT ur_result_t UR_APICALL
177177
urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName,
178178
size_t propSize, void *pPropValue, size_t *pPropSizeRet) {
179-
180-
CL_RETURN_ON_FAILURE(clGetProgramInfo(cl_adapter::cast<cl_program>(hProgram),
181-
mapURProgramInfoToCL(propName),
182-
propSize, pPropValue, pPropSizeRet));
183-
179+
size_t CheckPropSize = 0;
180+
auto ClResult = clGetProgramInfo(cl_adapter::cast<cl_program>(hProgram),
181+
mapURProgramInfoToCL(propName), propSize,
182+
pPropValue, &CheckPropSize);
183+
if (pPropValue && CheckPropSize != propSize) {
184+
return UR_RESULT_ERROR_INVALID_SIZE;
185+
}
186+
CL_RETURN_ON_FAILURE(ClResult);
187+
if (pPropSizeRet) {
188+
*pPropSizeRet = CheckPropSize;
189+
}
184190
return UR_RESULT_SUCCESS;
185191
}
186192

@@ -249,30 +255,30 @@ UR_APIEXPORT ur_result_t UR_APICALL
249255
urProgramGetBuildInfo(ur_program_handle_t hProgram, ur_device_handle_t hDevice,
250256
ur_program_build_info_t propName, size_t propSize,
251257
void *pPropValue, size_t *pPropSizeRet) {
252-
253-
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
254-
255-
switch (propName) {
256-
case UR_PROGRAM_BUILD_INFO_BINARY_TYPE:
257-
cl_program_binary_type cl_value;
258+
if (propName == UR_PROGRAM_BUILD_INFO_BINARY_TYPE) {
259+
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);
260+
cl_program_binary_type BinaryType;
258261
CL_RETURN_ON_FAILURE(clGetProgramBuildInfo(
259262
cl_adapter::cast<cl_program>(hProgram),
260263
cl_adapter::cast<cl_device_id>(hDevice),
261264
mapURProgramBuildInfoToCL(propName), sizeof(cl_program_binary_type),
262-
&cl_value, nullptr));
263-
return ReturnValue(mapCLBinaryTypeToUR(cl_value));
264-
case UR_PROGRAM_BUILD_INFO_LOG:
265-
case UR_PROGRAM_BUILD_INFO_OPTIONS:
266-
case UR_PROGRAM_BUILD_INFO_STATUS:
267-
CL_RETURN_ON_FAILURE(
268-
clGetProgramBuildInfo(cl_adapter::cast<cl_program>(hProgram),
269-
cl_adapter::cast<cl_device_id>(hDevice),
270-
mapURProgramBuildInfoToCL(propName), propSize,
271-
pPropValue, pPropSizeRet));
272-
return UR_RESULT_SUCCESS;
273-
default:
274-
return UR_RESULT_ERROR_INVALID_ENUMERATION;
265+
&BinaryType, nullptr));
266+
return ReturnValue(mapCLBinaryTypeToUR(BinaryType));
275267
}
268+
size_t CheckPropSize = 0;
269+
cl_int ClErr = clGetProgramBuildInfo(cl_adapter::cast<cl_program>(hProgram),
270+
cl_adapter::cast<cl_device_id>(hDevice),
271+
mapURProgramBuildInfoToCL(propName),
272+
propSize, pPropValue, &CheckPropSize);
273+
if (pPropValue && CheckPropSize != propSize) {
274+
return UR_RESULT_ERROR_INVALID_SIZE;
275+
}
276+
CL_RETURN_ON_FAILURE(ClErr);
277+
if (pPropSizeRet) {
278+
*pPropSizeRet = CheckPropSize;
279+
}
280+
281+
return UR_RESULT_SUCCESS;
276282
}
277283

278284
UR_APIEXPORT ur_result_t UR_APICALL

0 commit comments

Comments
 (0)