vt  1.5.0
(Virtual Transport)
sub_handle.h
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // *****************************************************************************
4 //
5 // sub_handle.h
6 // DARMA/vt => Virtual Transport
7 //
8 // Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9 // (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10 // Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are met:
14 //
15 // * Redistributions of source code must retain the above copyright notice,
16 // this list of conditions and the following disclaimer.
17 //
18 // * Redistributions in binary form must reproduce the above copyright notice,
19 // this list of conditions and the following disclaimer in the documentation
20 // and/or other materials provided with the distribution.
21 //
22 // * Neither the name of the copyright holder nor the names of its
23 // contributors may be used to endorse or promote products derived from this
24 // software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact darma@sandia.gov
39 //
40 // *****************************************************************************
41 //@HEADER
42 */
43 
44 #if !defined INCLUDED_VT_RDMAHANDLE_SUB_HANDLE_H
45 #define INCLUDED_VT_RDMAHANDLE_SUB_HANDLE_H
46 
48 #include "vt/rdmahandle/handle.h"
50 #include "vt/rdmahandle/cache.h"
53 
54 #include <unordered_map>
55 
56 namespace vt { namespace rdma {
57 
58 namespace impl {
59 
60 struct ReduceLBMsg;
61 
62 } /* end namespace impl */
63 
64 template <typename T, HandleEnum E, typename IndexT>
65 struct SubHandle {
68 
69  SubHandle() = default;
70 
71 private:
72  struct SubInfo {
73  SubInfo() = default;
74  SubInfo(uint64_t in_count, uint64_t in_offset)
75  : count_(in_count),
76  offset_(in_offset)
77  { }
78  uint64_t count_ = 0;
79  uint64_t offset_ = 0;
80  };
81 
82 public:
83  void initialize(
84  ProxyType in_proxy, bool in_is_migratable, IndexT in_range,
85  vt::HandlerType map_han, bool in_dense_start_with_zero
86  );
87 
88  void makeSubHandles(bool initial = true);
89 
90  typename IndexT::DenseIndexType linearize(IndexT idx);
91 
92  NodeType getHomeNode(IndexT const& idx);
93 
94  IndexInfo fetchInfo(IndexT const& idx);
95 
96  void updateInfo(IndexT const& idx, IndexInfo info, NodeType home);
97 
98  IndexInfo resolveLocation(IndexT const& idx);
99 
100  void get(IndexT const& idx, Lock l, T* ptr, uint64_t len, int offset);
101 
102  std::size_t getCount(IndexT const& idx, Lock l = Lock::Shared);
103 
105  IndexT const& idx, Lock l, T* ptr, uint64_t len, int offset
106  );
107 
109  IndexT const& idx, Lock l, T* ptr, uint64_t len, int offset
110  );
111 
112  void put(IndexT const& idx, Lock l, T* ptr, uint64_t len, int offset);
113 
115  IndexT const& idx, Lock l, T* ptr, uint64_t len, int offset,
116  MPI_Op op
117  );
118 
119  void accum(
120  IndexT const& idx, Lock l, T* ptr, uint64_t len, int offset,
121  MPI_Op op
122  );
123 
124  T fetchOp(IndexT const& idx, Lock l, T ptr, int offset, MPI_Op op);
125 
126  bool isUniform() const { return uniform_size_; }
127 
128  template <typename Callable>
129  void access(IndexT idx, Lock l, Callable fn, uint64_t offset);
130 
131  Handle<T, E, IndexT> addLocalIndex(IndexT index, uint64_t count);
132 
133  int getOrderedOffset(IndexT idx, NodeType home_node);
134 
135  void stageLocalIndex(IndexT index, uint64_t count);
136 
137  void migratedOutIndex(IndexT index);
138 
139  void migratedInIndex(IndexT index);
140 
141  void afterLB();
142 
143  void checkChanged(impl::ReduceLBMsg* msg);
144 
145  bool ready() const { return ready_; }
146 
147  uint64_t totalLocalCount() const;
148 
149  std::size_t getNumHandles() const;
150 
151  std::size_t getNumActiveHandles() const;
152 
153  void deleteHandle();
154 
155  std::size_t getNumDeletedHandles() const;
156 
157  std::size_t getCollectionExpected() const;
158 
159  void setCollectionExpected(std::size_t count);
160 
161  void destroy();
162 
163  static void destroyCollective(ProxyType proxy);
164 
165  template <mapping::ActiveMapTypedFnType<IndexT> map_fn>
166  static ProxyType construct(
167  bool in_is_migratable, IndexT in_range, bool in_dense_start_with_zero
168  );
169  static ProxyType construct(
170  bool in_is_migratable, IndexT in_range, bool in_dense_start_with_zero,
171  vt::HandlerType map
172  );
173 
174 private:
175  template <typename U>
176  void waitForHandleReady(Handle<U,E> const& h);
177 
178 protected:
180  bool is_migratable_ = false;
182  IndexT range_ = {};
183  std::unordered_map<IndexT, SubInfo> sub_handles_;
184  std::unordered_map<IndexT, std::size_t> sub_handles_staged_;
185  std::vector<IndexT> sub_layout_;
186  std::vector<uint64_t> sub_prefix_;
190  bool ready_ = false;
191  bool mpi2_ = false;
192  bool uniform_size_ = false;
193  std::size_t count_if_uniform_ = 0;
194  std::size_t collection_expected_count_ = 0;
195  std::vector<IndexT> migrate_out_;
196  std::vector<IndexT> migrate_in_;
197  bool ordered_opt_ = true;
198  std::unordered_map<IndexT, int> ordered_local_offset_;
200  std::size_t deleted_count_ = 0;
201 };
202 
203 }} /* end namespace vt::rdma */
204 
206 
207 #endif /*INCLUDED_VT_RDMAHANDLE_SUB_HANDLE_H*/
vt::rdma::SubHandle::getNumHandles
std::size_t getNumHandles() const
Definition: sub_handle.impl.h:471
vt::rdma::SubHandle::migratedInIndex
void migratedInIndex(IndexT index)
Definition: sub_handle.impl.h:554
vt::rdma::SubHandle::waitForHandleReady
void waitForHandleReady(Handle< U, E > const &h)
Definition: sub_handle.impl.h:517
vt::rdma::SubHandle::is_migratable_
bool is_migratable_
Definition: sub_handle.h:180
vt::rdma::SubHandle::getOrderedOffset
int getOrderedOffset(IndexT idx, NodeType home_node)
Definition: sub_handle.impl.h:163
vt::rdma::Lock
Lock
Definition: lock_mpi.h:52
vt::rdma::SubHandle::fetchInfo
IndexInfo fetchInfo(IndexT const &idx)
Definition: sub_handle.impl.h:228
vt::rdma::SubHandle::range_
IndexT range_
Definition: sub_handle.h:182
vt::rdma::SubHandle::setCollectionExpected
void setCollectionExpected(std::size_t count)
Definition: sub_handle.impl.h:539
vt::rdma::SubHandle::resolveLocation
IndexInfo resolveLocation(IndexT const &idx)
Definition: sub_handle.impl.h:310
vt::rdma::SubHandle::ProxyType
vt::objgroup::proxy::Proxy< SubHandle< T, E, IndexT > > ProxyType
Definition: sub_handle.h:67
vt::rdma::SubHandle::migrate_out_
std::vector< IndexT > migrate_out_
Definition: sub_handle.h:195
vt::rdma::SubHandle::dense_start_with_zero_
bool dense_start_with_zero_
Definition: sub_handle.h:199
vt::rdma::SubHandle::SubInfo::SubInfo
SubInfo(uint64_t in_count, uint64_t in_offset)
Definition: sub_handle.h:74
vt::rdma::SubHandle::deleteHandle
void deleteHandle()
Definition: sub_handle.impl.h:481
vt::HandlerType
int64_t HandlerType
Used to hold a handler ID which identifier a function pointer/context.
Definition: types_type.h:63
vt::rdma::SubHandle::SubInfo
Definition: sub_handle.h:72
vt::rdma::SubHandle::isUniform
bool isUniform() const
Definition: sub_handle.h:126
vt::rdma::SubHandle::SubInfo::count_
uint64_t count_
Definition: sub_handle.h:78
vt::rdma::SubHandle::map_han_
vt::HandlerType map_han_
Definition: sub_handle.h:181
vt::rdma::SubHandle::stageLocalIndex
void stageLocalIndex(IndexT index, uint64_t count)
Definition: sub_handle.impl.h:434
vt::rdma::SubHandle::getNumDeletedHandles
std::size_t getNumDeletedHandles() const
Definition: sub_handle.impl.h:486
vt::NodeType
PhysicalResourceType NodeType
Used to hold the current node/rank or the number of nodes.
Definition: types_type.h:57
vt::rdma::SubHandle::getCount
std::size_t getCount(IndexT const &idx, Lock l=Lock::Shared)
Definition: sub_handle.impl.h:337
vt::rdma::SubHandle::SubHandle
SubHandle()=default
vt::rdma::SubHandle::migrate_in_
std::vector< IndexT > migrate_in_
Definition: sub_handle.h:196
vt::rdma::SubHandle::migratedOutIndex
void migratedOutIndex(IndexT index)
Definition: sub_handle.impl.h:544
vt::rdma::SubHandle::sub_handles_
std::unordered_map< IndexT, SubInfo > sub_handles_
Definition: sub_handle.h:183
vt::rdma::SubHandle::get
void get(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition: sub_handle.impl.h:327
vt::rdma::SubHandle::rget
RequestHolder rget(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition: sub_handle.impl.h:347
vt::rdma::SubHandle::put
void put(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition: sub_handle.impl.h:369
vt::rdma::SubHandle::rput
RequestHolder rput(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition: sub_handle.impl.h:358
vt::rdma::SubHandle::raccum
RequestHolder raccum(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset, MPI_Op op)
Definition: sub_handle.impl.h:379
vt::rdma::SubHandle::SubInfo::offset_
uint64_t offset_
Definition: sub_handle.h:79
vt::rdma::SubHandle::initialize
void initialize(ProxyType in_proxy, bool in_is_migratable, IndexT in_range, vt::HandlerType map_han, bool in_dense_start_with_zero)
Definition: sub_handle.impl.h:54
vt::rdma::SubHandle::fetchOp
T fetchOp(IndexT const &idx, Lock l, T ptr, int offset, MPI_Op op)
Definition: sub_handle.impl.h:402
dense.h
vt::rdma::SubHandle::uniform_size_
bool uniform_size_
Definition: sub_handle.h:192
vt::rdma::SubHandle::totalLocalCount
uint64_t totalLocalCount() const
Definition: sub_handle.impl.h:462
vt::rdma::SubHandle::mpi2_
bool mpi2_
Definition: sub_handle.h:191
vt::rdma::RequestHolder
Definition: request_holder.h:56
handle.h
sub_handle.impl.h
index_info.h
vt::rdma::Lock::Shared
vt::rdma::Cache
Definition: cache.h:55
vt::rdma::SubHandle::ordered_opt_
bool ordered_opt_
Definition: sub_handle.h:197
vt::rdma::SubHandle::sub_layout_
std::vector< IndexT > sub_layout_
Definition: sub_handle.h:185
vt
Definition: activefn.h:51
vt::objgroup::proxy::Proxy< SubHandle< T, E, IndexT > >
vt::rdma::SubHandle::destroyCollective
static void destroyCollective(ProxyType proxy)
Definition: sub_handle.impl.h:528
vt::rdma::SubHandle::collection_expected_count_
std::size_t collection_expected_count_
Definition: sub_handle.h:194
vt::rdma::SubHandle::destroy
void destroy()
Definition: sub_handle.impl.h:522
vt::rdma::SubHandle::sub_prefix_
std::vector< uint64_t > sub_prefix_
Definition: sub_handle.h:186
mapping_headers.h
cache.h
vt::rdma::SubHandle::SubInfo::SubInfo
SubInfo()=default
vt::rdma::SubHandle::getHomeNode
NodeType getHomeNode(IndexT const &idx)
Definition: sub_handle.impl.h:155
vt::rdma::SubHandle::sub_handles_staged_
std::unordered_map< IndexT, std::size_t > sub_handles_staged_
Definition: sub_handle.h:184
vt::rdma::SubHandle::addLocalIndex
Handle< T, E, IndexT > addLocalIndex(IndexT index, uint64_t count)
Definition: sub_handle.impl.h:423
vt::rdma::SubHandle::loc_handle_
Handle< uint64_t, E > loc_handle_
Definition: sub_handle.h:188
vt::rdma::SubHandle::makeSubHandles
void makeSubHandles(bool initial=true)
Definition: sub_handle.impl.h:67
vt::rdma::SubHandle::linearize
IndexT::DenseIndexType linearize(IndexT idx)
Definition: sub_handle.impl.h:145
vt::rdma::SubHandle::count_if_uniform_
std::size_t count_if_uniform_
Definition: sub_handle.h:193
vt::rdma::SubHandle::getCollectionExpected
std::size_t getCollectionExpected() const
Definition: sub_handle.impl.h:534
vt::config::rdma
Definition: debug_config.h:63
vt::rdma::SubHandle::proxy_
ProxyType proxy_
Definition: sub_handle.h:179
vt::rdma::SubHandle::accum
void accum(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset, MPI_Op op)
Definition: sub_handle.impl.h:391
vt::rdma::SubHandle::afterLB
void afterLB()
Definition: sub_handle.impl.h:574
types_type.h
vt::rdma::SubHandle::ready_
bool ready_
Definition: sub_handle.h:190
vt::rdma::SubHandle::data_handle_
Handle< T, E > data_handle_
Definition: sub_handle.h:187
vt::rdma::IndexInfo
Definition: index_info.h:51
vt::rdma::Handle
Handle specialization for index-level RDMA access (overdecomposed)
Definition: handle.fwd.h:58
vt::rdma::SubHandle::ordered_local_offset_
std::unordered_map< IndexT, int > ordered_local_offset_
Definition: sub_handle.h:198
vt::rdma::SubHandle::ready
bool ready() const
Definition: sub_handle.h:145
vt::rdma::impl::ReduceLBMsg
Definition: sub_handle.impl.h:565
vt::rdma::SubHandle::deleted_count_
std::size_t deleted_count_
Definition: sub_handle.h:200
vt::rdma::SubHandle::getNumActiveHandles
std::size_t getNumActiveHandles() const
Definition: sub_handle.impl.h:476
vt::rdma::SubHandle::construct
static ProxyType construct(bool in_is_migratable, IndexT in_range, bool in_dense_start_with_zero)
Definition: sub_handle.impl.h:493
vt::rdma::SubHandle::updateInfo
void updateInfo(IndexT const &idx, IndexInfo info, NodeType home)
Definition: sub_handle.impl.h:187
vt::rdma::SubHandle::checkChanged
void checkChanged(impl::ReduceLBMsg *msg)
Definition: sub_handle.impl.h:592
vt::rdma::SubHandle::access
void access(IndexT idx, Lock l, Callable fn, uint64_t offset)
Definition: sub_handle.impl.h:413
vt::rdma::SubHandle::cache_
Cache< IndexT > cache_
Definition: sub_handle.h:189