@@ -192,6 +192,11 @@ struct SAllocInfo
192192 cl_device_id AssociatedDevice = nullptr ;
193193};
194194
195+ struct SEventInfo
196+ {
197+ cl_command_type Type = 0 ;
198+ };
199+
195200struct SLayerContext
196201{
197202 SLayerContext () {
@@ -265,6 +270,26 @@ struct SLayerContext
265270 AllocMaps[context].erase (ptr);
266271 }
267272
273+ SEventInfo& getEventInfo (cl_event event)
274+ {
275+ return EventMap[event];
276+ }
277+
278+ bool findEventInfo (cl_event event, SEventInfo& info)
279+ {
280+ auto it = EventMap.find (event);
281+ if (it != EventMap.end ()) {
282+ info = it->second ;
283+ return true ;
284+ }
285+ return false ;
286+ }
287+
288+ void removeEventInfo (cl_event event)
289+ {
290+ EventMap.erase (event);
291+ }
292+
268293private:
269294 void getSVMTypesForPlatform (cl_platform_id platform)
270295 {
@@ -395,6 +420,9 @@ struct SLayerContext
395420
396421 typedef std::map<const void *, SAllocInfo> CAllocMap;
397422 std::map<cl_context, CAllocMap> AllocMaps;
423+
424+ std::map<cl_event, SEventInfo> EventMap;
425+
398426};
399427
400428SLayerContext& getLayerContext (void )
@@ -542,6 +570,13 @@ void* CL_API_CALL clSVMAllocWithPropertiesKHR_EMU(
542570 return nullptr ;
543571 }
544572
573+ if (size == 0 ) {
574+ if (errcode_ret) {
575+ errcode_ret[0 ] = CL_SUCCESS;
576+ }
577+ return nullptr ;
578+ }
579+
545580 void * ret = nullptr ;
546581
547582 cl_device_id device = nullptr ;
@@ -927,6 +962,38 @@ cl_int CL_API_CALL clGetDeviceInfo_override(
927962 param_value_size_ret);
928963}
929964
965+ cl_int CL_API_CALL clGetEventInfo_override (
966+ cl_event event,
967+ cl_event_info param_name,
968+ size_t param_value_size,
969+ void * param_value,
970+ size_t * param_value_size_ret)
971+ {
972+ switch (param_name) {
973+ case CL_EVENT_COMMAND_TYPE:
974+ {
975+ SEventInfo eventInfo;
976+ if (getLayerContext ().findEventInfo (event, eventInfo)) {
977+ auto ptr = (cl_command_type*)param_value;
978+ return writeParamToMemory (
979+ param_value_size,
980+ eventInfo.Type ,
981+ param_value_size_ret,
982+ ptr );
983+ }
984+ }
985+ break ;
986+ default : break ;
987+ }
988+
989+ return g_pNextDispatch->clGetEventInfo (
990+ event,
991+ param_name,
992+ param_value_size,
993+ param_value,
994+ param_value_size_ret);
995+ }
996+
930997cl_int CL_API_CALL clGetPlatformInfo_override (
931998 cl_platform_id platform,
932999 cl_platform_info param_name,
@@ -1140,6 +1207,22 @@ cl_int CL_API_CALL clEnqueueSVMMemcpy_override(
11401207{
11411208 cl_context context = getContext (command_queue);
11421209
1210+ if (size == 0 ) {
1211+ if (event) {
1212+ cl_int ret = g_pNextDispatch->clEnqueueMarkerWithWaitList (
1213+ command_queue,
1214+ num_events_in_wait_list,
1215+ event_wait_list,
1216+ event);
1217+ if (ret == CL_SUCCESS) {
1218+ auto & eventInfo = getLayerContext ().getEventInfo (*event);
1219+ eventInfo.Type = CL_COMMAND_SVM_MEMCPY;
1220+ }
1221+ return ret;
1222+ }
1223+ return CL_SUCCESS;
1224+ }
1225+
11431226 if (isUSMPtr (context, dst_ptr) || isUSMPtr (context, src_ptr)) {
11441227 return clEnqueueMemcpyINTEL (
11451228 command_queue,
@@ -1175,6 +1258,22 @@ cl_int CL_API_CALL clEnqueueSVMMemFill_override(
11751258{
11761259 cl_context context = getContext (command_queue);
11771260
1261+ if (size == 0 ) {
1262+ if (event) {
1263+ cl_int ret = g_pNextDispatch->clEnqueueMarkerWithWaitList (
1264+ command_queue,
1265+ num_events_in_wait_list,
1266+ event_wait_list,
1267+ event);
1268+ if (ret == CL_SUCCESS) {
1269+ auto & eventInfo = getLayerContext ().getEventInfo (*event);
1270+ eventInfo.Type = CL_COMMAND_SVM_MEMFILL;
1271+ }
1272+ return ret;
1273+ }
1274+ return CL_SUCCESS;
1275+ }
1276+
11781277 if (isUSMPtr (context, svm_ptr)) {
11791278 return clEnqueueMemFillINTEL (
11801279 command_queue,
@@ -1215,3 +1314,20 @@ cl_int CL_API_CALL clEnqueueSVMMigrateMem_override(
12151314 event_wait_list,
12161315 event);
12171316}
1317+
1318+ cl_int CL_API_CALL clReleaseEvent_override (
1319+ cl_event event)
1320+ {
1321+ cl_uint refCount = 0 ;
1322+ g_pNextDispatch->clGetEventInfo (
1323+ event,
1324+ CL_EVENT_REFERENCE_COUNT,
1325+ sizeof (refCount),
1326+ &refCount,
1327+ nullptr );
1328+ if (refCount == 1 ) {
1329+ getLayerContext ().removeEventInfo (event);
1330+ }
1331+
1332+ return g_pNextDispatch->clReleaseEvent (event);
1333+ }
0 commit comments