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