@@ -100,8 +100,13 @@ urKernelSetArgLocal(ur_kernel_handle_t hKernel, uint32_t argIndex,
100
100
return UR_RESULT_SUCCESS;
101
101
}
102
102
103
- static cl_int mapURKernelInfoToCL (ur_kernel_info_t URPropName) {
103
+ // Querying the number of registers that a kernel uses is supported unofficially
104
+ // on some devices.
105
+ #ifndef CL_KERNEL_REGISTER_COUNT_INTEL
106
+ #define CL_KERNEL_REGISTER_COUNT_INTEL 0x425B
107
+ #endif
104
108
109
+ static cl_int mapURKernelInfoToCL (ur_kernel_info_t URPropName) {
105
110
switch (static_cast <uint32_t >(URPropName)) {
106
111
case UR_KERNEL_INFO_FUNCTION_NAME:
107
112
return CL_KERNEL_FUNCTION_NAME;
@@ -115,9 +120,10 @@ static cl_int mapURKernelInfoToCL(ur_kernel_info_t URPropName) {
115
120
return CL_KERNEL_PROGRAM;
116
121
case UR_KERNEL_INFO_ATTRIBUTES:
117
122
return CL_KERNEL_ATTRIBUTES;
118
- // NUM_REGS doesn't have a CL equivalent
119
- case UR_KERNEL_INFO_NUM_REGS:
120
123
case UR_KERNEL_INFO_SPILL_MEM_SIZE:
124
+ return CL_KERNEL_SPILL_MEM_SIZE_INTEL;
125
+ case UR_KERNEL_INFO_NUM_REGS:
126
+ return CL_KERNEL_REGISTER_COUNT_INTEL;
121
127
default :
122
128
return -1 ;
123
129
}
@@ -132,10 +138,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
132
138
UrReturnHelper ReturnValue (propSize, pPropValue, pPropSizeRet);
133
139
134
140
switch (propName) {
135
- // OpenCL doesn't have a way to support this.
136
- case UR_KERNEL_INFO_NUM_REGS: {
137
- return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
138
- }
139
141
case UR_KERNEL_INFO_PROGRAM: {
140
142
return ReturnValue (hKernel->Program );
141
143
}
@@ -145,14 +147,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
145
147
case UR_KERNEL_INFO_REFERENCE_COUNT: {
146
148
return ReturnValue (hKernel->getReferenceCount ());
147
149
}
148
- case UR_KERNEL_INFO_SPILL_MEM_SIZE: {
149
- return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
150
- }
151
150
default : {
152
151
size_t CheckPropSize = 0 ;
153
152
cl_int ClResult =
154
153
clGetKernelInfo (hKernel->CLKernel , mapURKernelInfoToCL (propName),
155
154
propSize, pPropValue, &CheckPropSize);
155
+ if (ClResult == CL_INVALID_VALUE) {
156
+ return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
157
+ }
156
158
if (pPropValue && CheckPropSize != propSize) {
157
159
return UR_RESULT_ERROR_INVALID_SIZE;
158
160
}
@@ -334,12 +336,18 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
334
336
}
335
337
336
338
UR_APIEXPORT ur_result_t UR_APICALL urKernelRetain (ur_kernel_handle_t hKernel) {
339
+
340
+ UR_ASSERT (hKernel->getReferenceCount () > 0u , UR_RESULT_ERROR_INVALID_KERNEL);
341
+
337
342
hKernel->incrementReferenceCount ();
338
343
return UR_RESULT_SUCCESS;
339
344
}
340
345
341
346
UR_APIEXPORT ur_result_t UR_APICALL
342
347
urKernelRelease (ur_kernel_handle_t hKernel) {
348
+
349
+ UR_ASSERT (hKernel->getReferenceCount () != 0 , UR_RESULT_ERROR_INVALID_KERNEL);
350
+
343
351
if (hKernel->decrementReferenceCount () == 0 ) {
344
352
delete hKernel;
345
353
}
@@ -428,25 +436,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelSetArgPointer(
428
436
ur_kernel_handle_t hKernel, uint32_t argIndex,
429
437
const ur_kernel_arg_pointer_properties_t *, const void *pArgValue) {
430
438
431
- cl_context CLContext;
432
- CL_RETURN_ON_FAILURE (clGetKernelInfo (hKernel->CLKernel , CL_KERNEL_CONTEXT,
433
- sizeof (cl_context), &CLContext,
434
- nullptr ));
435
-
436
- clSetKernelArgMemPointerINTEL_fn FuncPtr = nullptr ;
437
- UR_RETURN_ON_FAILURE (
438
- cl_ext::getExtFuncFromContext<clSetKernelArgMemPointerINTEL_fn>(
439
- CLContext,
440
- ur::cl::getAdapter ()->fnCache .clSetKernelArgMemPointerINTELCache ,
441
- cl_ext::SetKernelArgMemPointerName, &FuncPtr));
442
-
443
- if (FuncPtr) {
444
- CL_RETURN_ON_FAILURE (
445
- FuncPtr (hKernel->CLKernel , static_cast <cl_uint>(argIndex), pArgValue));
439
+ if (hKernel->clSetKernelArgMemPointerINTEL == nullptr ) {
440
+ return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
446
441
}
447
442
443
+ CL_RETURN_ON_FAILURE (hKernel->clSetKernelArgMemPointerINTEL (
444
+ hKernel->CLKernel , static_cast <cl_uint>(argIndex), pArgValue));
445
+
448
446
return UR_RESULT_SUCCESS;
449
447
}
448
+
450
449
UR_APIEXPORT ur_result_t UR_APICALL urKernelGetNativeHandle (
451
450
ur_kernel_handle_t hKernel, ur_native_handle_t *phNativeKernel) {
452
451
0 commit comments