Repository: microsoft/onnxruntime
File: onnxruntime/test/autoep/library/ep_stream_support.cc (C++)

Code before:

// callback for EP library to release any internal state
/*static*/
void ORT_API_CALL StreamImpl::ReleaseImpl(_In_ OrtSyncStreamImpl* this_ptr) noexcept {
  delete static_cast<StreamImpl*>(this_ptr);
}

//
// Notification support
//

/*static*/
OrtStatus* ORT_API_CALL NotificationImpl::ActivateImpl(_In_ OrtSyncNotificationImpl* this_ptr) noexcept {
  auto& impl = *static_cast<NotificationImpl*>(this_ptr);
  static_cast<void>(impl);

  // e.g.
  // CUDA: cudaEventRecord
  // CANN: aclrtRecordEvent
  return nullptr;
}

/*static*/
OrtStatus* ORT_API_CALL NotificationImpl::WaitOnDeviceImpl(_In_ OrtSyncNotificationImpl* this_ptr,
                                                           _In_ OrtSyncStream* stream) noexcept {
  auto& impl = *static_cast<NotificationImpl*>(this_ptr);

  // TODO is this the right place to check `stream != nullptr` or should that be done elsewhere?
  if (stream == nullptr) {
    return nullptr;
  }

  void* handle = impl.ort_api.SyncStream_GetHandle(stream);
  static_cast<void>(handle);

  // Setup the event or similar that will be activated on notification.
  // See CudaNotification or CannNotification for examples.
  //
  // e.g.
  // CUDA: cudaStreamWaitEvent(static_cast<cudaStream_t>(device_stream.GetHandle()), event_)
  // CANN: aclrtStreamWaitEvent(static_cast<aclrtStream>(device_stream.GetHandle()), event_)
  //
  // `event_` should be a member that is created in the ctor.
  // The stream handle should come from the StreamImpl instance and can be the real type so no static_cast is needed.
  return nullptr;
}

/*static*/
OrtStatus* ORT_API_CALL NotificationImpl::WaitOnHostImpl(_In_ OrtSyncNotificationImpl* this_ptr) noexcept {
  auto& impl = *static_cast<NotificationImpl*>(this_ptr);
  static_cast<void>(impl);

Review comment (bug):
I ran into `stream` being nullptr in a test. not sure if that should have been caught earlier or if implementors are expected to handle a possibly null stream.

Code after:

// callback for EP library to release any internal state
/*static*/
void ORT_API_CALL StreamImpl::ReleaseImpl(_In_ OrtSyncStreamImpl* this_ptr) noexcept {
  delete static_cast<StreamImpl*>(this_ptr);
}

//
// Notification support
//

/*static*/
OrtStatus* ORT_API_CALL NotificationImpl::ActivateImpl(_In_ OrtSyncNotificationImpl* this_ptr) noexcept {
  auto& impl = *static_cast<NotificationImpl*>(this_ptr);
  static_cast<void>(impl);

  // e.g.
  // CUDA: cudaEventRecord
  // CANN: aclrtRecordEvent
  return nullptr;
}

/*static*/
OrtStatus* ORT_API_CALL NotificationImpl::WaitOnDeviceImpl(_In_ OrtSyncNotificationImpl* this_ptr,
                                                           _In_ OrtSyncStream* stream) noexcept {
  if (stream == nullptr) {
    return nullptr;
  }

  auto& impl = *static_cast<NotificationImpl*>(this_ptr);

  void* handle = impl.ort_api.SyncStream_GetHandle(stream);
  static_cast<void>(handle);

  // Setup the event or similar that will be activated on notification.
  // See CudaNotification or CannNotification for examples.
  //
  // e.g.
  // CUDA: cudaStreamWaitEvent(static_cast<cudaStream_t>(device_stream.GetHandle()), event_)
  // CANN: aclrtStreamWaitEvent(static_cast<aclrtStream>(device_stream.GetHandle()), event_)
  //
  // `event_` should be a member that is created in the ctor.
  // The stream handle should come from the StreamImpl instance and can be the real type so no static_cast is needed.
  return nullptr;
}

/*static*/
OrtStatus* ORT_API_CALL NotificationImpl::WaitOnHostImpl(_In_ OrtSyncNotificationImpl* this_ptr) noexcept {
  auto& impl = *static_cast<NotificationImpl*>(this_ptr);
  static_cast<void>(impl);