zeroshade commented on code in PR #37365:
URL: https://github.com/apache/arrow/pull/37365#discussion_r1305825652


##########
cpp/src/arrow/gpu/cuda_context.cc:
##########
@@ -281,6 +279,49 @@ Result<std::shared_ptr<CudaDevice>> AsCudaDevice(const 
std::shared_ptr<Device>&
   }
 }
 
+Status CudaDevice::Stream::WaitEvent(const Device::SyncEvent& event) {
+  auto cuda_event =
+      checked_cast<const CudaDevice::SyncEvent*, const 
Device::SyncEvent*>(&event);
+  if (!cuda_event) {
+    return Status::Invalid("CudaDevice::Stream cannot Wait on non-cuda event");
+  }
+
+  auto cu_event = cuda_event->value();
+  if (!cu_event) {
+    return Status::Invalid("Cuda Stream cannot wait on null event");
+  }
+
+  ContextSaver set_temporary((CUcontext)(context_.get()->handle()));
+  // TODO: do we need to account for CUevent_capture_flags??
+  CU_RETURN_NOT_OK("cuStreamWaitEvent",
+                   cuStreamWaitEvent(stream_, cu_event, 
CU_EVENT_WAIT_DEFAULT));
+  return Status::OK();
+}
+
+Status CudaDevice::Stream::Synchronize() const {
+  ContextSaver set_temporary((CUcontext)(context_.get()->handle()));
+  CU_RETURN_NOT_OK("cuStreamSynchronize", cuStreamSynchronize(stream_));
+  return Status::OK();
+}
+
+Status CudaDevice::SyncEvent::Wait() {
+  ContextSaver set_temporary((CUcontext)(context_.get()->handle()));
+  CU_RETURN_NOT_OK("cuEventSynchronize", cuEventSynchronize(value()));
+  return Status::OK();
+}
+
+Status CudaDevice::SyncEvent::Record(const Device::Stream& st) {
+  auto cuda_stream = checked_cast<const CudaDevice::Stream*, const 
Device::Stream*>(&st);
+  if (!cuda_stream) {
+    return Status::Invalid("CudaDevice::Event cannot record on non-cuda 
stream");
+  }
+
+  ContextSaver set_temporary((CUcontext)(context_.get()->handle()));
+  CU_RETURN_NOT_OK("cuEventRecord", cuEventRecord(value(), 
cuda_stream->value()));
+  // TODO: there is also cuEventRecordWithFlags, do we want to allow flags?

Review Comment:
   @kkraus14 Is it common / typical for `unsigned int flags` in most libs? 
Would it make sense to add that as an optional argument to the base `Record` 
method?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to