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]: add a simple GetCapability implementation #17643

Merged
merged 13 commits into from
Oct 6, 2023
31 changes: 31 additions & 0 deletions onnxruntime/core/providers/js/js_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#endif

#include "core/graph/function_utils.h"
#include "core/graph/indexed_sub_graph.h"
#include "core/framework/compute_capability.h"
#include "core/framework/data_transfer_manager.h"
#include "core/framework/kernel_registry.h"
#include "core/framework/fallback_cpu_capability.h"
#include "core/providers/shared/node_unit/node_unit.h"
#include "allocator.h"
#include "data_transfer.h"
Expand Down Expand Up @@ -631,6 +633,35 @@ std::vector<AllocatorPtr> JsExecutionProvider::CreatePreferredAllocators() {
std::vector<std::unique_ptr<ComputeCapability>> JsExecutionProvider::GetCapability(
const onnxruntime::GraphViewer& graph,
const IKernelLookup& kernel_lookup) const {
InlinedVector<NodeIndex> candidates;
for (auto& node_index : graph.GetNodesInTopologicalOrder()) {
const auto* p_node = graph.GetNode(node_index);
if (p_node == nullptr)
continue;

const auto& node = *p_node;
if (!node.GetExecutionProviderType().empty()) {
continue;
}

const KernelCreateInfo* webgpu_kernel_def = kernel_lookup.LookUpKernel(node);
// none of the provided registries has a webgpu kernel for this node
if (webgpu_kernel_def == nullptr) {
LOGS(*GetLogger(), INFO) << "webgpu kernel not found in registries for Op type: " << node.OpType() << " node name: " << node.Name();
continue;
}
candidates.push_back(node.Index());
}
auto cpu_nodes = GetCpuPreferredNodes(graph, kernel_lookup, candidates);
std::vector<std::unique_ptr<ComputeCapability>> result;
for (auto& node_index : candidates) {
if (cpu_nodes.count(node_index) > 0)
continue;

auto sub_graph = std::make_unique<IndexedSubGraph>();
sub_graph->nodes.push_back(node_index);
result.emplace_back(std::make_unique<ComputeCapability>(std::move(sub_graph)));
}
return IExecutionProvider::GetCapability(graph, kernel_lookup);
snnn marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down