@@ -258,11 +258,60 @@ cl_int CL_API_CALL clEnqueueWaitSemaphoresKHR_EMU(
258258 const cl_event *event_wait_list,
259259 cl_event *event)
260260{
261+ cl_int retVal = CL_SUCCESS;
261262 if ( num_semaphores == 0 )
262263 {
263264 return CL_INVALID_VALUE;
264265 }
265266
267+ cl_context q_context;
268+ retVal = g_pNextDispatch->clGetCommandQueueInfo (
269+ command_queue, CL_QUEUE_CONTEXT, sizeof (q_context), &q_context, nullptr );
270+ if (retVal != CL_SUCCESS)
271+ return retVal;
272+
273+ // CL_INVALID_EVENT_WAIT_LIST
274+ // -event_wait_list is NULL and num_events_in_wait_list is not 0, or
275+ // -event_wait_list is not NULL and num_events_in_wait_list is 0, or
276+ if ((num_events_in_wait_list>0 &&event_wait_list==nullptr ) ||
277+ (num_events_in_wait_list==0 &&event_wait_list!=nullptr ))
278+ {
279+ return CL_INVALID_EVENT_WAIT_LIST;
280+ }
281+ else
282+ {
283+ for (cl_uint i=0 ; i<num_events_in_wait_list; i++)
284+ {
285+ // CL_INVALID_EVENT_WAIT_LIST - event objects in event_wait_list are
286+ // not valid events.
287+ if (event_wait_list[i] == nullptr )
288+ return CL_INVALID_EVENT_WAIT_LIST;
289+
290+ // CL_INVALID_CONTEXT - the context associated with command_queue and
291+ // that associated with events in event_wait_list are not the same
292+ cl_context e_context;
293+ retVal = g_pNextDispatch->clGetEventInfo (
294+ event_wait_list[i], CL_EVENT_CONTEXT, sizeof (e_context),
295+ &e_context, nullptr );
296+ if (retVal != CL_SUCCESS)
297+ return retVal;
298+ if (q_context != e_context)
299+ return CL_INVALID_CONTEXT;
300+
301+ // CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST - the execution status
302+ // of any of the events in event_wait_list is a negative integer
303+ // value.
304+ cl_int status = 0 ;
305+ retVal = g_pNextDispatch->clGetEventInfo (
306+ event_wait_list[i], CL_EVENT_COMMAND_EXECUTION_STATUS,
307+ sizeof (status), &status, nullptr );
308+ if (retVal != CL_SUCCESS)
309+ return retVal;
310+ if (status < 0 )
311+ return CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
312+ }
313+ }
314+
266315 std::vector<cl_event> combinedWaitList;
267316 combinedWaitList.insert (
268317 combinedWaitList.end (),
@@ -275,6 +324,12 @@ cl_int CL_API_CALL clEnqueueWaitSemaphoresKHR_EMU(
275324 {
276325 return CL_INVALID_SEMAPHORE_KHR;
277326 }
327+ if ( semaphores[i]->Context != q_context)
328+ {
329+ // CL_INVALID_CONTEXT - the context associated with command_queue and
330+ // any of the semaphore objects in sema_objects are not the same
331+ return CL_INVALID_CONTEXT;
332+ }
278333 if ( semaphores[i]->Event == nullptr )
279334 {
280335 // This is a semaphore that is not in a pending signal
@@ -285,7 +340,7 @@ cl_int CL_API_CALL clEnqueueWaitSemaphoresKHR_EMU(
285340 semaphores[i]->Event );
286341 }
287342
288- cl_int retVal = g_pNextDispatch->clEnqueueMarkerWithWaitList (
343+ retVal = g_pNextDispatch->clEnqueueMarkerWithWaitList (
289344 command_queue,
290345 (cl_uint)combinedWaitList.size (),
291346 combinedWaitList.data (),
@@ -315,17 +370,72 @@ cl_int CL_API_CALL clEnqueueSignalSemaphoresKHR_EMU(
315370 const cl_event *event_wait_list,
316371 cl_event *event)
317372{
373+ cl_int retVal = CL_SUCCESS;
318374 if ( num_semaphores == 0 )
319375 {
320376 return CL_INVALID_VALUE;
321377 }
322378
379+ cl_context q_context;
380+ retVal = g_pNextDispatch->clGetCommandQueueInfo (
381+ command_queue, CL_QUEUE_CONTEXT, sizeof (q_context), &q_context, nullptr );
382+ if (retVal != CL_SUCCESS)
383+ return retVal;
384+
385+ // CL_INVALID_EVENT_WAIT_LIST
386+ // -event_wait_list is NULL and num_events_in_wait_list is not 0, or
387+ // -event_wait_list is not NULL and num_events_in_wait_list is 0, or
388+ if ((num_events_in_wait_list>0 &&event_wait_list==nullptr ) ||
389+ (num_events_in_wait_list==0 &&event_wait_list!=nullptr ))
390+ {
391+ return CL_INVALID_EVENT_WAIT_LIST;
392+ }
393+ else
394+ {
395+ for (cl_uint i=0 ; i<num_events_in_wait_list; i++)
396+ {
397+ // CL_INVALID_EVENT_WAIT_LIST - event objects in event_wait_list are
398+ // not valid events.
399+ if (event_wait_list[i] == nullptr )
400+ return CL_INVALID_EVENT_WAIT_LIST;
401+
402+ // CL_INVALID_CONTEXT - the context associated with command_queue and
403+ // that associated with events in event_wait_list are not the same
404+ cl_context e_context;
405+ retVal = g_pNextDispatch->clGetEventInfo (
406+ event_wait_list[i], CL_EVENT_CONTEXT, sizeof (e_context),
407+ &e_context, nullptr );
408+ if (retVal != CL_SUCCESS)
409+ return retVal;
410+ if (q_context != e_context)
411+ return CL_INVALID_CONTEXT;
412+
413+ // CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST - the execution status
414+ // of any of the events in event_wait_list is a negative integer
415+ // value.
416+ cl_int status = 0 ;
417+ retVal = g_pNextDispatch->clGetEventInfo (
418+ event_wait_list[i], CL_EVENT_COMMAND_EXECUTION_STATUS,
419+ sizeof (status), &status, nullptr );
420+ if (retVal != CL_SUCCESS)
421+ return retVal;
422+ if (status < 0 )
423+ return CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
424+ }
425+ }
426+
323427 for ( cl_uint i = 0 ; i < num_semaphores; i++ )
324428 {
325429 if ( !cli_semaphore::isValid (semaphores[i]) )
326430 {
327431 return CL_INVALID_SEMAPHORE_KHR;
328432 }
433+ if ( semaphores[i]->Context != q_context)
434+ {
435+ // CL_INVALID_CONTEXT - the context associated with command_queue and
436+ // any of the semaphore objects in sema_objects are not the same
437+ return CL_INVALID_CONTEXT;
438+ }
329439 if ( semaphores[i]->Event != nullptr )
330440 {
331441 // This is a semaphore that is in a pending signal or signaled
@@ -340,7 +450,7 @@ cl_int CL_API_CALL clEnqueueSignalSemaphoresKHR_EMU(
340450 event = &local_event;
341451 }
342452
343- cl_int retVal = g_pNextDispatch->clEnqueueMarkerWithWaitList (
453+ retVal = g_pNextDispatch->clEnqueueMarkerWithWaitList (
344454 command_queue,
345455 num_events_in_wait_list,
346456 event_wait_list,
0 commit comments