Address performance issue with abseil flat_hash_table. (#10819)

When returning by value in a cross DLL call, the hash table
even though containing all the entries that are originally there
can not find at least some of them. Reverting to std::unordered_set
pending further investigation.
This commit is contained in:
Dmitri Smirnov 2022-03-10 09:49:55 -08:00 committed by GitHub
parent e80ff63274
commit 1d545dfe87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 28 deletions

View file

@ -38,12 +38,12 @@ static bool IsSmallInitializer(const onnxruntime::GraphViewer& graph, const Node
}
} // namespace
InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) {
std::unordered_set<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) {
// automatic conversion from const std::vector&
gsl::span<const NodeIndex> ordered_nodes = graph.GetNodesInTopologicalOrder();
const auto& ordered_nodes = graph.GetNodesInTopologicalOrder();
InlinedVector<size_t> node_id_to_order_map(graph.MaxNodeIndex());
for (size_t id = 0, limit = ordered_nodes.size(); id < limit; ++id) {
const NodeIndex& node_id = ordered_nodes[id];
@ -55,7 +55,7 @@ InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& g
return node_id_to_order_map[n1] > node_id_to_order_map[n2];
};
std::priority_queue<NodeIndex, InlinedVector<NodeIndex>, decltype(greater_order_comp)> candidates(greater_order_comp);
std::priority_queue<NodeIndex, std::vector<NodeIndex>, decltype(greater_order_comp)> candidates(greater_order_comp);
InlinedHashSet<const NodeArg*> cpu_output_args;
@ -95,10 +95,10 @@ InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& g
}));
}
gsl::span<const NodeArg* const> graph_inputs = graph.GetInputs();
const auto& graph_inputs = graph.GetInputs();
InlinedHashSet<NodeIndex> visited;
visited.reserve(candidates.size());
InlinedHashSet<NodeIndex> cpu_nodes;
std::unordered_set<NodeIndex> cpu_nodes;
cpu_nodes.reserve(candidates.size());
// The algo below is trying to identity a subgraph that only depends on cpu tensors.
// Usually it is a subgraph that doing shape calculation based on a GPU tensor, then reshape it back.

View file

@ -18,9 +18,9 @@ namespace onnxruntime {
@param kernel_registries Kernel registries for the target EP
@param tentative_nodes Nodes that are tentative to be placed on on target EP
*/
InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes);
std::unordered_set<NodeIndex> GetCpuPreferredNodes(const GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes);
} // namespace onnxruntime

View file

@ -251,10 +251,10 @@ std::unique_ptr<IAllocator> CreateROCMPinnedAllocator(int16_t device_id, const c
std::unique_ptr<IDataTransfer> CreateGPUDataTransfer(void* stream);
InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes);
std::unordered_set<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes);
std::string GetEnvironmentVar(const std::string& var_name);

View file

@ -347,10 +347,10 @@ std::string GetEnvironmentVar(const std::string& var_name) {
return g_host->GetEnvironmentVar(var_name);
}
InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) {
std::unordered_set<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) {
return g_host->GetCpuPreferredNodes(graph, provider_type, kernel_registries, tentative_nodes);
}

View file

@ -173,10 +173,10 @@ struct ProviderHost {
virtual bool RocmCall_true(int retCode, const char* exprString, const char* libName, int successCode, const char* msg) = 0;
#endif
virtual InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) = 0;
virtual std::unordered_set<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) = 0;
virtual Status UnpackTensor(const ONNX_NAMESPACE::TensorProto& tensor, const void* raw_data, size_t raw_data_len, /*out*/ bool* p_data, size_t expected_size) = 0;
virtual Status UnpackTensor(const ONNX_NAMESPACE::TensorProto& tensor, const void* raw_data, size_t raw_data_len, /*out*/ float* p_data, size_t expected_size) = 0;

View file

@ -207,10 +207,10 @@ struct ProviderHostImpl : ProviderHost {
std::string GetEnvironmentVar(const std::string& var_name) override { return Env::Default().GetEnvironmentVar(var_name); }
InlinedHashSet<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) override {
std::unordered_set<NodeIndex> GetCpuPreferredNodes(const onnxruntime::GraphViewer& graph,
const std::string& provider_type,
gsl::span<const KernelRegistry* const> kernel_registries,
gsl::span<const NodeIndex> tentative_nodes) override {
return onnxruntime::GetCpuPreferredNodes(graph, provider_type, kernel_registries, tentative_nodes);
}