From 7a580017220d22a23fbe25f1bf6abd2aa60e887c Mon Sep 17 00:00:00 2001 From: "Philipp v. K" Date: Mon, 7 Feb 2022 19:11:52 +0100 Subject: [PATCH 1/3] USMP: Register hill_climb algo in algorithms map --- include/tvm/tir/usmp/algorithms.h | 11 +++++++++++ src/tir/usmp/unified_static_memory_planner.cc | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/tvm/tir/usmp/algorithms.h b/include/tvm/tir/usmp/algorithms.h index 77276a2c931c..e2f2b6fb73f3 100644 --- a/include/tvm/tir/usmp/algorithms.h +++ b/include/tvm/tir/usmp/algorithms.h @@ -54,6 +54,17 @@ Map GreedyBySize(const Array& buffer_inf Map GreedyByConflicts(const Array& buffer_info_arr, const Integer& memory_pressure); +/*! + * \brief The Hill-Climb algorithm to plan memory + * + * This will perform a hill climbing algorithm in deciding the offsets + * within provided Pools. + * + * \return A Map of BufferInfo objects and their associated PoolAllocation + */ +Map HillClimb(const Array& buffer_info_arr, + const Integer& memory_pressure); + } // namespace algo } // namespace usmp } // namespace tir diff --git a/src/tir/usmp/unified_static_memory_planner.cc b/src/tir/usmp/unified_static_memory_planner.cc index 5a2125077566..43dbf65728d2 100644 --- a/src/tir/usmp/unified_static_memory_planner.cc +++ b/src/tir/usmp/unified_static_memory_planner.cc @@ -46,7 +46,8 @@ static constexpr const char* kDefaultAlgo = "greedy_by_size"; static std::unordered_map( const Array&, const Integer&)>> algorithms{{"greedy_by_size", algo::GreedyBySize}, - {"greedy_by_conflicts", algo::GreedyByConflicts}}; + {"greedy_by_conflicts", algo::GreedyByConflicts}, + {"hill_climb", algo::HillClimb}}; IRModule PlanMemory(const IRModule& mod, String algo) { VLOG(1) << "workspace required = " << CalculateModuleWorkspaceSize(mod); From 97604e475d6c0ddc1ba2900a4fc606ec178831b6 Mon Sep 17 00:00:00 2001 From: "Philipp v. K" Date: Mon, 7 Feb 2022 19:12:18 +0100 Subject: [PATCH 2/3] USMP: Add missing space to assertion message --- src/tir/usmp/unified_static_memory_planner.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tir/usmp/unified_static_memory_planner.cc b/src/tir/usmp/unified_static_memory_planner.cc index 43dbf65728d2..3b941d3cc021 100644 --- a/src/tir/usmp/unified_static_memory_planner.cc +++ b/src/tir/usmp/unified_static_memory_planner.cc @@ -56,7 +56,7 @@ IRModule PlanMemory(const IRModule& mod, String algo) { Array buffer_info_arr = CreateArrayBufferInfo(buffer_info_analysis->buffer_info_stmts); CHECK(algorithms.count(algo)) << "The selected USMP algorithm : " << algo - << "is not defined. Please define it in the above algorithms map."; + << " is not defined. Please define it in the above algorithms map."; Map buffer_info_pool_allocations = algorithms[algo](buffer_info_arr, buffer_info_analysis->memory_pressure); Map stmt_pool_allocations = AssignStmtPoolAllocations( From 985cec5f21d7e18a6029a35d0f9f4864d09c83a4 Mon Sep 17 00:00:00 2001 From: Philipp van Kempen Date: Wed, 9 Feb 2022 10:53:22 +0100 Subject: [PATCH 3/3] USMP: Integrate hill_climb algo in test_crt_aot_usmp --- tests/python/relay/aot/test_crt_aot_usmp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/relay/aot/test_crt_aot_usmp.py b/tests/python/relay/aot/test_crt_aot_usmp.py index 47495aaa16c8..6a040d9a9e79 100644 --- a/tests/python/relay/aot/test_crt_aot_usmp.py +++ b/tests/python/relay/aot/test_crt_aot_usmp.py @@ -212,6 +212,7 @@ def test_byoc_microtvm(merge_compiler_regions): [ (MOBILENET_V1_URL, "greedy_by_size", 4845696), (MOBILENET_V1_URL, "greedy_by_conflicts", 4444288), + (MOBILENET_V1_URL, "hill_climb", 3240064), ], ) def test_tflite_model(model_url, usmp_algo, workspace_size):