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

Code before:
          past_present_share_buffer->second.i() != 0) {
        continue;
      }
    }

    candidates.push_back(node.Index());
    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 {
  // Cache all 4 combinations to preserve exact flag values for potential future use
  if (enable_graph_capture_ && register_int64_ops_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(true, true);
    return registry;
  } else if (enable_graph_capture_ && !register_int64_ops_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(true, false);
    return registry;
  } else if (!enable_graph_capture_ && register_int64_ops_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(false, true);
    return registry;
  } else {  // !enable_graph_capture_ && !register_int64_ops_
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(false, 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,

Review comment (suggestion):
I think we can make it simpler: we just check `register_int64_ops_`. and when graph capture is on, `register_int64_ops_` should always be true.

not sure if this may cause other issues but in my understanding there is no scenario where `enable_graph_capture_ == true && register_int64_ops_ == false`

Code after:
        continue;
      }
    }

    candidates.push_back(node.Index());
    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 {
  // Cache registries based on enable_graph_capture_ and enable_int64_ flags
  // Note: enable_int64_ is always true when enable_graph_capture_ is true
  if (enable_graph_capture_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(true, true);
    return registry;
  } else if (enable_int64_) {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(false, true);
    return registry;
  } else {
    static std::shared_ptr<KernelRegistry> registry = webgpu::RegisterKernels(false, 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 {
  // NHWC for Resize operator is not implemented on kWebGpuExecutionProvider