Itoyori  v0.0.1
coll_mem_manager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ityr/common/util.hpp"
4 #include "ityr/ori/util.hpp"
6 #include "ityr/ori/coll_mem.hpp"
7 
8 namespace ityr::ori {
9 
11 public:
13 
14  coll_mem& get(void* addr) {
15  for (auto [addr_begin, addr_end, id] : coll_mem_ids_) {
16  if (addr_begin <= addr && addr < addr_end) {
17  return *coll_mems_[id];
18  }
19  }
20  common::die("Address %p was passed but not allocated by Itoyori", addr);
21  }
22 
23  coll_mem& create(std::size_t size, std::unique_ptr<mem_mapper::base> mmapper) {
24  coll_mem_id_t id = coll_mems_.size();
25 
26  coll_mem& cm = *coll_mems_.emplace_back(std::in_place, size, id, std::move(mmapper));
27  std::byte* raw_ptr = reinterpret_cast<std::byte*>(cm.vm().addr());
28 
29  coll_mem_ids_.emplace_back(std::make_tuple(raw_ptr, raw_ptr + size, id));
30 
31  return cm;
32  }
33 
34  void destroy(coll_mem& cm) {
35  std::byte* p = reinterpret_cast<std::byte*>(cm.vm().addr());
36  auto it = std::find(coll_mem_ids_.begin(), coll_mem_ids_.end(),
37  std::make_tuple(p, p + cm.size(), cm.id()));
38  ITYR_CHECK(it != coll_mem_ids_.end());
39  coll_mem_ids_.erase(it);
40 
41  coll_mems_[cm.id()].reset();
42  }
43 
44 private:
45  std::vector<std::optional<coll_mem>> coll_mems_;
46  std::vector<std::tuple<void*, void*, coll_mem_id_t>> coll_mem_ids_;
47 };
48 
49 }
void * addr() const
Definition: virtual_mem.hpp:46
Definition: coll_mem_manager.hpp:10
coll_mem & create(std::size_t size, std::unique_ptr< mem_mapper::base > mmapper)
Definition: coll_mem_manager.hpp:23
coll_mem_manager()
Definition: coll_mem_manager.hpp:12
void destroy(coll_mem &cm)
Definition: coll_mem_manager.hpp:34
coll_mem & get(void *addr)
Definition: coll_mem_manager.hpp:14
Definition: coll_mem.hpp:16
coll_mem_id_t id() const
Definition: coll_mem.hpp:33
std::size_t size() const
Definition: coll_mem.hpp:34
const common::virtual_mem & vm() const
Definition: coll_mem.hpp:41
#define ITYR_CHECK(cond)
Definition: util.hpp:48
Definition: block_region_set.hpp:9
uint64_t coll_mem_id_t
Definition: coll_mem.hpp:14
constexpr auto size(const checkout_span< T, Mode > &cs) noexcept
Definition: checkout_span.hpp:178
ForwardIteratorD move(const ExecutionPolicy &policy, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIteratorD first_d)
Move a range to another.
Definition: parallel_loop.hpp:934