MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / ForwardUserKernel

Method ForwardUserKernel

oneflow/core/kernel/user_kernel.cpp:697–737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

695}
696
697void UserKernel::ForwardUserKernel(const std::function<Blob*(const std::string&)>& BnInOp2Blob,
698 user_op::OpKernelState* opkernel_state) const {
699 const bool updated = ctx_->UpdateTensorWithCorrBlob(BnInOp2Blob);
700
701 if (updated) {
702 cache_ctx_->UpdateTensorWithCorrBlob(BnInOp2Blob);
703 kernel_->InitOpKernelCacheWithFlags(cache_ctx_.get(), user_op::OpKernelCache::kAttrNotChanged,
704 &opkernel_cache_);
705 } else {
706 // do nothing
707 }
708#ifdef WITH_CUDA_GRAPHS
709 bool current_scope_capturing = false;
710 if (cuda_graph_exec_) {
711 auto* cuda_stream = dynamic_cast<ep::CudaStream*>(ctx_->stream());
712 if (!cuda_stream->IsGraphCapturing()) {
713 if (cuda_graph_exec_->IsInstantiated() && (!updated)) {
714 cuda_stream->LaunchGraph(cuda_graph_exec_.get());
715 return;
716 }
717 const auto* cuda_graph_support =
718 CHECK_NOTNULL(dynamic_cast<const user_op::CudaGraphSupport*>(kernel_.get()));
719 if (cuda_graph_support->IsReadyForCapture(ctx_.get(), opkernel_state,
720 opkernel_cache_.get())) {
721 current_scope_capturing = true;
722 cuda_stream->BeginGraphCapture();
723 }
724 }
725 }
726#endif // WITH_CUDA_GRAPHS
727
728 kernel_->Compute(ctx_.get(), opkernel_state, opkernel_cache_.get());
729
730#ifdef WITH_CUDA_GRAPHS
731 if (cuda_graph_exec_ && current_scope_capturing) {
732 auto* cuda_stream = dynamic_cast<ep::CudaStream*>(ctx_->stream());
733 cuda_stream->EndGraphCapture(cuda_graph_exec_.get());
734 cuda_stream->LaunchGraph(cuda_graph_exec_.get());
735 }
736#endif // WITH_CUDA_GRAPHS
737}
738
739bool UserKernel::IsCudaGraphSupported() const {
740#ifdef WITH_CUDA_GRAPHS

Callers

nothing calls this directly

Calls 11

IsGraphCapturingMethod · 0.80
IsInstantiatedMethod · 0.80
LaunchGraphMethod · 0.80
IsReadyForCaptureMethod · 0.80
BeginGraphCaptureMethod · 0.80
EndGraphCaptureMethod · 0.80
getMethod · 0.45
streamMethod · 0.45
ComputeMethod · 0.45

Tested by

no test coverage detected