Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webgpu] Use pushErrorScope()/popErrorScope() once for an inference run #23438

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions onnxruntime/core/providers/webgpu/compute_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,5 @@ ComputeContext::ComputeContext(OpKernelContext& kernel_context)
kernel_context_{kernel_context} {
}

void ComputeContext::PushErrorScope() {
if (webgpu_context_.ValidationMode() >= ValidationMode::Basic) {
webgpu_context_.Device().PushErrorScope(wgpu::ErrorFilter::Validation);
}
}

Status ComputeContext::PopErrorScope() {
Status status{};

if (webgpu_context_.ValidationMode() >= ValidationMode::Basic) {
ORT_RETURN_IF_ERROR(webgpu_context_.Wait(
webgpu_context_.Device().PopErrorScope(
wgpu::CallbackMode::WaitAnyOnly, [](wgpu::PopErrorScopeStatus pop_status, wgpu::ErrorType error_type, char const* message, Status* status) {
ORT_ENFORCE(pop_status == wgpu::PopErrorScopeStatus::Success, "Instance dropped.");
if (error_type == wgpu::ErrorType::NoError) {
return;
}
*status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "WebGPU validation failed. ", message);
},
&status)));
}
return status;
}

} // namespace webgpu
} // namespace onnxruntime
14 changes: 0 additions & 14 deletions onnxruntime/core/providers/webgpu/compute_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,6 @@ class ComputeContext {
return webgpu_context_.Run(*this, program);
}

//
// Push error scope.
//
// This is useful only when "skip_validation" is not set.
//
void PushErrorScope();

//
// Pop error scope.
//
// This is useful only when "skip_validation" is not set.
//
Status PopErrorScope();

protected:
WebGpuContext& webgpu_context_;
OpKernelContext& kernel_context_;
Expand Down
19 changes: 18 additions & 1 deletion onnxruntime/core/providers/webgpu/webgpu_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,10 @@ std::unique_ptr<profiling::EpProfiler> WebGpuExecutionProvider::GetProfiler() {
}

Status WebGpuExecutionProvider::OnRunStart(const onnxruntime::RunOptions& /*run_options*/) {
if (context_.ValidationMode() >= ValidationMode::Basic) {
context_.Device().PushErrorScope(wgpu::ErrorFilter::Validation);
}

if (profiler_->Enabled()) {
context_.StartProfiling();
}
Expand All @@ -858,7 +862,20 @@ Status WebGpuExecutionProvider::OnRunEnd(bool /* sync_stream */, const onnxrunti
context_.CollectProfilingData(profiler_->Events());
}

return Status::OK();
Status status{};
if (context_.ValidationMode() >= ValidationMode::Basic) {
ORT_RETURN_IF_ERROR(context_.Wait(
context_.Device().PopErrorScope(
wgpu::CallbackMode::WaitAnyOnly, [](wgpu::PopErrorScopeStatus pop_status, wgpu::ErrorType error_type, char const* message, Status* status) {
ORT_ENFORCE(pop_status == wgpu::PopErrorScopeStatus::Success, "Instance dropped.");
if (error_type == wgpu::ErrorType::NoError) {
return;
}
*status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "WebGPU validation failed. ", message);
},
&status)));
}
return status;
}

bool WebGpuExecutionProvider::IsGraphCaptureEnabled() const {
Expand Down
2 changes: 0 additions & 2 deletions onnxruntime/core/providers/webgpu/webgpu_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class WebGpuKernel : public OpKernel {
Status Compute(OpKernelContext* p_op_kernel_context) const override {
ComputeContext context{*p_op_kernel_context};

context.PushErrorScope();
Status s = ComputeInternal(context);
ORT_RETURN_IF_ERROR(context.PopErrorScope());
jchen10 marked this conversation as resolved.
Show resolved Hide resolved

return s;
}
Expand Down