@@ -276,13 +276,15 @@ _pi_event::_pi_event(pi_command_type type, pi_context context, pi_queue queue)
276
276
isStarted_{false }, evEnd_{nullptr }, evStart_{nullptr }, evQueued_{nullptr },
277
277
queue_{queue}, context_{context} {
278
278
279
- if (is_native_event () ) {
279
+ if (type != PI_COMMAND_TYPE_USER ) {
280
280
PI_CHECK_ERROR (cuEventCreate (&evEnd_, CU_EVENT_DEFAULT));
281
281
282
282
if (queue_->properties_ & PI_QUEUE_PROFILING_ENABLE) {
283
283
PI_CHECK_ERROR (cuEventCreate (&evQueued_, CU_EVENT_DEFAULT));
284
284
PI_CHECK_ERROR (cuEventCreate (&evStart_, CU_EVENT_DEFAULT));
285
285
}
286
+ } else {
287
+ cl::sycl::detail::pi::die (" User-defined events not implemented" );
286
288
}
287
289
288
290
if (queue_ != nullptr ) {
@@ -303,7 +305,7 @@ pi_result _pi_event::start() {
303
305
pi_result result;
304
306
305
307
try {
306
- if (is_native_event () && queue_->properties_ & PI_QUEUE_PROFILING_ENABLE) {
308
+ if (queue_->properties_ & PI_QUEUE_PROFILING_ENABLE) {
307
309
// NOTE: This relies on the default stream to be unused.
308
310
result = PI_CHECK_ERROR (cuEventRecord (evQueued_, 0 ));
309
311
result = PI_CHECK_ERROR (cuEventRecord (evStart_, queue_->get ()));
@@ -313,8 +315,6 @@ pi_result _pi_event::start() {
313
315
}
314
316
315
317
isStarted_ = true ;
316
- // let observers know that the event is "submitted"
317
- trigger_callback (get_execution_status ());
318
318
return result;
319
319
}
320
320
@@ -351,37 +351,16 @@ pi_result _pi_event::record() {
351
351
352
352
pi_result result = PI_INVALID_OPERATION;
353
353
354
- if (is_native_event ()) {
355
-
356
- if (!queue_) {
357
- return PI_INVALID_QUEUE;
358
- }
354
+ if (!queue_) {
355
+ return PI_INVALID_QUEUE;
356
+ }
359
357
360
- CUstream cuStream = queue_->get ();
358
+ CUstream cuStream = queue_->get ();
361
359
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;
385
364
}
386
365
387
366
if (result == PI_SUCCESS) {
@@ -392,65 +371,23 @@ pi_result _pi_event::record() {
392
371
}
393
372
394
373
pi_result _pi_event::wait () {
395
-
396
374
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;
410
380
}
411
381
412
- auto is_success = retErr == PI_SUCCESS;
413
- auto status = is_success ? get_execution_status () : pi_int32 (retErr);
414
-
415
- trigger_callback (status);
416
-
417
382
return retErr;
418
383
}
419
384
420
385
// makes all future work submitted to queue wait for all work captured in event.
421
386
pi_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 ));
454
391
}
455
392
456
393
_pi_program::_pi_program (pi_context ctxt)
@@ -2763,37 +2700,13 @@ pi_result cuda_piEventSetCallback(pi_event event,
2763
2700
pi_int32 command_exec_callback_type,
2764
2701
pfn_notify notify, void *user_data) {
2765
2702
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" );
2776
2704
return PI_SUCCESS;
2777
2705
}
2778
2706
2779
2707
pi_result cuda_piEventSetStatus (pi_event event, pi_int32 execution_status) {
2780
2708
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" );
2797
2710
return PI_INVALID_VALUE;
2798
2711
}
2799
2712
@@ -2821,19 +2734,13 @@ pi_result cuda_piEventRelease(pi_event event) {
2821
2734
if (event->decrement_reference_count () == 0 ) {
2822
2735
std::unique_ptr<_pi_event> event_ptr{event};
2823
2736
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;
2835
2743
}
2836
-
2837
2744
return result;
2838
2745
}
2839
2746
@@ -2888,9 +2795,6 @@ pi_result cuda_piEnqueueEventsWait(pi_queue command_queue,
2888
2795
// / \return PI_SUCCESS on success. PI_INVALID_EVENT if given a user event.
2889
2796
pi_result cuda_piextEventGetNativeHandle (pi_event event,
2890
2797
pi_native_handle *nativeHandle) {
2891
- if (event->is_user_event ()) {
2892
- return PI_INVALID_EVENT;
2893
- }
2894
2798
*nativeHandle = reinterpret_cast <pi_native_handle>(event->get ());
2895
2799
return PI_SUCCESS;
2896
2800
}
0 commit comments