Itoyori  v0.0.1
callstack.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <optional>
4 
5 #include "ityr/common/util.hpp"
11 
12 namespace ityr::ito {
13 
14 class callstack {
15 public:
16  callstack(std::size_t size)
17  : vm_(common::reserve_same_vm_coll(size, common::get_page_size())),
18  pm_(init_stack_pm()),
19  win_(common::topology::mpicomm(), reinterpret_cast<std::byte*>(vm_.addr()), vm_.size()) {}
20 
21  void* top() const { return vm_.addr(); }
22  void* bottom() const { return reinterpret_cast<std::byte*>(vm_.addr()) + vm_.size(); }
23  std::size_t size() const { return vm_.size(); }
24 
25  void direct_copy_from(void* addr,
26  std::size_t size,
27  common::topology::rank_t target_rank) const {
28  ITYR_CHECK(target_rank != common::topology::my_rank());
29  ITYR_CHECK(target_rank < common::topology::n_ranks());
30  ITYR_CHECK(vm_.addr() <= addr);
31  ITYR_CHECK(reinterpret_cast<std::byte*>(addr) + size <= reinterpret_cast<std::byte*>(vm_.addr()) + vm_.size());
32 
33  auto target_disp = reinterpret_cast<uintptr_t>(addr) - reinterpret_cast<uintptr_t>(vm_.addr());
34  common::mpi_get(reinterpret_cast<std::byte*>(addr), size, target_rank, target_disp, win_.win());
35  }
36 
37 private:
38  static std::string stack_shmem_name(int rank) {
39  std::stringstream ss;
40  ss << "/ityr_ito_stack_" << rank;
41  return ss.str();
42  }
43 
44  common::physical_mem init_stack_pm() {
45  common::physical_mem pm(stack_shmem_name(common::topology::my_rank()), vm_.size(), true);
46  pm.map_to_vm(vm_.addr(), vm_.size(), 0);
47  return pm;
48  }
49 
50  common::virtual_mem vm_;
51  common::physical_mem pm_;
52  common::mpi_win_manager<std::byte> win_;
53 };
54 
55 }
MPI_Win win() const
Definition: mpi_rma.hpp:409
Definition: physical_mem.hpp:18
void * addr() const
Definition: virtual_mem.hpp:46
std::size_t size() const
Definition: virtual_mem.hpp:47
Definition: callstack.hpp:14
std::size_t size() const
Definition: callstack.hpp:23
callstack(std::size_t size)
Definition: callstack.hpp:16
void direct_copy_from(void *addr, std::size_t size, common::topology::rank_t target_rank) const
Definition: callstack.hpp:25
void * bottom() const
Definition: callstack.hpp:22
void * top() const
Definition: callstack.hpp:21
#define ITYR_CHECK(cond)
Definition: util.hpp:48
rank_t n_ranks()
Definition: topology.hpp:208
int rank_t
Definition: topology.hpp:12
MPI_Comm mpicomm()
Definition: topology.hpp:206
rank_t my_rank()
Definition: topology.hpp:207
void mpi_get(T *origin, std::size_t count, int target_rank, std::size_t target_disp, MPI_Win win)
Definition: mpi_rma.hpp:69
std::size_t get_page_size()
Definition: util.hpp:170
virtual_mem reserve_same_vm_coll(std::size_t size, std::size_t alignment=alignof(max_align_t))
Definition: virtual_mem.hpp:170
Definition: aarch64.hpp:5