Repository: microsoft/onnxruntime
File: onnxruntime/core/providers/webgpu/webgpu_execution_provider.cc (C++)

Code before:
    tenative_candidates.push_back(node.Index());
  }

  auto cpu_nodes = GetCpuPreferredNodes(graph, kernel_lookup, tenative_candidates, *GetLogger());
  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 result;
}

std::shared_ptr<KernelRegistry> WebGpuExecutionProvider::GetKernelRegistry() const {
  // Use different registries based on graph capture configuration
  static std::shared_ptr<KernelRegistry> registry_with_graph_capture;
  static std::shared_ptr<KernelRegistry> registry_without_graph_capture;
  static std::once_flag init_flag_with_graph_capture;
  static std::once_flag init_flag_without_graph_capture;

  if (enable_graph_capture_) {
    std::call_once(init_flag_with_graph_capture, []() {
      registry_with_graph_capture = webgpu::RegisterKernels(true);  // with int64 support
    });
    return registry_with_graph_capture;
  } else {
    std::call_once(init_flag_without_graph_capture, []() {
      registry_without_graph_capture = webgpu::RegisterKernels(false);  // without int64 support
    });
    return registry_without_graph_capture;
  }
}

std::unique_ptr<onnxruntime::IDataTransfer> WebGpuExecutionProvider::GetDataTransfer() const {
  return std::make_unique<webgpu::DataTransfer>(BufferManager());
}

#if defined(__wasm__)
std::unique_ptr<onnxruntime::IExternalDataLoader> WebGpuExecutionProvider::GetExternalDataLoader() const {
  return std::make_unique<webgpu::ExternalDataLoader>();
}
#endif

std::optional<bool> WebGpuExecutionProvider::ShouldConvertDataLayoutForOp(std::string_view node_domain,
                                                                          std::string_view node_op_type,
                                                                          DataLayout target_data_layout) const {
  if (target_data_layout != DataLayout::NHWC) {

Review comment (suggestion):
```suggestion
std::shared_ptr<KernelRegistry> WebGpuExecutionProvider::GetKernelRegistry() const {
  if (enable_graph_capture_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(true);
    return registry;
  } else {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(false);
    return registry;
  }
}
```

Code after:
    tenative_candidates.push_back(node.Index());
  }

  auto cpu_nodes = GetCpuPreferredNodes(graph, kernel_lookup, tenative_candidates, *GetLogger());
  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 result;
}

std::shared_ptr<KernelRegistry> WebGpuExecutionProvider::GetKernelRegistry() const {
  if (enable_graph_capture_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(true);
    return registry;
  } else {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(false);
    return registry;
  }
}

std::unique_ptr<onnxruntime::IDataTransfer> WebGpuExecutionProvider::GetDataTransfer() const {
  return std::make_unique<webgpu::DataTransfer>(BufferManager());
}

#if defined(__wasm__)
std::unique_ptr<onnxruntime::IExternalDataLoader> WebGpuExecutionProvider::GetExternalDataLoader() const {
  return std::make_unique<webgpu::ExternalDataLoader>();
}
#endif

std::optional<bool> WebGpuExecutionProvider::ShouldConvertDataLayoutForOp(std::string_view node_domain,
                                                                          std::string_view node_op_type,
                                                                          DataLayout target_data_layout) const {
  if (target_data_layout != DataLayout::NHWC) {
    return std::nullopt;
  }

  // NHWC for Resize operator is not implemented on kWebGpuExecutionProvider
  if (node_domain == kOnnxDomain && node_op_type == "Resize") {
    return false;
  }

  return std::nullopt;
}