OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TieredCpuBufferMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
20 
21 namespace CudaMgr_Namespace {
22 class CudaMgr;
23 }
24 
25 namespace Data_Namespace {
26 constexpr size_t numCpuTiers = 2;
27 enum CpuTier { DRAM = 0, PMEM = 1 };
28 using CpuTierSizeVector = std::vector<size_t>;
29 } // namespace Data_Namespace
30 
31 namespace Buffer_Namespace {
32 
34  public:
35  TieredCpuBufferMgr(const int device_id,
36  const size_t total_size,
38  const size_t min_slab_size,
39  const size_t max_slab_size,
40  const size_t default_slab_size,
41  const size_t page_size,
42  const CpuTierSizeVector& cpu_tier_sizes,
43  AbstractBufferMgr* parent_mgr = nullptr);
44 
45  ~TieredCpuBufferMgr() override {
46  // The destruction of the allocators automatically frees all memory
47  }
48 
49  // Needed for testing to replace allocators with Mocks.
50  std::vector<std::pair<std::unique_ptr<Arena>, size_t>>& getAllocators() {
51  return allocators_;
52  }
53 
54  inline MgrType getMgrType() override { return TIERED_CPU_MGR; }
55  inline std::string getStringMgrType() override { return ToString(TIERED_CPU_MGR); }
56  Arena* getAllocatorForSlab(int32_t slab_num) const;
57  std::string dump() const;
58 
59  private:
60  void addSlab(const size_t slab_size) override;
61  void freeAllMem() override;
62  void initializeMem() override;
63 
64  // A vector of allocators (order in vector denotes priority for use). These allocators
65  // should represent various tiers of memory we intend to use, such as DRAM, PMEM, and
66  // HBMEM. The size specifies the maximum space is allowed for each allocator.
67  std::vector<std::pair<std::unique_ptr<Arena>, size_t>> allocators_;
68  // Map to track which slabs were created by which allocator (may not be necessary
69  // later).
70  std::map<int32_t, Arena*> slab_to_allocator_map_;
71 };
72 
73 } // namespace Buffer_Namespace
std::vector< std::pair< std::unique_ptr< Arena >, size_t > > & getAllocators()
constexpr size_t numCpuTiers
std::map< int32_t, Arena * > slab_to_allocator_map_
std::vector< std::pair< std::unique_ptr< Arena >, size_t > > allocators_
void addSlab(const size_t slab_size) override
Arena * getAllocatorForSlab(int32_t slab_num) const
std::vector< size_t > CpuTierSizeVector
TieredCpuBufferMgr(const int device_id, const size_t total_size, CudaMgr_Namespace::CudaMgr *cuda_mgr, const size_t min_slab_size, const size_t max_slab_size, const size_t default_slab_size, const size_t page_size, const CpuTierSizeVector &cpu_tier_sizes, AbstractBufferMgr *parent_mgr=nullptr)