From a8bd873ca402ab887d4ae551d85fb0f7afc32dc2 Mon Sep 17 00:00:00 2001 From: Austin Ho Date: Tue, 2 Apr 2024 14:28:45 +0000 Subject: [PATCH] #0: Return const ref sharded buffer structs --- tt_metal/impl/buffers/buffer.hpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tt_metal/impl/buffers/buffer.hpp b/tt_metal/impl/buffers/buffer.hpp index 0de7991a1d6..15da9122737 100644 --- a/tt_metal/impl/buffers/buffer.hpp +++ b/tt_metal/impl/buffers/buffer.hpp @@ -191,11 +191,11 @@ class Buffer { return this->shard_parameters_.value(); } - std::vector get_dev_page_to_host_page_mapping() const { + const std::vector& get_dev_page_to_host_page_mapping() const { return dev_page_to_host_page_mapping_; } - std::vector get_host_page_to_dev_page_mapping() const { + const std::vector& get_host_page_to_dev_page_mapping() const { return host_page_to_dev_page_mapping_; } @@ -218,17 +218,17 @@ class Buffer { } - std::vector all_cores() const{ + const std::vector& all_cores() const{ TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); return all_cores_; } - std::vector< std::vector > core_host_page_indices() const{ + const std::vector< std::vector >& core_host_page_indices() const{ TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); return core_host_page_indices_; } - uint32_t num_cores() const{ + uint32_t num_cores() const { if(!is_sharded(this->buffer_layout_)) return 1; else{ @@ -238,25 +238,26 @@ class Buffer { } } - std::unordered_map core_to_core_id() const{ + const std::unordered_map& core_to_core_id() const{ TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); return core_to_core_id_; } - std::vector host_pages_in_shard(uint32_t core_id) const + const std::vector& host_pages_in_shard(uint32_t core_id) const { TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); return core_host_page_indices_[core_id]; } - std::vector host_pages_in_shard(CoreCoord core) const + const std::vector& host_pages_in_shard(CoreCoord core) const { TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); auto core_id = core_to_core_id_.at(core); return core_host_page_indices_[core_id]; } - std::vector dev_pages_in_shard(const uint32_t & core_id) const + // Why is this dynamic? + const std::vector dev_pages_in_shard(const uint32_t & core_id) const { TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); std::vector ret_vec; @@ -268,14 +269,14 @@ class Buffer { return ret_vec; } - std::vector dev_pages_in_shard(const CoreCoord & core) const + const std::vector dev_pages_in_shard(const CoreCoord & core) const { TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); auto core_id = core_to_core_id_.at(core); return dev_pages_in_shard(core_id); } - std::vector get_host_page_to_local_shard_page_mapping() const + const std::vector& get_host_page_to_local_shard_page_mapping() const { TT_ASSERT(is_sharded(this->buffer_layout_) , "Buffer not sharded"); return host_page_to_local_shard_page_mapping_;