OmniSciDB  72c90bc290
 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 page_size,
41  const CpuTierSizeVector& cpu_tier_sizes,
42  AbstractBufferMgr* parent_mgr = nullptr);
43 
44  ~TieredCpuBufferMgr() override {
45  // The destruction of the allocators automatically frees all memory
46  }
47 
48  // Needed for testing to replace allocators with Mocks.
49  std::vector<std::pair<std::unique_ptr<Arena>, size_t>>& getAllocators() {
50  return allocators_;
51  }
52 
53  inline MgrType getMgrType() override { return TIERED_CPU_MGR; }
54  inline std::string getStringMgrType() override { return ToString(TIERED_CPU_MGR); }
55  Arena* getAllocatorForSlab(int32_t slab_num) const;
56  std::string dump() const;
57 
58  private:
59  void addSlab(const size_t slab_size) override;
60  void freeAllMem() override;
61  void initializeMem() override;
62 
63  // A vector of allocators (order in vector denotes priority for use). These allocators
64  // should represent various tiers of memory we intend to use, such as DRAM, PMEM, and
65  // HBMEM. The size specifies the maximum space is allowed for each allocator.
66  std::vector<std::pair<std::unique_ptr<Arena>, size_t>> allocators_;
67  // Map to track which slabs were created by which allocator (may not be necessary
68  // later).
69  std::map<int32_t, Arena*> slab_to_allocator_map_;
70 };
71 
72 } // 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_
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 page_size, const CpuTierSizeVector &cpu_tier_sizes, AbstractBufferMgr *parent_mgr=nullptr)
void addSlab(const size_t slab_size) override
Arena * getAllocatorForSlab(int32_t slab_num) const
std::vector< size_t > CpuTierSizeVector