@@ -276,13 +276,15 @@ _pi_event::_pi_event(pi_command_type type, pi_context context, pi_queue queue)
276276 isStarted_{false }, evEnd_{nullptr }, evStart_{nullptr }, evQueued_{nullptr },
277277 queue_{queue}, context_{context} {
278278
279- if (is_native_event () ) {
279+ if (type != PI_COMMAND_TYPE_USER ) {
280280 PI_CHECK_ERROR (cuEventCreate (&evEnd_, CU_EVENT_DEFAULT));
281281
282282 if (queue_->properties_ & PI_QUEUE_PROFILING_ENABLE) {
283283 PI_CHECK_ERROR (cuEventCreate (&evQueued_, CU_EVENT_DEFAULT));
284284 PI_CHECK_ERROR (cuEventCreate (&evStart_, CU_EVENT_DEFAULT));
285285 }
286+ } else {
287+ cl::sycl::detail::pi::die (" User-defined events not implemented" );
286288 }
287289
288290 if (queue_ != nullptr ) {
@@ -303,7 +305,7 @@ pi_result _pi_event::start() {
303305 pi_result result;
304306
305307 try {
306- if (is_native_event () && queue_->properties_ & PI_QUEUE_PROFILING_ENABLE) {
308+ if (queue_->properties_ & PI_QUEUE_PROFILING_ENABLE) {
307309 // NOTE: This relies on the default stream to be unused.
308310 result = PI_CHECK_ERROR (cuEventRecord (evQueued_, 0 ));
309311 result = PI_CHECK_ERROR (cuEventRecord (evStart_, queue_->get ()));
@@ -313,8 +315,6 @@ pi_result _pi_event::start() {
313315 }
314316
315317 isStarted_ = true ;
316- // let observers know that the event is "submitted"
317- trigger_callback (get_execution_status ());
318318 return result;
319319}
320320
@@ -351,37 +351,16 @@ pi_result _pi_event::record() {
351351
352352 pi_result result = PI_INVALID_OPERATION;
353353
354- if (is_native_event ()) {
355-
356- if (!queue_) {
357- return PI_INVALID_QUEUE;
358- }
354+ if (!queue_) {
355+ return PI_INVALID_QUEUE;
356+ }
359357
360- CUstream cuStream = queue_->get ();
358+ CUstream cuStream = queue_->get ();
361359
362- try {
363- result = PI_CHECK_ERROR (cuEventRecord (evEnd_, cuStream));
364-
365- result = cuda_piEventRetain (this );
366- try {
367- result = PI_CHECK_ERROR (cuLaunchHostFunc (
368- cuStream,
369- [](void *userData) {
370- pi_event event = reinterpret_cast <pi_event>(userData);
371- event->set_event_complete ();
372- cuda_piEventRelease (event);
373- },
374- this ));
375- } catch (...) {
376- // If host function fails to enqueue we must release the event here
377- result = cuda_piEventRelease (this );
378- throw ;
379- }
380- } catch (pi_result error) {
381- result = error;
382- }
383- } else {
384- result = PI_SUCCESS;
360+ try {
361+ result = PI_CHECK_ERROR (cuEventRecord (evEnd_, cuStream));
362+ } catch (pi_result error) {
363+ result = error;
385364 }
386365
387366 if (result == PI_SUCCESS) {
@@ -392,65 +371,23 @@ pi_result _pi_event::record() {
392371}
393372
394373pi_result _pi_event::wait () {
395-
396374 pi_result retErr;
397- if (is_native_event ()) {
398- try {
399- retErr = PI_CHECK_ERROR (cuEventSynchronize (evEnd_));
400- isCompleted_ = true ;
401- } catch (pi_result error) {
402- retErr = error;
403- }
404- } else {
405-
406- while (!is_completed ()) {
407- // wait for user event to complete
408- }
409- retErr = PI_SUCCESS;
375+ try {
376+ retErr = PI_CHECK_ERROR (cuEventSynchronize (evEnd_));
377+ isCompleted_ = true ;
378+ } catch (pi_result error) {
379+ retErr = error;
410380 }
411381
412- auto is_success = retErr == PI_SUCCESS;
413- auto status = is_success ? get_execution_status () : pi_int32 (retErr);
414-
415- trigger_callback (status);
416-
417382 return retErr;
418383}
419384
420385// makes all future work submitted to queue wait for all work captured in event.
421386pi_result enqueueEventWait (pi_queue queue, pi_event event) {
422- if (event->is_native_event ()) {
423-
424- // for native events, the cuStreamWaitEvent call is used.
425- // This makes all future work submitted to stream wait for all
426- // work captured in event.
427-
428- return PI_CHECK_ERROR (cuStreamWaitEvent (queue->get (), event->get (), 0 ));
429-
430- } else {
431-
432- // for user events, we enqueue a callback. When invoked, the
433- // callback will block until the user event is marked as
434- // completed.
435-
436- static auto user_wait_func = [](void *user_data) {
437- // The host function must not make any CUDA API calls.
438- auto event = static_cast <pi_event>(user_data);
439-
440- // busy wait for user event to complete
441- event->wait ();
442-
443- // this function does not need the event to be kept alive
444- // anymore
445- cuda_piEventRelease (event);
446- };
447-
448- // retain event to ensure it is still alive when the
449- // user_wait_func callback is invoked
450- cuda_piEventRetain (event);
451-
452- return PI_CHECK_ERROR (cuLaunchHostFunc (queue->get (), user_wait_func, event));
453- }
387+ // for native events, the cuStreamWaitEvent call is used.
388+ // This makes all future work submitted to stream wait for all
389+ // work captured in event.
390+ return PI_CHECK_ERROR (cuStreamWaitEvent (queue->get (), event->get (), 0 ));
454391}
455392
456393_pi_program::_pi_program (pi_context ctxt)
@@ -2763,37 +2700,13 @@ pi_result cuda_piEventSetCallback(pi_event event,
27632700 pi_int32 command_exec_callback_type,
27642701 pfn_notify notify, void *user_data) {
27652702
2766- assert (event);
2767- assert (notify);
2768- assert (command_exec_callback_type == PI_EVENT_SUBMITTED ||
2769- command_exec_callback_type == PI_EVENT_RUNNING ||
2770- command_exec_callback_type == PI_EVENT_COMPLETE);
2771- event_callback callback (pi_event_status (command_exec_callback_type), notify,
2772- user_data);
2773-
2774- event->set_event_callback (callback);
2775-
2703+ cl::sycl::detail::pi::die (" Event Callback not implemented" );
27762704 return PI_SUCCESS;
27772705}
27782706
27792707pi_result cuda_piEventSetStatus (pi_event event, pi_int32 execution_status) {
27802708
2781- assert (execution_status >= PI_EVENT_COMPLETE &&
2782- execution_status <= PI_EVENT_QUEUED);
2783-
2784- if (!event || event->is_native_event ()) {
2785- return PI_INVALID_EVENT;
2786- }
2787-
2788- if (execution_status == PI_EVENT_COMPLETE) {
2789- return event->set_event_complete ();
2790- } else if (execution_status < 0 ) {
2791- // TODO: A negative integer value causes all enqueued commands that wait
2792- // on this user event to be terminated.
2793- cl::sycl::detail::pi::die (" cuda_piEventSetStatus support for negative execution_status not "
2794- " implemented." );
2795- }
2796-
2709+ cl::sycl::detail::pi::die (" Event Set Status not implemented" );
27972710 return PI_INVALID_VALUE;
27982711}
27992712
@@ -2821,19 +2734,13 @@ pi_result cuda_piEventRelease(pi_event event) {
28212734 if (event->decrement_reference_count () == 0 ) {
28222735 std::unique_ptr<_pi_event> event_ptr{event};
28232736 pi_result result = PI_INVALID_EVENT;
2824-
2825- if (event->is_native_event ()) {
2826- try {
2827- ScopedContext active (event->get_context ());
2828- auto cuEvent = event->get ();
2829- result = PI_CHECK_ERROR (cuEventDestroy (cuEvent));
2830- } catch (...) {
2831- result = PI_OUT_OF_RESOURCES;
2832- }
2833- } else {
2834- result = PI_SUCCESS;
2737+ try {
2738+ ScopedContext active (event->get_context ());
2739+ auto cuEvent = event->get ();
2740+ result = PI_CHECK_ERROR (cuEventDestroy (cuEvent));
2741+ } catch (...) {
2742+ result = PI_OUT_OF_RESOURCES;
28352743 }
2836-
28372744 return result;
28382745 }
28392746
@@ -2888,9 +2795,6 @@ pi_result cuda_piEnqueueEventsWait(pi_queue command_queue,
28882795// / \return PI_SUCCESS on success. PI_INVALID_EVENT if given a user event.
28892796pi_result cuda_piextEventGetNativeHandle (pi_event event,
28902797 pi_native_handle *nativeHandle) {
2891- if (event->is_user_event ()) {
2892- return PI_INVALID_EVENT;
2893- }
28942798 *nativeHandle = reinterpret_cast <pi_native_handle>(event->get ());
28952799 return PI_SUCCESS;
28962800}
0 commit comments