未验证 提交 ec8ef528 编写于 作者: T T8T9 提交者: GitHub

[Libsize] Reduce size of dynamic library ".so" (#3717)

* reduce .so size. test=develop

* compile all targets when LITE_ON_TINY_PUBLISH=OFF

* unordered_map is more convenient when key is customized class

* test=develop
上级 a95ffa03
......@@ -163,7 +163,7 @@ void Run(const std::vector<int64_t>& input_shape,
auto end = GetCurrentUS();
perf_vct.push_back((end - start) / 1000.0);
}
std::sort(perf_vct.begin(), perf_vct.end());
std::stable_sort(perf_vct.begin(), perf_vct.end());
float min_res = perf_vct.back();
float max_res = perf_vct.front();
float total_res = accumulate(perf_vct.begin(), perf_vct.end(), 0.0);
......
......@@ -14,7 +14,7 @@
#include "lite/api/light_api.h"
#include <algorithm>
#include <unordered_map>
#include <map>
#include "paddle_use_kernels.h" // NOLINT
#include "paddle_use_ops.h" // NOLINT
......
......@@ -371,7 +371,7 @@ void CheckIfModelSupported() {
for (size_t i = 0; i < valid_places.size(); i++) {
targets.push_back(valid_places[i].target);
}
std::sort(targets.begin(), targets.end());
std::stable_sort(targets.begin(), targets.end());
targets.erase(unique(targets.begin(), targets.end()), targets.end());
std::string targets_str = TargetToStr(targets[0]);
for (size_t i = 1; i < targets.size(); i++) {
......
......@@ -435,7 +435,7 @@ void OptBase::CheckIfModelSupported(bool print_ops_info) {
for (size_t i = 0; i < valid_places_.size(); i++) {
targets.push_back(valid_places_[i].target);
}
std::sort(targets.begin(), targets.end());
std::stable_sort(targets.begin(), targets.end());
targets.erase(unique(targets.begin(), targets.end()), targets.end());
std::string targets_str = TargetToStr(targets[0]);
for (size_t i = 1; i < targets.size(); i++) {
......
......@@ -19,8 +19,8 @@
#include <iostream>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/backends/apu/neuron_adapter.h"
......
......@@ -109,9 +109,9 @@ class LoDTensor2BatchFunctor {
seq_info.emplace_back(lod[seq_id], length, seq_id);
}
std::sort(seq_info.begin(), seq_info.end(), [](SeqInfo a, SeqInfo b) {
return a.length > b.length;
});
std::stable_sort(seq_info.begin(),
seq_info.end(),
[](SeqInfo a, SeqInfo b) { return a.length > b.length; });
// Calculate the start position of each batch.
// example: sequences = {s0, s1, s2}
......
......@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once
#include <algorithm>
#include <unordered_map>
#include <map>
#include <vector>
namespace paddle {
......@@ -45,7 +45,7 @@ class AlgorithmsCache {
std::function<TAlgorithm()> gen_func);
private:
std::unordered_map<int64_t, TAlgorithm> hash_;
std::map<int64_t, TAlgorithm> hash_;
int search_times_;
};
......
......@@ -14,8 +14,8 @@
#pragma once
#include <map>
#include <string>
#include <unordered_map>
#include "lite/core/tensor.h"
......@@ -38,7 +38,7 @@ class Debugger {
}
private:
std::unordered_map<std::string, bool> op_config;
std::map<std::string, bool> op_config;
Debugger() {
op_config["concat"] = true;
op_config["pooling"] = true;
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "HiAiModelManagerService.h" // NOLINT
#include "hiai_ir_build.h" // NOLINT
......
......@@ -17,7 +17,6 @@ limitations under the License. */
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/backends/opencl/cl_image.h"
#include "lite/backends/opencl/cl_include.h"
......@@ -74,7 +73,7 @@ class CLContext {
// size_t max_work_size);
private:
std::unordered_map<std::string, std::unique_ptr<cl::Program>> programs_;
std::map<std::string, std::unique_ptr<cl::Program>> programs_;
std::vector<std::shared_ptr<cl::Kernel>> kernels_;
std::map<std::string, int> kernel_offset_;
};
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "rknpu/rknpu_pub.h" // NOLINT
......
......@@ -15,8 +15,8 @@
#pragma once
#include <iostream>
#include <map>
#include <string>
#include <unordered_map>
#include <utility> // for std::move
#include <vector>
#include "lite/backends/x86/jit/gen_base.h"
......@@ -208,7 +208,7 @@ class KernelFuncs {
}
private:
std::unordered_map<int64_t, typename KernelTuple::func_type> funcs_;
std::map<int64_t, typename KernelTuple::func_type> funcs_;
};
const char* to_string(KernelType kt);
......
......@@ -13,9 +13,9 @@
* limitations under the License. */
#include "lite/backends/x86/jit/kernel_pool.h"
#include <map>
#include <memory> // for shared_ptr
#include <string>
#include <unordered_map>
namespace paddle {
namespace lite {
......
......@@ -14,7 +14,7 @@ limitations under the License. */
#pragma once
#include <iostream>
#include <unordered_set>
#include <set>
#include <vector>
#include "lite/backends/x86/math/sampler.h"
#include "lite/core/context.h"
......@@ -65,7 +65,7 @@ class SampleWithProb {
auto* probabilities_data = P->template mutable_data<T>(Target);
// temp sets for unique sampling
std::unordered_set<int64_t> tmp_samples;
std::set<int64_t> tmp_samples;
int j = 0; // column index
// add true labels, not that efficient
while (j < num_true) {
......
......@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include "lite/backends/x86/math/blas.h"
#include "lite/backends/x86/math/selected_rows_functor.h"
......@@ -329,14 +329,14 @@ struct MergeAdd<lite::TargetType::kX86, T> {
merged_row_set.end());
if (sorted_result) {
std::sort(merge_rows.begin(), merge_rows.end());
std::stable_sort(merge_rows.begin(), merge_rows.end());
}
out.set_rows(merge_rows);
math::SetConstant<lite::TargetType::kX86, T> constant_functor;
constant_functor(context, out.mutable_value(), 0.0);
std::unordered_map<int64_t, size_t> rows_to_id;
std::map<int64_t, size_t> rows_to_id;
for (size_t i = 0; i < merge_rows.size(); ++i) {
rows_to_id[merge_rows[i]] = i;
}
......
......@@ -92,9 +92,9 @@ class LoDTensor2BatchFunctor {
seq_info[seq_id].seq_idx = seq_id;
}
std::sort(seq_info.begin(), seq_info.end(), [](SeqInfo a, SeqInfo b) {
return a.length > b.length;
});
std::stable_sort(seq_info.begin(),
seq_info.end(),
[](SeqInfo a, SeqInfo b) { return a.length > b.length; });
// Calculate the start position of each batch.
// example: sequences = {s0, s1, s2}
......
......@@ -23,7 +23,7 @@ namespace math {
std::vector<TreeNode> Tree2ColUtil::construct_patch(
size_t root, int max_depth, const std::vector<std::vector<int>> &tr) {
std::stack<TreeNode, std::deque<TreeNode>> stack;
std::unordered_map<int, bool> visited;
std::map<int, bool> visited;
std::vector<TreeNode> patch;
stack.push(TreeNode(root, 1, 1, 0));
......
......@@ -15,7 +15,7 @@
#pragma once
#include <array>
#include <unordered_map>
#include <map>
#include <vector>
#include "lite/backends/x86/math/math_function.h"
#include "lite/core/context.h"
......
......@@ -19,9 +19,9 @@
#include <chrono> // NOLINT
#include <cmath>
#include <iomanip>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/op_registry.h"
......
......@@ -19,7 +19,6 @@
#include "lite/backends/cuda/context.h"
#endif
#ifdef LITE_WITH_OPENCL
#include <unordered_map>
#include "lite/backends/opencl/cl_context.h"
#include "lite/backends/opencl/cl_runtime.h"
#endif
......
......@@ -19,8 +19,8 @@
*/
#pragma once
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/utils/cp_logging.h"
#include "lite/utils/replace_stl/stream.h"
......@@ -157,7 +157,7 @@ class Dot {
}
private:
std::unordered_map<std::string, Node> nodes_;
std::map<std::string, Node> nodes_;
std::vector<Edge> edges_;
std::vector<Attr> attrs_;
};
......
......@@ -461,12 +461,12 @@ class XPUMultiEncoderFuser {
}
}
std::unordered_set<const Node*> to_remove;
std::set<const Node*> to_remove;
Node* first_encoder = all_encoders[0];
std::string in_name, out_name;
std::vector<std::string> arg_names{
"FCWeight", "FCBias", "LNScale", "LNBias"};
std::unordered_map<std::string, std::vector<std::string>> arg_map;
std::map<std::string, std::vector<std::string>> arg_map;
for (size_t i = 0; i < all_encoders.size(); ++i) {
Node* cur_encoder = all_encoders[i];
auto* op_info = cur_encoder->stmt()->op_info();
......@@ -589,7 +589,7 @@ class XPUMultiEncoderFuser {
}
}
if (stack) {
std::unordered_set<const Node*> to_remove2;
std::set<const Node*> to_remove2;
Node* stack_out = stack->outlinks.front();
// avoid modification while traversing
auto stack_out_outlinks = stack_out->outlinks;
......
......@@ -14,7 +14,7 @@
#include "lite/core/mir/fusion/conv_bn_fuser.h"
#include <memory>
#include <unordered_set>
#include <set>
#include <vector>
namespace paddle {
......
......@@ -15,8 +15,8 @@
#pragma once
#include <memory>
#include <set>
#include <string>
#include <unordered_set>
#include "lite/core/mir/pass.h"
namespace paddle {
......
......@@ -14,7 +14,7 @@
#include "lite/core/mir/fusion/quant_dequant_op_fuser.h"
#include <memory>
#include <unordered_set>
#include <set>
#include <vector>
#include "lite/utils/string.h"
......@@ -78,7 +78,7 @@ void DeleteQuantOpFuser::InsertNewNode(SSAGraph* graph,
}
// delete nodes and edges
std::unordered_set<const Node*> nodes2rm = {
std::set<const Node*> nodes2rm = {
input_scale_node, quant_node, output_scale_node, output_act_node};
GraphSafeRemoveNodes(graph, nodes2rm);
}
......@@ -365,7 +365,7 @@ void DeleteQuantDequantOpFuser::InsertNewNode(SSAGraph* graph,
IR_NODE_LINK_TO(input_act_node, quantized_node);
}
// delete nodes and edges
std::unordered_set<const Node*> nodes2rm = {
std::set<const Node*> nodes2rm = {
input_scale_node, quant_dequant_node, output_scale_node, output_act_node};
GraphSafeRemoveNodes(graph, nodes2rm);
}
......
......@@ -28,12 +28,11 @@ typedef struct {
std::string name;
int cluster;
std::pair<int, int> lifetime;
std::unordered_set<std::string> adj;
std::set<std::string> adj;
} MemNode;
void MemoryOptimizePass::CollectLifeCycleByDevice(
std::unordered_map<std::string, lifecycle_map_t>* lifecycles,
SSAGraph* graph) {
std::map<std::string, lifecycle_map_t>* lifecycles, SSAGraph* graph) {
max_lifecycle_ = 0;
auto is_host = [](TargetType x) -> bool {
......@@ -41,22 +40,22 @@ void MemoryOptimizePass::CollectLifeCycleByDevice(
};
// The all of input and output variables of the Ops will not be reused.
std::unordered_set<std::string> invalid_op_nodes = {"while",
"conditional_block",
"conditional_block_infer",
"merge_lod_tensor_infer",
"merge_lod_tensor",
"equal",
"lod_reset",
"concat",
"yolo_box",
"subgraph",
"feed",
"fetch"};
std::set<std::string> invalid_op_nodes = {"while",
"conditional_block",
"conditional_block_infer",
"merge_lod_tensor_infer",
"merge_lod_tensor",
"equal",
"lod_reset",
"concat",
"yolo_box",
"subgraph",
"feed",
"fetch"};
auto insert_invalid_op_nodes_for_specific_target = [&](
std::unordered_set<std::string> op_node_set, TargetType specific_target) {
std::unordered_set<std::string> invalid_op_nodes_opencl = {"layout", "fc"};
std::set<std::string> op_node_set, TargetType specific_target) {
std::set<std::string> invalid_op_nodes_opencl = {"layout", "fc"};
for (auto& op_node : graph->StmtTopologicalOrder()) {
if (!op_node->IsStmt()) continue;
TargetType op_target_type = op_node->AsStmt().place().target;
......@@ -76,7 +75,7 @@ void MemoryOptimizePass::CollectLifeCycleByDevice(
VLOG(4) << "invalid_op_nodes.size();" << invalid_op_nodes.size();
// Collect the invalid input and output variables that will not be reused.
std::unordered_set<std::string> invalid_var_names;
std::set<std::string> invalid_var_names;
for (auto& op_node : graph->StmtTopologicalOrder()) {
// variables of invalid_op_nodes wil not be reused
if (!op_node->IsStmt()) continue;
......@@ -97,9 +96,8 @@ void MemoryOptimizePass::CollectLifeCycleByDevice(
// The specified input and output variables of the Ops whose 'inplace' attr
// is true will not be reused, such as reshape/reshape2's X and Out
// variables
std::unordered_map<std::string,
std::pair<std::unordered_set<std::string>,
std::unordered_set<std::string>>>
std::map<std::string,
std::pair<std::set<std::string>, std::set<std::string>>>
inplace_op_nodes = {{"reshape", {{"X"}, {"Out"}}},
{"reshape2", {{"X"}, {"Out"}}}};
auto inplace_op_node = inplace_op_nodes.find(op_type);
......@@ -162,7 +160,7 @@ void MemoryOptimizePass::CollectLifeCycleByDevice(
void MemoryOptimizePass::MakeReusePlan(
const lifecycle_map_t& lifecycles,
std::unordered_map<std::string, std::string>* node2cluster) {
std::map<std::string, std::string>* node2cluster) {
std::vector<MemNode> mem_nodes;
std::vector<std::string> cluster;
for (auto& data : lifecycles) {
......@@ -193,7 +191,7 @@ void MemoryOptimizePass::MakeReusePlan(
mem_nodes[i].cluster = cluster_index;
(*node2cluster)[mem_nodes[i].name] = mem_nodes[i].name;
cluster.push_back(mem_nodes[i].name);
std::unordered_set<std::string> cluster_adj = mem_nodes[i].adj;
std::set<std::string> cluster_adj = mem_nodes[i].adj;
for (size_t j = i + 1; j < mem_nodes.size(); j++) {
if (mem_nodes[j].cluster < 0 &&
(cluster_adj.find(mem_nodes[j].name) == cluster_adj.end())) {
......@@ -211,14 +209,13 @@ void MemoryOptimizePass::MakeReusePlan(
}
void MemoryOptimizePass::PerformReusePlan(
SSAGraph* graph,
const std::unordered_map<std::string, std::string>& reuse_table) {
SSAGraph* graph, const std::map<std::string, std::string>& reuse_table) {
int node_append_idx = 0;
for (auto& op_node : graph->StmtTopologicalOrder()) {
if (!op_node->IsStmt()) continue;
auto& stmt = op_node->AsStmt();
auto* op_info = stmt.mutable_op_info();
std::unordered_map<std::string, std::vector<std::string>> in_args, out_args;
std::map<std::string, std::vector<std::string>> in_args, out_args;
// replace the op's input according the reuse table.
for (auto argument : op_info->inputs()) {
for (const auto& x : argument.second) {
......@@ -298,10 +295,10 @@ void MemoryOptimizePass::Apply(const std::unique_ptr<SSAGraph>& graph) {
// name of var and the value in the table represents the current name of var.
// 3. Perform reuse plan: Replace all var's name in the model according to the
// mapping table.
std::unordered_map<std::string, lifecycle_map_t> lifecycles;
std::map<std::string, lifecycle_map_t> lifecycles;
CollectLifeCycleByDevice(&lifecycles, graph.get());
for (auto& ele : lifecycles) {
std::unordered_map<std::string, std::string> node2cluster;
std::map<std::string, std::string> node2cluster;
MakeReusePlan(ele.second, &node2cluster);
PerformReusePlan(graph.get(), node2cluster);
}
......
......@@ -17,11 +17,10 @@
#include <algorithm>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
......@@ -38,18 +37,16 @@ namespace mir {
class MemoryOptimizePass : public ProgramPass {
public:
using lifecycle_t = std::pair<int, int>;
using lifecycle_map_t = std::unordered_map<std::string, lifecycle_t>;
using lifecycle_map_t = std::map<std::string, lifecycle_t>;
void Apply(const std::unique_ptr<SSAGraph>& graph) override;
private:
void CollectLifeCycleByDevice(
std::unordered_map<std::string, lifecycle_map_t>* lifecycles, SSAGraph*);
void MakeReusePlan(
const lifecycle_map_t& lifecycles,
std::unordered_map<std::string, std::string>* node2cluster);
void PerformReusePlan(
SSAGraph* graph,
const std::unordered_map<std::string, std::string>& reuse_table);
std::map<std::string, lifecycle_map_t>* lifecycles, SSAGraph*);
void MakeReusePlan(const lifecycle_map_t& lifecycles,
std::map<std::string, std::string>* node2cluster);
void PerformReusePlan(SSAGraph* graph,
const std::map<std::string, std::string>& reuse_table);
private:
int max_lifecycle_{-1};
......
......@@ -126,7 +126,7 @@ void MultiStreamAnalysisPass::Init(SSAGraph* graph) {
}
bool MultiStreamAnalysisPass::CheckOpSupport() {
std::unordered_set<std::string> invalid_op = {
std::set<std::string> invalid_op = {
"while", "conditional_block", "conditional_block_infer", "graph_op"};
for (auto& op_type : op_types_set_) {
if (invalid_op.count(op_type)) {
......
......@@ -15,11 +15,11 @@
#pragma once
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
......@@ -73,11 +73,11 @@ class MultiStreamAnalysisPass : public StmtPass {
std::queue<Node*> exec_que_;
std::vector<Node*> exec_ops_;
std::vector<std::vector<Node*>> ops_in_streams_;
std::unordered_map<std::string, bool> resources_;
std::unordered_map<std::string, int> map_arg_to_lane_;
std::map<std::string, bool> resources_;
std::map<std::string, int> map_arg_to_lane_;
int max_stream_;
int io_copy_once_num_;
std::unordered_set<std::string> op_types_set_;
std::set<std::string> op_types_set_;
};
} // namespace mir
......
......@@ -13,10 +13,10 @@
// limitations under the License.
#pragma once
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/mir/node.h"
......@@ -97,13 +97,12 @@ class Pass {
// explicitly declared.
// Bind kernels. All kernels bound at runtime must be registered.
void BindKernels(
const std::unordered_map<std::string, std::set<lite_api::Place>>&
kernels) {
const std::map<std::string, std::set<lite_api::Place>>& kernels) {
bound_kernels_ = kernels;
}
// Get all bound kernels.
const std::unordered_map<std::string, std::set<lite_api::Place>>&
GetBoundKernels() const {
const std::map<std::string, std::set<lite_api::Place>>& GetBoundKernels()
const {
return bound_kernels_;
}
// Add one kernel to the bound kernels.
......@@ -150,9 +149,8 @@ class Pass {
std::string doc_;
std::set<TargetType> bound_targets_;
std::set<TargetType> excluded_targets_;
std::unordered_map<std::string, std::set<lite_api::Place>> bound_kernels_;
std::unordered_map<std::string, variant<Node, std::vector<Node*>>>
pass_attrs_;
std::map<std::string, std::set<lite_api::Place>> bound_kernels_;
std::map<std::string, variant<Node, std::vector<Node*>>> pass_attrs_;
};
// Different kinds.
......
......@@ -13,9 +13,9 @@
// limitations under the License.
#include "lite/core/mir/pass_utils.h"
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include "lite/core/op_registry.h"
namespace paddle {
......
......@@ -146,7 +146,7 @@ void PatternMatcher::ValidateByNodeRole(
subgraphs->end(),
[](const PatternMatcher::subgraph_t &subgraph) -> bool {
// Collect the inlinks and outlinks.
std::unordered_set<Node *> ios;
std::set<Node *> ios;
for (auto &item : subgraph) {
ios.insert(item.second);
}
......@@ -170,7 +170,7 @@ void PatternMatcher::ValidateByNodeRole(
}
struct HitGroup {
std::unordered_map<PMNode *, Node *> roles;
std::map<PMNode *, Node *> roles;
bool Match(Node *node, PMNode *pat) {
if (nodes_.count(node)) {
......@@ -188,7 +188,7 @@ struct HitGroup {
}
private:
std::unordered_set<Node *> nodes_;
std::set<Node *> nodes_;
};
// Tell whether Node a links to b.
......@@ -279,12 +279,13 @@ void PatternMatcher::UniquePatterns(
if (subgraphs->empty()) return;
std::vector<PatternMatcher::subgraph_t> result;
std::unordered_set<size_t> set;
std::set<size_t> set;
std::hash<std::string> hasher;
for (auto &g : *subgraphs) {
// Sort the items in the sub-graph, and transform to a string key.
std::vector<std::pair<PMNode *, Node *>> sorted_keys(g.begin(), g.end());
std::sort(sorted_keys.begin(), sorted_keys.end(), GraphItemLessThan());
std::stable_sort(
sorted_keys.begin(), sorted_keys.end(), GraphItemLessThan());
STL::stringstream ss;
for (auto &item : sorted_keys) {
ss << reinterpret_cast<size_t>(item.first) << ":"
......@@ -301,7 +302,7 @@ void PatternMatcher::UniquePatterns(
void PatternMatcher::RemoveOverlappedMatch(std::vector<subgraph_t> *subgraphs) {
std::vector<subgraph_t> result;
std::unordered_set<Node *> node_set;
std::set<Node *> node_set;
for (const auto &subgraph : *subgraphs) {
bool valid = true;
......@@ -325,7 +326,7 @@ std::string PMPattern::DotString() const {
Dot dot;
int id = 0;
// Create Nodes
std::unordered_map<PMNode *, std::string> node2dot;
std::map<PMNode *, std::string> node2dot;
for (const auto &node : nodes()) {
std::string node_id = string_format("Node%d", id++);
dot.AddNode(node_id, {}, node->name());
......@@ -519,7 +520,7 @@ bool HasInput(const Node &op, const std::string &argument) {
}
void GraphSafeRemoveNodes(SSAGraph *graph,
const std::unordered_set<const Node *> &nodes) {
const std::set<const Node *> &nodes) {
for (auto *node : nodes) {
graph->RemoveNode(node);
}
......
......@@ -18,11 +18,11 @@
#include <gtest/gtest_prod.h>
#endif
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "lite/core/mir/node.h"
......@@ -254,7 +254,7 @@ class PMPattern {
std::vector<std::unique_ptr<PMNode>> nodes_;
std::vector<edge_t> edges_;
std::unordered_map<std::string, PMNode*> node_map_;
std::map<std::string, PMNode*> node_map_;
static size_t id_;
};
......@@ -286,7 +286,7 @@ class PMPattern {
*/
class PatternMatcher {
public:
using subgraph_t = std::unordered_map<PMNode*, Node*>;
using subgraph_t = std::map<PMNode*, Node*>;
// Operate on the detected pattern.
using handle_t =
......@@ -324,7 +324,7 @@ class PatternMatcher {
using hit_rcd_t =
std::pair<Node* /*node in graph*/, PMNode* /*node in pattern*/>;
PMPattern pattern_;
std::unordered_map<const PMNode*, std::unordered_set<Node*>> pmnodes2nodes_;
std::map<const PMNode*, std::set<Node*>> pmnodes2nodes_;
};
// Check whether a var node is a op node's nth input.
......@@ -337,8 +337,7 @@ bool IsNthInput(const Node& var,
bool HasInput(const Node& op, const std::string& argument);
// Graph safely remove some nodes, will automatically clean up the edges.
void GraphSafeRemoveNodes(SSAGraph* graph,
const std::unordered_set<const Node*>& nodes);
void GraphSafeRemoveNodes(SSAGraph* graph, const std::set<const Node*>& nodes);
// Some pre-defined patterns those can be reused in multiple passes.
// The related Fluid Layer or Op should be one pattern here for better re-usage
......@@ -354,7 +353,7 @@ struct KeyCounter {
int IncCounter(const std::string& key) { return dic_[key]++; }
private:
std::unordered_map<std::string, size_t> dic_;
std::map<std::string, size_t> dic_;
};
// Generate a unique PMNode's name with name_scope and id.
......
......@@ -42,7 +42,7 @@ void FuseBase::DeleteInterNodes(SSAGraph *graph) {
}
VLOG(4) << "keys: " << key2nodes_.size();
std::unordered_set<const Node *> nodes2rm;
std::set<const Node *> nodes2rm;
for (auto &matched : key2nodes_) {
for (const auto &key : keys) {
nodes2rm.insert(matched.at(key));
......
......@@ -16,8 +16,6 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "lite/core/mir/node.h"
......
......@@ -15,9 +15,9 @@
#include "lite/core/mir/quantized_op_attributes_inference_pass.h"
#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/mir/graph_visualize_pass.h"
......
......@@ -15,9 +15,9 @@
#pragma once
#include <limits>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/mir/pass.h"
#include "lite/core/types.h"
......
......@@ -14,9 +14,9 @@
#include "lite/core/mir/ssa_graph.h"
#include <algorithm>
#include <map>
#include <memory>
#include <set>
#include <unordered_map>
#include <utility>
namespace paddle {
......@@ -55,9 +55,10 @@ std::map<mir::Node *, std::set<mir::Node *>> SSAGraph::BuildOperationAdjList() {
nodes.push_back(adj_n);
}
}
std::sort(nodes.begin(),
nodes.end(),
[](mir::Node *node1, mir::Node *node2) { return node1 > node2; });
std::stable_sort(
nodes.begin(), nodes.end(), [](mir::Node *node1, mir::Node *node2) {
return node1 > node2;
});
adj_list[&n].insert(std::make_move_iterator(nodes.begin()),
std::make_move_iterator(nodes.end()));
}
......@@ -75,9 +76,10 @@ std::map<mir::Node *, std::set<mir::Node *>> SSAGraph::BuildNodeAdjList() {
for (auto &var : n.inlinks) {
nodes.push_back(var);
}
std::sort(nodes.begin(),
nodes.end(),
[](mir::Node *node1, mir::Node *node2) { return node1 > node2; });
std::stable_sort(
nodes.begin(), nodes.end(), [](mir::Node *node1, mir::Node *node2) {
return node1 > node2;
});
adj_list[&n].insert(std::make_move_iterator(nodes.begin()),
std::make_move_iterator(nodes.end()));
}
......@@ -161,10 +163,9 @@ void SSAGraph::Build(const Program &program,
return true;
};
std::unordered_map<std::string, PrecisionType> var_types =
program.var_data_type();
std::map<std::string, PrecisionType> var_types = program.var_data_type();
std::unordered_map<std::string, mir::Node *> arg_update_node_map_;
std::map<std::string, mir::Node *> arg_update_node_map_;
for (auto &op : program.ops()) {
VLOG(3) << op->op_info()->Type();
auto *op_node = GraphCreateInstructNode(op, valid_places);
......
......@@ -15,9 +15,9 @@
#include "lite/core/mir/static_kernel_pick_pass.h"
#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/mir/graph_visualize_pass.h"
......@@ -46,8 +46,8 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
if (!node.IsStmt()) continue;
auto& instruct = node.AsStmt();
std::unordered_map<std::string, PrecisionType> in_types;
std::unordered_map<std::string, PrecisionType> out_types;
std::map<std::string, PrecisionType> in_types;
std::map<std::string, PrecisionType> out_types;
for (std::list<Node*>::iterator i = node.inlinks.begin();
i != node.inlinks.end();
++i) {
......@@ -77,7 +77,7 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
<< " score:" << score;
scored.emplace_back(score, std::move(kernel));
}
std::sort(scored.begin(), scored.end(), KernelScoreCmp);
std::stable_sort(scored.begin(), scored.end(), KernelScoreCmp);
instruct.kernels().clear();
if (!instruct.op_info()->HasAttr("enable_int8")) {
......@@ -131,7 +131,7 @@ void StaticKernelPickPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
instruct.op_info()->output_names());
scored.emplace_back(score, std::move(kernel));
}
std::sort(scored.begin(), scored.end(), KernelScoreCmp);
std::stable_sort(scored.begin(), scored.end(), KernelScoreCmp);
instruct.kernels().clear();
}
// If the out_type_int8 is true, we should pick the kernel with the
......
......@@ -15,9 +15,9 @@
#pragma once
#include <limits>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/mir/pass.h"
#include "lite/core/types.h"
......@@ -50,14 +50,13 @@ class StaticKernelPickPass : public mir::StmtPass {
private:
// Score the kernel.
size_t KernelGrade(
const lite::mir::Node::Stmt& instruct,
const lite::KernelBase& kernel,
const std::vector<Place>& places,
const std::unordered_map<std::string, PrecisionType>& in_types,
const std::unordered_map<std::string, PrecisionType>& out_types,
const std::vector<std::string>& in_names,
const std::vector<std::string>& out_names) {
size_t KernelGrade(const lite::mir::Node::Stmt& instruct,
const lite::KernelBase& kernel,
const std::vector<Place>& places,
const std::map<std::string, PrecisionType>& in_types,
const std::map<std::string, PrecisionType>& out_types,
const std::vector<std::string>& in_names,
const std::vector<std::string>& out_names) {
CHECK_GT(places.size(), static_cast<size_t>(0)) << "valid_places is empty.";
float final_score{-1.};
Place winner_place{places[0]};
......
......@@ -15,7 +15,6 @@
#include "lite/core/mir/subgraph/subgraph_detector.h"
#include <memory>
#include <set>
#include <unordered_set>
#include <utility>
#include <vector>
#include "lite/core/mir/dot.h"
......@@ -46,13 +45,13 @@ std::string SubgraphVisualizer::operator()() {
"khaki1", "ivory4", "sandybrown", "olivedrab2",
"turquoise4", "snow3", "sienna4", "salmon2",
};
std::unordered_map<Node *, int> subgraph_indices;
std::map<Node *, int> subgraph_indices;
for (size_t i = 0; i < subgraphs_.size(); i++) {
for (size_t j = 0; j < subgraphs_[i].size(); j++) {
subgraph_indices[subgraphs_[i][j]] = i;
}
}
std::unordered_map<std::string, int> exists_ops;
std::map<std::string, int> exists_ops;
std::set<std::string> exists_args;
for (auto &node : graph_->StmtTopologicalOrder()) {
if (!node->IsStmt()) {
......@@ -125,9 +124,9 @@ void SubgraphDetector::node_dat_t::UnionFindCombine(node_dat_t *candidate) {
candidate->union_find_parent = union_find_parent;
// Obtain the input and output nodes for the combined one
std::unordered_set<node_dat_t *> inputs(inlinks.begin(), inlinks.end());
std::unordered_set<node_dat_t *> outputs(candidate->outlinks.begin(),
candidate->outlinks.end());
std::set<node_dat_t *> inputs(inlinks.begin(), inlinks.end());
std::set<node_dat_t *> outputs(candidate->outlinks.begin(),
candidate->outlinks.end());
for (auto *out_node : outlinks) {
if (out_node != candidate) {
outputs.insert(out_node);
......@@ -185,7 +184,7 @@ void SubgraphDetector::FlexibleDFS(
for (auto &node : source) {
stack.push_back(std::pair<const node_dat_t *, bool>(node, false));
}
std::unordered_set<const node_dat_t *> visited;
std::set<const node_dat_t *> visited;
while (!stack.empty()) {
auto top = stack.back();
stack.pop_back();
......@@ -210,9 +209,9 @@ void SubgraphDetector::FlexibleDFS(
}
}
std::unordered_set<Node *> SubgraphDetector::GetExcludedNodesFromConfigFile() {
std::set<Node *> SubgraphDetector::GetExcludedNodesFromConfigFile() {
// get exclude nodes from config file
std::unordered_set<Node *> excluded_nodes;
std::set<Node *> excluded_nodes;
std::string config_file_path =
GetStringFromEnv(SUBGRAPH_CUSTOM_PARTITION_CONFIG_FILE);
if (!IsFileExists(config_file_path)) {
......@@ -285,7 +284,7 @@ std::unordered_set<Node *> SubgraphDetector::GetExcludedNodesFromConfigFile() {
void SubgraphDetector::InitNodes(node_map_t *nodes) {
// Initialize and mark the subgraph detector nodes based on teller.
std::unordered_set<Node *> excluded_nodes = GetExcludedNodesFromConfigFile();
std::set<Node *> excluded_nodes = GetExcludedNodesFromConfigFile();
for (auto &it : *nodes) {
for (auto &in_node : it.first->inlinks) {
it.second->inlinks.push_back((*nodes)[in_node]);
......@@ -337,7 +336,7 @@ std::vector<std::vector<Node *>> SubgraphDetector::ExtractSubgraphs(
// then the src and dst nodes can not be fused into one node,
// otherwise it can be done.
while (true) {
std::unordered_set<node_dat_t *> contract_nodes;
std::set<node_dat_t *> contract_nodes;
for (auto *out_node : node->outlinks) {
// must be an candidate
if (!out_node->marked) continue;
......@@ -372,7 +371,7 @@ std::vector<std::vector<Node *>> SubgraphDetector::ExtractSubgraphs(
}
}
std::unordered_map<node_dat_t * /*ancestor*/, std::vector<Node *>> clusters;
std::map<node_dat_t * /*ancestor*/, std::vector<Node *>> clusters;
for (auto &node : graph_->StmtTopologicalOrder()) {
if (!node->IsStmt()) continue;
if ((*nodes)[node]->marked) {
......@@ -426,11 +425,11 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph,
subgraph_op_desc.SetAttr<int32_t>("sub_block", sub_block_idx);
// Extract input and output nodes from the target subgraph
std::unordered_set<Node *> input_var_nodes;
std::unordered_set<Node *> weight_var_nodes;
std::unordered_set<Node *> output_var_nodes;
std::unordered_set<Node *> local_var_nodes;
std::unordered_set<Node *> unused_var_nodes;
std::set<Node *> input_var_nodes;
std::set<Node *> weight_var_nodes;
std::set<Node *> output_var_nodes;
std::set<Node *> local_var_nodes;
std::set<Node *> unused_var_nodes;
ExtractInputsOutputs(subgraph_nodes,
&input_var_nodes,
&weight_var_nodes,
......@@ -551,11 +550,11 @@ void SubgraphFuser::operator()() {
}
void ExtractInputsOutputs(const std::vector<Node *> &op_nodes,
std::unordered_set<Node *> *input_var_nodes,
std::unordered_set<Node *> *weight_var_nodes,
std::unordered_set<Node *> *output_var_nodes,
std::unordered_set<Node *> *local_var_nodes,
std::unordered_set<Node *> *unused_var_nodes) {
std::set<Node *> *input_var_nodes,
std::set<Node *> *weight_var_nodes,
std::set<Node *> *output_var_nodes,
std::set<Node *> *local_var_nodes,
std::set<Node *> *unused_var_nodes) {
for (auto &op_node : op_nodes) {
for (auto &var_node : op_node->inlinks) {
if (var_node->AsArg().is_weight) {
......@@ -597,10 +596,10 @@ void ExtractInputsOutputs(const std::vector<Node *> &op_nodes,
}
}
std::unordered_set<const Node *> GetNodes2RM(
std::set<const Node *> GetNodes2RM(
const std::vector<Node *> &op_nodes,
const std::vector<std::unordered_set<Node *>> &excluded_var_nodes) {
std::unordered_set<const Node *> nodes2rm(op_nodes.begin(), op_nodes.end());
const std::vector<std::set<Node *>> &excluded_var_nodes) {
std::set<const Node *> nodes2rm(op_nodes.begin(), op_nodes.end());
for (auto &op_node : op_nodes) {
for (auto &var_node : op_node->inlinks) {
if (!nodes2rm.count(var_node)) {
......@@ -625,8 +624,8 @@ std::unordered_set<const Node *> GetNodes2RM(
}
static void SortHelper(Node *node,
const std::unordered_set<Node *> &unordered_nodes,
std::unordered_set<const Node *> *visited_nodes,
const std::set<Node *> &unordered_nodes,
std::set<const Node *> *visited_nodes,
std::vector<Node *> *ordered_nodes) {
for (auto &var_node : node->inlinks) {
if (var_node->inlinks.empty()) continue;
......@@ -640,8 +639,8 @@ static void SortHelper(Node *node,
}
std::vector<Node *> GetTopologicalOrder(
const std::unordered_set<Node *> &unordered_nodes) {
std::unordered_set<const Node *> visited_nodes;
const std::set<Node *> &unordered_nodes) {
std::set<const Node *> visited_nodes;
std::vector<Node *> ordered_nodes;
for (auto &node : unordered_nodes) {
if (!node->IsStmt()) continue;
......
......@@ -16,9 +16,8 @@
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "lite/core/mir/pass.h"
......@@ -51,7 +50,7 @@ class SubgraphDetector {
// pointer of the Node. This is to avoid changing the original graph in the
// process of graph analysis.
struct node_dat_t;
using node_map_t = std::unordered_map<Node*, node_dat_t*>;
using node_map_t = std::map<Node*, node_dat_t*>;
using node_set_t = std::vector<node_dat_t*>;
struct node_dat_t {
explicit node_dat_t(Node* _node) : node(_node) {}
......@@ -73,7 +72,7 @@ class SubgraphDetector {
const std::function<bool(const node_dat_t*)>& enter,
const std::function<bool(const node_dat_t*)>& leave);
std::unordered_set<Node*> GetExcludedNodesFromConfigFile();
std::set<Node*> GetExcludedNodesFromConfigFile();
void InitNodes(node_map_t* nodes);
......@@ -114,18 +113,17 @@ class SubgraphFuser {
};
void ExtractInputsOutputs(const std::vector<Node*>& op_nodes,
std::unordered_set<Node*>* input_var_nodes,
std::unordered_set<Node*>* weight_var_nodes,
std::unordered_set<Node*>* output_var_nodes,
std::unordered_set<Node*>* local_var_nodes,
std::unordered_set<Node*>* unused_var_nodes);
std::set<Node*>* input_var_nodes,
std::set<Node*>* weight_var_nodes,
std::set<Node*>* output_var_nodes,
std::set<Node*>* local_var_nodes,
std::set<Node*>* unused_var_nodes);
std::unordered_set<const Node*> GetNodes2RM(
std::set<const Node*> GetNodes2RM(
const std::vector<Node*>& op_nodes,
const std::vector<std::unordered_set<Node*>>& excluded_var_nodes);
const std::vector<std::set<Node*>>& excluded_var_nodes);
std::vector<Node*> GetTopologicalOrder(
const std::unordered_set<Node*>& unordered_nodes);
std::vector<Node*> GetTopologicalOrder(const std::set<Node*>& unordered_nodes);
} // namespace mir
} // namespace lite
......
......@@ -14,8 +14,8 @@
#include "lite/core/mir/subgraph/subgraph_pass.h"
#include <memory>
#include <set>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "lite/core/mir/pass_registry.h"
......@@ -27,7 +27,7 @@ namespace lite {
namespace mir {
void NPUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
std::unordered_set<std::string> supported_lists;
std::set<std::string> supported_lists;
#define USE_SUBGRAPH_BRIDGE(op_type, target) supported_lists.insert(#op_type);
#include "lite/kernels/npu/bridges/paddle_use_bridges.h"
#undef USE_SUBGRAPH_BRIDGE
......@@ -41,7 +41,7 @@ void NPUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
}
void APUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
std::unordered_set<std::string> supported_lists;
std::set<std::string> supported_lists;
#define USE_SUBGRAPH_BRIDGE(op_type, target) \
supported_lists.insert(#op_type); \
LOG(INFO) << #op_type
......@@ -58,7 +58,7 @@ void APUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
void XPUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
if (!GetBoolFromEnv("XPU_ENABLE_XTCL")) return;
std::unordered_set<std::string> supported_lists;
std::set<std::string> supported_lists;
#define USE_SUBGRAPH_BRIDGE(op_type, target) supported_lists.insert(#op_type);
#include "lite/kernels/xpu/bridges/paddle_use_bridges.h"
#undef USE_SUBGRAPH_BRIDGE
......@@ -72,7 +72,7 @@ void XPUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
}
void BMSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
std::unordered_set<std::string> supported_lists;
std::set<std::string> supported_lists;
#define USE_SUBGRAPH_BRIDGE(op_type, target) supported_lists.insert(#op_type);
#include "lite/kernels/bm/bridges/paddle_use_bridges.h"
#undef USE_SUBGRAPH_BRIDGE
......@@ -86,7 +86,7 @@ void BMSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
}
void RKNPUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
std::unordered_set<std::string> supported_lists;
std::set<std::string> supported_lists;
#define USE_SUBGRAPH_BRIDGE(op_type, target) supported_lists.insert(#op_type);
#include "lite/kernels/rknpu/bridges/paddle_use_bridges.h"
#undef USE_SUBGRAPH_BRIDGE
......@@ -100,7 +100,7 @@ void RKNPUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
}
void MLUSubgraphPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
std::unordered_set<std::string> supported_lists;
std::set<std::string> supported_lists;
#define USE_SUBGRAPH_BRIDGE(op_type, target) supported_lists.insert(#op_type);
#include "lite/kernels/mlu/bridges/paddle_use_bridges.h"
#undef USE_SUBGRAPH_BRIDGE
......
......@@ -138,7 +138,7 @@ void PrecisionCastPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
}
// record the copied node.
std::unordered_map<std::string, Node*> cast_nodes;
std::map<std::string, Node*> cast_nodes;
for (auto& node : nodes) {
if (!node->IsStmt() || node->AsStmt().op_type() == "while") continue;
......@@ -153,7 +153,7 @@ void PrecisionCastPass::ComplementInputs(
SSAGraph* graph,
Node* inst_node,
Node* in,
std::unordered_map<std::string, Node*>* cast_nodes) {
std::map<std::string, Node*>* cast_nodes) {
// If this input is out of date.
if (inst_node->inlinks.end() ==
std::find(inst_node->inlinks.begin(), inst_node->inlinks.end(), in))
......@@ -194,14 +194,13 @@ void PrecisionCastPass::ComplementInputs(
}
}
void PrecisionCastPass::AddCastInst(
const Type& from,
const Type& to,
Node* in,
SSAGraph* graph,
Node* inst_node,
std::unordered_map<std::string, Node*>* cast_nodes,
const std::vector<Place>& valid_places) {
void PrecisionCastPass::AddCastInst(const Type& from,
const Type& to,
Node* in,
SSAGraph* graph,
Node* inst_node,
std::map<std::string, Node*>* cast_nodes,
const std::vector<Place>& valid_places) {
CHECK(!valid_places.empty()) << "valid_place should be set";
// var -> new_transform_op -> new_var -> inst
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/mir/pass.h"
#include "lite/core/op_registry.h"
......@@ -38,14 +38,14 @@ class PrecisionCastPass : public ProgramPass {
void ComplementInputs(SSAGraph* graph,
Node* inst_node,
Node* in,
std::unordered_map<std::string, Node*>* cast_nodes);
std::map<std::string, Node*>* cast_nodes);
void AddCastInst(const Type& from,
const Type& to,
Node* in,
SSAGraph* graph,
Node* inst_node,
std::unordered_map<std::string, Node*>* cast_nodes,
std::map<std::string, Node*>* cast_nodes,
const std::vector<Place>& valid_places);
void SetValidPlaces(const std::vector<Place>& valid_places);
......
......@@ -14,9 +14,9 @@
#include "lite/core/mir/type_target_cast_pass.h"
#include <list>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/mir/graph_visualize_pass.h"
......@@ -38,7 +38,7 @@ void TypeTargetTransformPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
CHECK(!valid_places_.empty());
// record the copied node.
std::unordered_map<std::string, Node*> copied_nodes;
std::map<std::string, Node*> copied_nodes;
for (auto& node : nodes) {
if (!node->IsStmt() || node->AsStmt().op_type() == "while") continue;
......@@ -53,7 +53,7 @@ void TypeTargetTransformPass::ComplementInputs(
SSAGraph* graph,
Node* inst_node,
Node* in,
std::unordered_map<std::string, Node*>* copied_nodes) {
std::map<std::string, Node*>* copied_nodes) {
// If this input is out of date.
if (inst_node->inlinks.end() ==
std::find(inst_node->inlinks.begin(), inst_node->inlinks.end(), in))
......@@ -90,7 +90,7 @@ void TypeTargetTransformPass::AddIoCopyInst(
Node* in,
SSAGraph* graph,
Node* inst_node,
std::unordered_map<std::string, Node*>* copied_nodes,
std::map<std::string, Node*>* copied_nodes,
const std::vector<Place>& valid_places) {
CHECK(!valid_places.empty()) << "valid_place should be set";
// var -> new_transform_op -> new_var -> inst
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/mir/pass.h"
#include "lite/core/op_registry.h"
......@@ -36,14 +36,14 @@ class TypeTargetTransformPass : public ProgramPass {
void ComplementInputs(SSAGraph* graph,
Node* inst_node,
Node* in,
std::unordered_map<std::string, Node*>* copied_nodes);
std::map<std::string, Node*>* copied_nodes);
void AddIoCopyInst(const Type& from,
const Type& to,
Node* in,
SSAGraph* graph,
Node* inst_node,
std::unordered_map<std::string, Node*>* copied_nodes,
std::map<std::string, Node*>* copied_nodes,
const std::vector<Place>& valid_places);
void SetValidPlaces(const std::vector<Place>& valid_places);
......
......@@ -78,7 +78,7 @@ void XPUPatternMatcher::ValidateByNodeRole(
subgraphs->end(),
[](const XPUPatternMatcher::subgraph_t &subgraph) -> bool {
// Collect the inlinks and outlinks.
std::unordered_set<Node *> ios;
std::set<Node *> ios;
for (auto &item : subgraph) {
ios.insert(item.second);
}
......@@ -96,7 +96,7 @@ void XPUPatternMatcher::ValidateByNodeRole(
subgraphs->end());
for (auto &subgraph : *subgraphs) {
std::unordered_set<Node *> ios;
std::set<Node *> ios;
for (auto &item : subgraph) {
ios.insert(item.second);
}
......@@ -113,7 +113,7 @@ void XPUPatternMatcher::ValidateByNodeRole(
}
struct HitGroup {
std::unordered_map<PMNode *, Node *> roles;
std::map<PMNode *, Node *> roles;
bool Match(Node *node, PMNode *pat) {
if (nodes_.count(node)) {
......@@ -131,7 +131,7 @@ struct HitGroup {
}
private:
std::unordered_set<Node *> nodes_;
std::set<Node *> nodes_;
};
// Tell whether Node a links to b.
......@@ -222,12 +222,13 @@ void XPUPatternMatcher::UniquePatterns(
if (subgraphs->empty()) return;
std::vector<PatternMatcher::subgraph_t> result;
std::unordered_set<size_t> set;
std::set<size_t> set;
std::hash<std::string> hasher;
for (auto &g : *subgraphs) {
// Sort the items in the sub-graph, and transform to a string key.
std::vector<std::pair<PMNode *, Node *>> sorted_keys(g.begin(), g.end());
std::sort(sorted_keys.begin(), sorted_keys.end(), GraphItemLessThan());
std::stable_sort(
sorted_keys.begin(), sorted_keys.end(), GraphItemLessThan());
STL::stringstream ss;
for (auto &item : sorted_keys) {
ss << reinterpret_cast<size_t>(item.first) << ":"
......@@ -245,7 +246,7 @@ void XPUPatternMatcher::UniquePatterns(
void XPUPatternMatcher::RemoveOverlappedMatch(
std::vector<subgraph_t> *subgraphs) {
std::vector<subgraph_t> result;
std::unordered_set<Node *> node_set;
std::set<Node *> node_set;
for (const auto &subgraph : *subgraphs) {
bool valid = true;
......
......@@ -14,8 +14,8 @@
#pragma once
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include "lite/core/mir/pattern_matcher.h"
......@@ -52,7 +52,7 @@ namespace xpu {
* matcher(&graph, handler);
*/
struct XPUPatternMatcher {
using subgraph_t = std::unordered_map<PMNode*, Node*>;
using subgraph_t = std::map<PMNode*, Node*>;
// Operate on the detected pattern.
using handle_t =
......@@ -83,7 +83,7 @@ struct XPUPatternMatcher {
using hit_rcd_t =
std::pair<Node* /*node in graph*/, PMNode* /*node in pattern*/>;
PMPattern pattern_;
std::unordered_map<const PMNode*, std::unordered_set<Node*>> pmnodes2nodes_;
std::map<const PMNode*, std::set<Node*>> pmnodes2nodes_;
std::vector<std::vector<Node*>> extra_input_vars_;
};
......
......@@ -14,7 +14,6 @@
#include "lite/core/mir/xpu_pattern_matcher_high_api.h"
#include <set>
#include <unordered_set>
#include "lite/utils/cp_logging.h"
namespace paddle {
......@@ -45,7 +44,7 @@ void XPUFuseBase::DeleteInterNodes(SSAGraph *graph) {
}
VLOG(4) << "keys: " << key2nodes_.size();
std::unordered_set<const Node *> nodes2rm;
std::set<const Node *> nodes2rm;
for (auto &matched : key2nodes_) {
for (const auto &key : keys) {
nodes2rm.insert(matched.at(key));
......
......@@ -83,39 +83,61 @@ std::list<std::unique_ptr<KernelBase>> KernelRegistry::Create(
case TARGET(kHost): {
CREATE_KERNEL(kHost);
} break;
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_X86)
case TARGET(kX86): {
CREATE_KERNEL(kX86);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_CUDA)
case TARGET(kCUDA): {
CREATE_KERNEL(kCUDA);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_ARM)
case TARGET(kARM): {
CREATE_KERNEL(kARM);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_OPENCL)
case TARGET(kOpenCL): {
CREATE_KERNEL(kOpenCL);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_NPU)
case TARGET(kNPU): {
CREATE_KERNEL(kNPU);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_APU)
case TARGET(kAPU): {
CREATE_KERNEL(kAPU);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_XPU)
case TARGET(kXPU): {
CREATE_KERNEL(kXPU);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_FPGA)
case TARGET(kFPGA): {
CREATE_KERNEL(kFPGA);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_BM)
case TARGET(kBM): {
CREATE_KERNEL(kBM);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_MLU)
case TARGET(kMLU): {
CREATE_KERNEL(kMLU);
} break;
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_RKNPU)
case TARGET(kRKNPU): {
CREATE_KERNEL(kRKNPU);
} break;
#endif
default:
CHECK(false) << "not supported kernel target " << TargetToStr(target);
}
......@@ -135,7 +157,8 @@ KernelRegistry::KernelRegistry() : registries_() {
&KernelRegistryForTarget<TARGET(target__), \
PRECISION(precision__), \
DATALAYOUT(layout__)>::Global());
// Currently, just register 2 kernel targets.
// Currently, just register 2 kernel targets.
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_CUDA)
INIT_FOR(kCUDA, kFloat, kNCHW);
INIT_FOR(kCUDA, kFloat, kNHWC);
INIT_FOR(kCUDA, kInt8, kNCHW);
......@@ -144,7 +167,9 @@ KernelRegistry::KernelRegistry() : registries_() {
INIT_FOR(kCUDA, kInt8, kNHWC);
INIT_FOR(kCUDA, kInt64, kNCHW);
INIT_FOR(kCUDA, kInt64, kNHWC);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_MLU)
INIT_FOR(kMLU, kFloat, kNHWC);
INIT_FOR(kMLU, kFloat, kNCHW);
INIT_FOR(kMLU, kFP16, kNHWC);
......@@ -153,6 +178,7 @@ KernelRegistry::KernelRegistry() : registries_() {
INIT_FOR(kMLU, kInt8, kNCHW);
INIT_FOR(kMLU, kInt16, kNHWC);
INIT_FOR(kMLU, kInt16, kNCHW);
#endif
INIT_FOR(kHost, kAny, kNCHW);
INIT_FOR(kHost, kAny, kNHWC);
......@@ -179,11 +205,13 @@ KernelRegistry::KernelRegistry() : registries_() {
INIT_FOR(kHost, kInt64, kNHWC);
INIT_FOR(kHost, kInt64, kAny);
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_X86)
INIT_FOR(kX86, kFloat, kNCHW);
INIT_FOR(kX86, kAny, kNCHW);
INIT_FOR(kX86, kAny, kAny);
INIT_FOR(kX86, kInt64, kNCHW);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_ARM)
INIT_FOR(kARM, kFloat, kNCHW);
INIT_FOR(kARM, kFloat, kNHWC);
INIT_FOR(kARM, kInt8, kNCHW);
......@@ -192,7 +220,8 @@ KernelRegistry::KernelRegistry() : registries_() {
INIT_FOR(kARM, kAny, kAny);
INIT_FOR(kARM, kInt32, kNCHW);
INIT_FOR(kARM, kInt64, kNCHW);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_OPENCL)
INIT_FOR(kOpenCL, kFloat, kNCHW);
INIT_FOR(kOpenCL, kFloat, kNHWC);
INIT_FOR(kOpenCL, kAny, kNCHW);
......@@ -211,7 +240,8 @@ KernelRegistry::KernelRegistry() : registries_() {
INIT_FOR(kOpenCL, kAny, kImageDefault);
INIT_FOR(kOpenCL, kAny, kImageFolder);
INIT_FOR(kOpenCL, kAny, kImageNW);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_NPU)
INIT_FOR(kNPU, kFloat, kNCHW);
INIT_FOR(kNPU, kFloat, kNHWC);
INIT_FOR(kNPU, kInt8, kNCHW);
......@@ -219,28 +249,34 @@ KernelRegistry::KernelRegistry() : registries_() {
INIT_FOR(kNPU, kAny, kNCHW);
INIT_FOR(kNPU, kAny, kNHWC);
INIT_FOR(kNPU, kAny, kAny);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_APU)
INIT_FOR(kAPU, kInt8, kNCHW);
INIT_FOR(kXPU, kFloat, kNCHW);
INIT_FOR(kXPU, kInt8, kNCHW);
INIT_FOR(kXPU, kAny, kNCHW);
INIT_FOR(kXPU, kAny, kAny);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_FPGA)
INIT_FOR(kFPGA, kFP16, kNHWC);
INIT_FOR(kFPGA, kFP16, kAny);
INIT_FOR(kFPGA, kFloat, kNHWC);
INIT_FOR(kFPGA, kAny, kNHWC);
INIT_FOR(kFPGA, kAny, kAny);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_BM)
INIT_FOR(kBM, kFloat, kNCHW);
INIT_FOR(kBM, kInt8, kNCHW);
INIT_FOR(kBM, kAny, kNCHW);
INIT_FOR(kBM, kAny, kAny);
#endif
#if !defined(LITE_ON_TINY_PUBLISH) || defined(LITE_WITH_RKNPU)
INIT_FOR(kRKNPU, kFloat, kNCHW);
INIT_FOR(kRKNPU, kInt8, kNCHW);
INIT_FOR(kRKNPU, kAny, kNCHW);
INIT_FOR(kRKNPU, kAny, kAny);
#endif
#undef INIT_FOR
}
......
......@@ -20,7 +20,6 @@
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/api/paddle_lite_factory_helper.h"
......
......@@ -14,7 +14,7 @@
#include "lite/core/program.h"
#include <algorithm>
#include <unordered_map>
#include <map>
#include "lite/model_parser/cpp/block_desc.h"
#include "lite/model_parser/cpp/op_desc.h"
#include "lite/model_parser/cpp/var_desc.h"
......@@ -70,7 +70,7 @@ void RuntimeProgram::SaveOpInfosToProgram(cpp::ProgramDesc* desc) {
void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
CHECK(desc);
CHECK(desc->BlocksSize());
std::unordered_map<std::string, cpp::VarDesc> origin_var_maps;
std::map<std::string, cpp::VarDesc> origin_var_maps;
auto& main_block = *desc->GetBlock<cpp::BlockDesc>(0);
auto var_size = main_block.VarsSize();
for (int i = 0; i < var_size; i++) {
......@@ -87,7 +87,7 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
auto in_names = op->op_info()->input_names();
auto out_names = op->op_info()->output_names();
in_names.insert(in_names.end(), out_names.begin(), out_names.end());
std::sort(in_names.begin(), in_names.end());
std::stable_sort(in_names.begin(), in_names.end());
in_names.erase(std::unique(in_names.begin(), in_names.end()),
in_names.end());
for (auto& in_name : in_names) {
......
......@@ -14,9 +14,9 @@
#pragma once
#include <list>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/kernel.h"
......@@ -67,7 +67,7 @@ struct Program {
lite::Scope* exec_scope() { return exec_scope_; }
lite::Scope* scope() { return scope_.get(); }
const std::unordered_map<std::string, PrecisionType>& var_data_type() const {
const std::map<std::string, PrecisionType>& var_data_type() const {
return var_data_type_;
}
......@@ -78,7 +78,7 @@ struct Program {
void PrepareWorkspace(const cpp::ProgramDesc& program);
private:
std::unordered_map<std::string, PrecisionType> var_data_type_;
std::map<std::string, PrecisionType> var_data_type_;
std::list<std::string> tmp_vars_;
std::list<std::string> weights_;
std::list<std::shared_ptr<OpLite>> ops_;
......
......@@ -14,9 +14,9 @@
#pragma once
#include <list>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/variable.h"
......@@ -74,7 +74,7 @@ class Scope final {
// Scope in `kids_` are owned by this class.
mutable std::list<Scope*> kids_;
const Scope* parent_{nullptr};
std::unordered_map<std::string, std::unique_ptr<Variable>> vars_;
std::map<std::string, std::unique_ptr<Variable>> vars_;
};
} // namespace lite
......
......@@ -21,10 +21,9 @@
// for analysis and runtime.
#include <map>
#include <set>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "lite/core/tensor.h"
#include "lite/core/version.h"
......
......@@ -15,8 +15,8 @@
#define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h
#include "lite/fluid/data_type.h"
#include <stdint.h>
#include <map>
#include <string>
#include <unordered_map>
using float16 = paddle::lite::fluid::float16;
......@@ -25,11 +25,10 @@ namespace lite {
namespace fluid {
struct DataTypeMap {
std::unordered_map<std::type_index, framework::proto::VarType::Type>
cpp_to_proto_;
std::unordered_map<int, std::type_index> proto_to_cpp_;
std::unordered_map<int, std::string> proto_to_str_;
std::unordered_map<int, size_t> proto_to_size_;
std::map<std::type_index, framework::proto::VarType::Type> cpp_to_proto_;
std::map<int, std::type_index> proto_to_cpp_;
std::map<int, std::string> proto_to_str_;
std::map<int, size_t> proto_to_size_;
};
static DataTypeMap* InitDataTypeMap();
......
......@@ -15,9 +15,9 @@ limitations under the License. */
#pragma once
#include <algorithm>
#include <map>
#include <memory>
#include <mutex> // NOLINT
#include <unordered_map>
#include <utility>
#include <vector>
......@@ -148,7 +148,7 @@ class SelectedRows {
// SelectedRows are simply concated when adding together. Until a
// SelectedRows add a Tensor, will the duplicate rows be handled.
std::vector<int64_t> rows_;
std::unordered_map<int64_t, int64_t>
std::map<int64_t, int64_t>
id_to_index_; // should not be used when rows_ has duplicate member
std::unique_ptr<Tensor> value_{nullptr};
int64_t height_; // height indicates the underline tensor's height
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/backends/apu/neuron_adapter.h"
......@@ -97,7 +97,7 @@ class Graph {
private:
NeuronModel* model_;
std::unordered_map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
std::map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
int32_t operandIdx_ = 0;
std::vector<std::string> input_names_;
std::vector<std::string> output_names_;
......
......@@ -16,9 +16,9 @@
#include <dlfcn.h>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/op_lite.h"
#include "lite/utils/macros.h"
......
......@@ -78,14 +78,14 @@ struct BeamSearchDecoder {
for (size_t src_idx = 0; src_idx < src_num; ++src_idx) {
if (sort_by_score) {
sort(sentence_vector_list[src_idx].begin(),
sentence_vector_list[src_idx].end(),
[reverse](const Sentence<T>& a, const Sentence<T>& b) {
if (reverse)
return a.scores.front() > b.scores.front();
else
return a.scores.back() > b.scores.back();
});
std::stable_sort(sentence_vector_list[src_idx].begin(),
sentence_vector_list[src_idx].end(),
[reverse](const Sentence<T>& a, const Sentence<T>& b) {
if (reverse)
return a.scores.front() > b.scores.front();
else
return a.scores.back() > b.scores.back();
});
}
for (Sentence<T>& sentence : sentence_vector_list[src_idx]) {
if (reverse) {
......
......@@ -321,7 +321,7 @@ static std::pair<Tensor, Tensor> ProposalForOneImage(
return scores_data[i] > scores_data[j];
};
if (pre_nms_top_n <= 0 || pre_nms_top_n >= scores_slice.numel()) {
std::sort(index, index + scores_slice.numel(), compare_func);
std::stable_sort(index, index + scores_slice.numel(), compare_func);
} else {
std::nth_element(index,
index + pre_nms_top_n,
......
......@@ -15,9 +15,9 @@
#pragma once
#include <pthread.h>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/op_lite.h"
......@@ -40,7 +40,7 @@ class Graph {
void UnlockCompilerMutex();
private:
std::unordered_map<std::string, std::string> nodes_;
std::map<std::string, std::string> nodes_;
void* compiler_handle_;
static pthread_mutex_t mutex_compiler_;
};
......
......@@ -13,8 +13,8 @@
// limitations under the License.
#include "lite/kernels/bm/bridges/utility.h"
#include <map>
#include <mutex> //NOLINT
#include <unordered_map>
namespace paddle {
namespace lite {
......@@ -23,7 +23,7 @@ namespace bm {
std::string UniqueName(const std::string& prefix) {
static std::mutex counter_mtx;
static std::unordered_map<std::string, int> counter_map;
static std::map<std::string, int> counter_map;
std::unique_lock<std::mutex> counter_lck(counter_mtx);
int counter = 1;
auto it = counter_map.find(prefix);
......
......@@ -137,11 +137,11 @@ bool SeqSortedseqTranseUtil::get_sorted_map(const std::vector<int>& offset_vec,
return false;
}
std::sort(_length_index.begin(),
_length_index.end(),
[&length_vec](int i1, int i2) {
return length_vec[i1] > length_vec[i2];
});
std::stable_sort(_length_index.begin(),
_length_index.end(),
[&length_vec](int i1, int i2) {
return length_vec[i1] > length_vec[i2];
});
_emit_offset_vec.resize(max_len + 1);
_map_vec.resize(word_sum);
......
......@@ -15,9 +15,9 @@
#pragma once
#include <cmath>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/op_lite.h"
#include "lite/core/tensor.h"
......@@ -230,7 +230,7 @@ class Graph {
private:
cnmlDataType_t fp_type_{CNML_DATA_FLOAT32};
std::unordered_map<std::string, std::shared_ptr<MLUTensor>> nodes_;
std::map<std::string, std::shared_ptr<MLUTensor>> nodes_;
std::vector<cnmlTensor_t> inputs_;
std::vector<cnmlTensor_t> outputs_;
std::vector<void*> input_addrs_;
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/op_lite.h"
#include "lite/core/program.h"
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "graph/op/all_ops.h"
......@@ -187,7 +187,7 @@ class Graph {
}
private:
std::unordered_map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
std::map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
};
} // namespace npu
......
......@@ -43,7 +43,7 @@ int ReduceMeanConverter(void* ctx, OpLite* op, KernelBase* kernel) {
dim[i] += x_dims.size();
}
}
std::sort(dim.begin(), dim.end());
std::stable_sort(dim.begin(), dim.end());
// X node
std::shared_ptr<Node> x_node = nullptr;
......
......@@ -217,7 +217,7 @@ void reduce_mean_ref(const std::shared_ptr<operators::ReduceMeanOp> op) {
}
bool reduce_all = false;
sort(dim.begin(), dim.end());
std::stable_sort(dim.begin(), dim.end());
if (dim.size() == 0) {
reduce_all = true;
}
......
......@@ -30,8 +30,7 @@ void Registry::Insert(const std::string& op_type,
int key = static_cast<int>(target);
auto it = map_.find(key);
if (it == map_.end()) {
map_.insert(
std::make_pair(key, std::unordered_map<std::string, cvt_func_type>()));
map_.insert(std::make_pair(key, std::map<std::string, cvt_func_type>()));
}
map_.at(key).insert(std::make_pair(op_type, cvt_func_name));
}
......
......@@ -15,8 +15,8 @@
#pragma once
#include <functional>
#include <map>
#include <string>
#include <unordered_map>
#include "lite/core/op_lite.h"
#include "lite/utils/macros.h"
......@@ -35,8 +35,7 @@ inline bool CHECK_REBUILD_WHEN_SHAPE_CHANGED(int status) {
using cvt_func_type =
std::function<int(void* ctx, OpLite* op, KernelBase* kernel)>;
using cvt_map_type =
std::unordered_map<int, std::unordered_map<std::string, cvt_func_type>>;
using cvt_map_type = std::map<int, std::map<std::string, cvt_func_type>>;
class Registry {
public:
static Registry& Instance();
......
......@@ -15,9 +15,9 @@
#pragma once
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "graph/buffer.h"
#include "graph/graph.h"
......
......@@ -33,7 +33,7 @@ namespace npu {
std::string SubgraphEngine::GenerateModelCacheName() const {
auto inames = device_inames_;
auto onames = device_onames_;
std::sort(inames.begin(), inames.end());
std::stable_sort(inames.begin(), inames.end());
std::string model_cache_name = "subgraph_" + std::to_string(block_idx_);
for (auto iname : inames) {
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/op_lite.h"
......@@ -123,7 +123,7 @@ class Graph {
rk::nn::Graph* GetHandle() { return rgraph_; }
private:
std::unordered_map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
std::map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
rk::nn::Graph* rgraph_;
};
......
......@@ -13,9 +13,9 @@
// limitations under the License.
#include "lite/kernels/rknpu/bridges/utility.h"
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/op_lite.h"
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/core/op_lite.h"
......
......@@ -75,12 +75,12 @@ void SearchGrnnCompute<T>::PrepareLayout(const Tensor* input_blob) {
width_data[i] = offset[i + 1] - offset[i];
idx_sorted_by_width_data[i] = i;
}
std::sort(idx_sorted_by_width_data,
idx_sorted_by_width_data + batch,
[&_width](int a, int b) {
return _width.template data<int>()[a] >
_width.template data<int>()[b];
});
std::stable_sort(idx_sorted_by_width_data,
idx_sorted_by_width_data + batch,
[&_width](int a, int b) {
return _width.template data<int>()[a] >
_width.template data<int>()[b];
});
int max_width = width_data[idx_sorted_by_width_data[0]];
// start of reorganizing the input
......
......@@ -14,9 +14,9 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "lite/backends/xpu/xpu_header_sitter.h"
......@@ -175,7 +175,7 @@ class Graph {
xtcl::network::xTensorCompiler::ParamNDArrayMap params_;
private:
std::unordered_map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
std::map<std::string, std::vector<std::shared_ptr<Node>>> nodes_;
};
} // namespace xpu
......
......@@ -43,16 +43,16 @@ bool CompatibleChecker<T>::CheckKernelVersion(const std::string& type,
}
template <typename T>
std::unordered_set<std::string> CompatibleChecker<T>::OpsType(T* program) {
std::set<std::string> CompatibleChecker<T>::OpsType(T* program) {
LOG(WARNING) << "OpsType() is not yet implemented.";
return std::unordered_set<std::string>();
return std::set<std::string>();
}
#ifndef LITE_ON_TINY_PUBLISH
template <>
std::unordered_set<std::string> CompatibleChecker<cpp::ProgramDesc>::OpsType(
std::set<std::string> CompatibleChecker<cpp::ProgramDesc>::OpsType(
cpp::ProgramDesc* program) {
std::unordered_set<std::string> ops_type;
std::set<std::string> ops_type;
for (size_t i = 0; i < program->BlocksSize(); ++i) {
auto* block = program->GetBlock<cpp::BlockDesc>(i);
for (size_t j = 0; j < block->OpsSize(); ++j) {
......
......@@ -14,8 +14,8 @@
#pragma once
#include <set>
#include <string>
#include <unordered_set>
#include "lite/api/paddle_place.h"
#include "lite/model_parser/desc_apis.h"
......@@ -31,7 +31,7 @@ class CompatibleChecker {
bool operator()(const lite_api::Place& place) {
bool status = true;
const std::unordered_set<std::string>& ops_type = OpsType(&program_);
const std::set<std::string>& ops_type = OpsType(&program_);
if (ops_type.empty()) {
VLOG(3) << "You are checking the compatibility of an empty program.";
}
......@@ -44,7 +44,7 @@ class CompatibleChecker {
}
private:
std::unordered_set<std::string> OpsType(T* program);
std::set<std::string> OpsType(T* program);
bool CheckKernelVersion(const std::string& type,
const lite_api::Place& place);
T program_;
......
......@@ -17,7 +17,6 @@
#include <fstream>
#include <limits>
#include <set>
#include <unordered_set>
#include "lite/core/scope.h"
#include "lite/core/tensor.h"
#include "lite/core/variable.h"
......@@ -187,7 +186,7 @@ void LoadCombinedParamsPb(const std::string &path,
if (!IsPersistable(var)) continue;
paramlist.push_back(var.Name());
}
std::sort(paramlist.begin(), paramlist.end());
std::stable_sort(paramlist.begin(), paramlist.end());
// Load vars
auto load_var_func = [&](std::istream &is) {
......@@ -321,7 +320,7 @@ void SaveCombinedParamsPb(const std::string &path,
if (!IsPersistable(var)) continue;
paramlist.push_back(var.Name());
}
std::sort(paramlist.begin(), paramlist.end());
std::stable_sort(paramlist.begin(), paramlist.end());
// Load vars
std::ofstream file(path, std::ios::binary);
......@@ -530,7 +529,7 @@ void SaveCombinedParamsNaive(const std::string &path,
auto prog = cpp_prog;
auto &main_block_desc = *prog.GetBlock<cpp::BlockDesc>(0);
// set unique_var_names to avoid saving shared params repeatedly
std::unordered_set<std::string> unique_var_names;
std::set<std::string> unique_var_names;
for (size_t i = 0; i < main_block_desc.VarsSize(); ++i) {
auto &var = *main_block_desc.GetVar<cpp::VarDesc>(i);
if (var.Name() == "feed" || var.Name() == "fetch" || !var.Persistable() ||
......
......@@ -22,7 +22,6 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/model_parser/desc_apis.h"
#include "lite/model_parser/naive_buffer/proto/framework.nb.h"
......
......@@ -24,7 +24,6 @@
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/framework.pb.h"
#include "lite/model_parser/desc_apis.h"
......
......@@ -52,7 +52,7 @@ bool ReduceMaxOp::InferShapeImpl() const {
}
}
}
sort(dims.begin(), dims.end());
std::stable_sort(dims.begin(), dims.end());
if (dims.size() == 0) {
reduce_all = true;
}
......
......@@ -52,7 +52,7 @@ bool ReduceMeanOp::InferShapeImpl() const {
}
}
}
sort(dims.begin(), dims.end());
std::stable_sort(dims.begin(), dims.end());
if (dims.size() == 0) {
reduce_all = true;
}
......
......@@ -50,7 +50,7 @@ bool ReduceOp::InferShapeImpl() const {
} else {
size_t out_rank = keep_dim ? x_rank : x_rank - dims.size();
std::vector<DDim::value_type> out_dims(out_rank);
sort(dims.begin(), dims.end());
std::stable_sort(dims.begin(), dims.end());
int dim_index = 0;
int out_index = 0;
for (size_t i = 0; i < x_rank; ++i) {
......
......@@ -44,7 +44,7 @@ bool ReduceProdOpLite::InferShapeImpl() const {
}
CHECK_OR_FALSE(static_cast<size_t>(dim[i]) < x_rank);
}
std::sort(dim.begin(), dim.end());
std::stable_sort(dim.begin(), dim.end());
if (reduce_all || dim.size() == 0) {
if (keep_dim) {
......
......@@ -125,9 +125,10 @@ int main(int argc, char** argv) {
// get output
std::iota(index.begin(), index.end(), 0);
sort(index.begin(), index.end(), [output0_data](size_t i1, size_t i2) {
return output0_data[i1] > output0_data[i2];
});
std::stable_sort(
index.begin(), index.end(), [output0_data](size_t i1, size_t i2) {
return output0_data[i1] > output0_data[i2];
});
test_num++;
if (label == index[0]) {
top1_num++;
......
......@@ -224,7 +224,7 @@ class ReduceMaxComputeTester : public arena::TestCase {
}
}
sort(dim_.begin(), dim_.end());
std::stable_sort(dim_.begin(), dim_.end());
if (dim_.size() == 0) {
reduce_all_ = true;
}
......
......@@ -223,7 +223,7 @@ class ReduceMeanComputeTester : public arena::TestCase {
}
}
sort(dim_.begin(), dim_.end());
std::stable_sort(dim_.begin(), dim_.end());
if (dim_.size() == 0) {
reduce_all_ = true;
}
......
......@@ -207,7 +207,7 @@ class ReduceProdComputeTester : public arena::TestCase {
}
}
}
sort(dim_.begin(), dim_.end());
std::stable_sort(dim_.begin(), dim_.end());
if (reduce_all_ || dim_.size() == 0) {
if (keep_dim_) {
......
......@@ -224,7 +224,7 @@ class ReduceSumComputeTester : public arena::TestCase {
}
}
sort(dim_.begin(), dim_.end());
std::stable_sort(dim_.begin(), dim_.end());
std::vector<int64_t> out_dims;
if (reduce_all_) {
if (keep_dim_) {
......
#!/bin/bash
set +x
set -x
#####################################################################################################
# 1. global variables, you can change them according to your requirements
#####################################################################################################
......
......@@ -16,9 +16,9 @@
#include <gflags/gflags.h>
#include <algorithm>
#include <fstream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "lite/api/cxx_api.h"
......@@ -63,7 +63,7 @@ struct DebugConfig {
int tensor_output_length;
int arm_thread_num;
std::unordered_map<std::string, lite::pb::VarDesc> var_descs;
std::map<std::string, lite::pb::VarDesc> var_descs;
std::vector<std::vector<std::string>> input_values;
};
......@@ -83,7 +83,7 @@ std::vector<T> Split2Vector(const std::string& input,
return tgt;
}
void CollectFeedVarsInfo(std::unordered_map<int, std::string>* feed_vars_info,
void CollectFeedVarsInfo(std::map<int, std::string>* feed_vars_info,
const framework::proto::ProgramDesc& prog_desc) {
CHECK(feed_vars_info);
auto desc = prog_desc;
......@@ -134,7 +134,7 @@ void PrepareModelInputTensor(const DebugConfig& conf,
const framework::proto::ProgramDesc& desc) {
CHECK(scope);
std::unordered_map<int, std::string> feed_vars_info;
std::map<int, std::string> feed_vars_info;
CollectFeedVarsInfo(&feed_vars_info, desc);
auto* feed_var =
scope->FindVar("feed")->GetMutable<std::vector<lite::Tensor>>();
......@@ -243,23 +243,22 @@ void CollectAndDumpTopoInfo(const std::vector<Instruction>& instructions,
os.close();
}
void CollectVarDescs(
std::unordered_map<std::string, lite::pb::VarDesc>* var_descs,
framework::proto::ProgramDesc* desc) {
void CollectVarDescs(std::map<std::string, lite::pb::VarDesc>* var_descs,
framework::proto::ProgramDesc* desc) {
CHECK(desc);
CHECK(var_descs);
CHECK(!desc->blocks().empty());
std::unordered_set<std::string> weights;
std::set<std::string> weights;
for (auto& proto_var_desc : *desc->mutable_blocks(0)->mutable_vars()) {
lite::pb::VarDesc var_desc(&proto_var_desc);
(*var_descs).emplace(var_desc.Name(), std::move(var_desc));
}
}
std::unordered_set<std::string> CollectUnusedVars(
std::set<std::string> CollectUnusedVars(
const std::vector<Instruction>& instructions) {
std::unordered_set<std::string> unused;
std::unordered_set<std::string> all_inputs;
std::set<std::string> unused;
std::set<std::string> all_inputs;
for (auto& inst : instructions) {
for (const auto& name : inst.op()->op_info()->input_names()) {
all_inputs.insert(name);
......@@ -295,7 +294,7 @@ void CollectAndDumpTensorInfo(const std::vector<Instruction>& instructions,
std::ofstream os(conf.tensor_output_file);
CHECK(os.is_open());
std::unordered_set<std::string> dump_vars;
std::set<std::string> dump_vars;
#define DUMP_TENSOR_ONCE(name__) \
LOG(INFO) << "----------------- dump tensor: " << name__; \
auto& tensor = scope->FindVar(name__)->Get<lite::Tensor>(); \
......@@ -314,8 +313,7 @@ void CollectAndDumpTensorInfo(const std::vector<Instruction>& instructions,
}
if (conf.tensor_names.size() == 0) {
std::unordered_set<std::string> unused(
std::move(CollectUnusedVars(instructions)));
std::set<std::string> unused(std::move(CollectUnusedVars(instructions)));
for (auto& inst : instructions) {
DUMP_OP_TENSOR_ONCE(input, feed);
......
......@@ -15,10 +15,10 @@
#pragma once
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include "lite/utils/all.h"
#include "lite/utils/cp_logging.h"
......@@ -82,7 +82,7 @@ class Factory {
}
protected:
std::unordered_map<std::string, std::list<creator_t>> creators_;
std::map<std::string, std::list<creator_t>> creators_;
};
/* A helper function to help run a lambda at the start.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册