From 40a230dbdba2ee8deceab75f15e92980036a2d37 Mon Sep 17 00:00:00 2001 From: Lily Orth-Smith Date: Tue, 15 Feb 2022 13:04:28 -0800 Subject: [PATCH 1/4] Fix bug --- include/tvm/ir/memory_pools.h | 15 +++++++++------ src/tir/usmp/transform/assign_pool_info.cc | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/tvm/ir/memory_pools.h b/include/tvm/ir/memory_pools.h index c6e52648ebd4..12fb8a6a97c6 100644 --- a/include/tvm/ir/memory_pools.h +++ b/include/tvm/ir/memory_pools.h @@ -103,14 +103,17 @@ struct PoolInfoNode : public Object { TVM_DECLARE_FINAL_OBJECT_INFO(PoolInfoNode, Object); }; +/*! +* \brief The string parameter to indicate read and write access to a pool +* This needs to be kept in sync with PoolInfo.READ_WRITE_ACCESS in +* python/tvm/ir/memory_pools.py +*/ + +static constexpr const char* kTargetPoolReadWriteAccess = "rw"; + class PoolInfo : public ObjectRef { public: - /*! - * \brief The string parameter to indicate read and write access to a pool - * This needs to be kept in sync with PoolInfo.READ_WRITE_ACCESS in - * python/tvm/ir/memory_pools.py - */ - static constexpr const char* kTargetPoolReadWriteAccess = "rw"; + /*! * \brief The string parameter to indicate read only access to a pool * This needs to be kept in sync with PoolInfo.READ_ONLY_ACCESS in diff --git a/src/tir/usmp/transform/assign_pool_info.cc b/src/tir/usmp/transform/assign_pool_info.cc index 2386b5fef77d..5768397773df 100644 --- a/src/tir/usmp/transform/assign_pool_info.cc +++ b/src/tir/usmp/transform/assign_pool_info.cc @@ -49,7 +49,7 @@ class PoolInfoAssigner : public StmtExprMutator { WorkspaceMemoryPools workspace_pools = module->GetAttr(tvm::attr::kWorkspaceMemoryPools) .value_or(WorkspaceMemoryPools({PoolInfo( - "global_workspace", {{target_host.value(), PoolInfo::kTargetPoolReadWriteAccess}}, + "global_workspace", {{target_host.value(), kTargetPoolReadWriteAccess}}, PoolInfo::kUnrestrictedPoolSizeHint, PoolInfo::kUnknownClockFrequency, PoolInfo::kUnknownReadBandwidth, PoolInfo::kUnknownWriteBandwidth, 0, 0, {{target_host.value(), 1}}, Bool(true))})); From 8e225d9d01c4cec617360470aaf26f9ce502fb09 Mon Sep 17 00:00:00 2001 From: Lily Orth-Smith Date: Tue, 15 Feb 2022 13:24:33 -0800 Subject: [PATCH 2/4] Fix whitespace --- include/tvm/ir/memory_pools.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/tvm/ir/memory_pools.h b/include/tvm/ir/memory_pools.h index 12fb8a6a97c6..88d402ea0e0c 100644 --- a/include/tvm/ir/memory_pools.h +++ b/include/tvm/ir/memory_pools.h @@ -113,7 +113,6 @@ static constexpr const char* kTargetPoolReadWriteAccess = "rw"; class PoolInfo : public ObjectRef { public: - /*! * \brief The string parameter to indicate read only access to a pool * This needs to be kept in sync with PoolInfo.READ_ONLY_ACCESS in From aa96aba70ad2f36a60ccee15c03fe98d6ec7d352 Mon Sep 17 00:00:00 2001 From: Lily Orth-Smith Date: Tue, 15 Feb 2022 13:55:14 -0800 Subject: [PATCH 3/4] lint --- include/tvm/ir/memory_pools.h | 8 ++++---- src/tir/usmp/transform/assign_pool_info.cc | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/tvm/ir/memory_pools.h b/include/tvm/ir/memory_pools.h index 88d402ea0e0c..5db1f6f3b5cd 100644 --- a/include/tvm/ir/memory_pools.h +++ b/include/tvm/ir/memory_pools.h @@ -104,10 +104,10 @@ struct PoolInfoNode : public Object { }; /*! -* \brief The string parameter to indicate read and write access to a pool -* This needs to be kept in sync with PoolInfo.READ_WRITE_ACCESS in -* python/tvm/ir/memory_pools.py -*/ + * \brief The string parameter to indicate read and write access to a pool + * This needs to be kept in sync with PoolInfo.READ_WRITE_ACCESS in + * python/tvm/ir/memory_pools.py + */ static constexpr const char* kTargetPoolReadWriteAccess = "rw"; diff --git a/src/tir/usmp/transform/assign_pool_info.cc b/src/tir/usmp/transform/assign_pool_info.cc index 5768397773df..88184017b272 100644 --- a/src/tir/usmp/transform/assign_pool_info.cc +++ b/src/tir/usmp/transform/assign_pool_info.cc @@ -48,11 +48,11 @@ class PoolInfoAssigner : public StmtExprMutator { ICHECK(target_host) << "main function does not have a target attr"; WorkspaceMemoryPools workspace_pools = module->GetAttr(tvm::attr::kWorkspaceMemoryPools) - .value_or(WorkspaceMemoryPools({PoolInfo( - "global_workspace", {{target_host.value(), kTargetPoolReadWriteAccess}}, - PoolInfo::kUnrestrictedPoolSizeHint, PoolInfo::kUnknownClockFrequency, - PoolInfo::kUnknownReadBandwidth, PoolInfo::kUnknownWriteBandwidth, 0, 0, - {{target_host.value(), 1}}, Bool(true))})); + .value_or(WorkspaceMemoryPools( + {PoolInfo("global_workspace", {{target_host.value(), kTargetPoolReadWriteAccess}}, + PoolInfo::kUnrestrictedPoolSizeHint, PoolInfo::kUnknownClockFrequency, + PoolInfo::kUnknownReadBandwidth, PoolInfo::kUnknownWriteBandwidth, 0, 0, + {{target_host.value(), 1}}, Bool(true))})); Array pool_infos = workspace_pools->pools; for (const PoolInfo& pool_info : pool_infos) { for (const auto& kv : pool_info->target_access) { From dad7a839604a2f4566e1ee5e1e598d8259e79d13 Mon Sep 17 00:00:00 2001 From: Lily Orth-Smith Date: Tue, 15 Feb 2022 16:49:32 -0800 Subject: [PATCH 4/4] Move the other consts out of PoolInfo --- include/tvm/ir/memory_pools.h | 35 ++++++++++++---------- src/tir/usmp/algo/greedy.cc | 2 +- src/tir/usmp/transform/assign_pool_info.cc | 5 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/tvm/ir/memory_pools.h b/include/tvm/ir/memory_pools.h index 5db1f6f3b5cd..d4eefdc910b0 100644 --- a/include/tvm/ir/memory_pools.h +++ b/include/tvm/ir/memory_pools.h @@ -108,26 +108,29 @@ struct PoolInfoNode : public Object { * This needs to be kept in sync with PoolInfo.READ_WRITE_ACCESS in * python/tvm/ir/memory_pools.py */ - static constexpr const char* kTargetPoolReadWriteAccess = "rw"; +/*! + * \brief The string parameter to indicate read only access to a pool + * This needs to be kept in sync with PoolInfo.READ_ONLY_ACCESS in + * python/tvm/ir/memory_pools.py + */ +static constexpr const char* kTargetPoolReadOnlyAccess = "ro"; + +/*! \brief The PoolSize is unrestricted for the memory planner */ +static const int kUnrestrictedPoolSizeHint = -1; + +/*! \brief The clock frequency is not known */ +static const int kUnknownClockFrequency = -1; + +/*! \brief The read bandwidth is not known */ +static const int kUnknownReadBandwidth = -1; + +/*! \brief The write bandwidth is not known */ +static const int kUnknownWriteBandwidth = -1; + class PoolInfo : public ObjectRef { public: - /*! - * \brief The string parameter to indicate read only access to a pool - * This needs to be kept in sync with PoolInfo.READ_ONLY_ACCESS in - * python/tvm/ir/memory_pools.py - */ - static constexpr const char* kTargetPoolReadOnlyAccess = "ro"; - /*! \brief The PoolSize is unrestricted for the memory planner */ - static const int kUnrestrictedPoolSizeHint = -1; - /*! \brief The clock frequency is not known */ - static const int kUnknownClockFrequency = -1; - /*! \brief The read bandwidth is not known */ - static const int kUnknownReadBandwidth = -1; - /*! \brief The write bandwidth is not known */ - static const int kUnknownWriteBandwidth = -1; - TVM_DLL PoolInfo(String pool_name, Map target_access, Integer size_hint_bytes = kUnrestrictedPoolSizeHint, Integer clock_frequency_hz = kUnknownClockFrequency, diff --git a/src/tir/usmp/algo/greedy.cc b/src/tir/usmp/algo/greedy.cc index c4f7cabb99f1..8246ffc219c6 100644 --- a/src/tir/usmp/algo/greedy.cc +++ b/src/tir/usmp/algo/greedy.cc @@ -61,7 +61,7 @@ size_t GreedyBase::round_up_to_byte_alignment(const size_t& non_aligned_byte_off */ bool GreedyBase::IsValidPlacement(const PoolInfo& candidate_pool, const size_t& next_offset, const size_t& size_bytes) { - if (candidate_pool->size_hint_bytes == PoolInfo::kUnrestrictedPoolSizeHint) { + if (candidate_pool->size_hint_bytes == kUnrestrictedPoolSizeHint) { // this means pool is not bounded return true; } diff --git a/src/tir/usmp/transform/assign_pool_info.cc b/src/tir/usmp/transform/assign_pool_info.cc index 88184017b272..1c528351566e 100644 --- a/src/tir/usmp/transform/assign_pool_info.cc +++ b/src/tir/usmp/transform/assign_pool_info.cc @@ -50,9 +50,8 @@ class PoolInfoAssigner : public StmtExprMutator { module->GetAttr(tvm::attr::kWorkspaceMemoryPools) .value_or(WorkspaceMemoryPools( {PoolInfo("global_workspace", {{target_host.value(), kTargetPoolReadWriteAccess}}, - PoolInfo::kUnrestrictedPoolSizeHint, PoolInfo::kUnknownClockFrequency, - PoolInfo::kUnknownReadBandwidth, PoolInfo::kUnknownWriteBandwidth, 0, 0, - {{target_host.value(), 1}}, Bool(true))})); + kUnrestrictedPoolSizeHint, kUnknownClockFrequency, kUnknownReadBandwidth, + kUnknownWriteBandwidth, 0, 0, {{target_host.value(), 1}}, Bool(true))})); Array pool_infos = workspace_pools->pools; for (const PoolInfo& pool_info : pool_infos) { for (const auto& kv : pool_info->target_access) {