vt 1.6.0
(Virtual Transport)
Loading...
Searching...
No Matches
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
50#include "vt/rdmahandle/cache.h"
53
54#include <unordered_map>
55
56namespace vt { namespace rdma {
57
58namespace impl {
59
60struct ReduceLBMsg;
61
62} /* end namespace impl */
63
64template <typename T, HandleEnum E, typename IndexT>
65struct SubHandle {
68
69 SubHandle() = default;
70
71private:
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
82public:
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
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,
172 );
173
174private:
175 template <typename U>
176 void waitForHandleReady(Handle<U,E> const& h);
177
178protected:
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;
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*/
Definition base_index.h:49
Definition manager.h:65
Definition rdma_channel.cc:50
Lock
Definition lock_mpi.h:52
Definition activefn.h:51
PhysicalResourceType NodeType
Used to hold the current node/rank or the number of nodes.
Definition types_type.h:57
int64_t HandlerType
Used to hold a handler ID which identifier a function pointer/context.
Definition types_type.h:63
A indexable proxy to object instances on all nodes that are tied together with a common ID.
Definition proxy_objgroup.h:78
Definition cache.h:55
Handle specialization for index-level RDMA access (overdecomposed).
Definition handle.fwd.h:58
Definition index_info.h:51
Definition request_holder.h:56
uint64_t count_
Definition sub_handle.h:78
SubInfo(uint64_t in_count, uint64_t in_offset)
Definition sub_handle.h:74
uint64_t offset_
Definition sub_handle.h:79
void migratedInIndex(IndexT index)
Definition sub_handle.impl.h:554
std::size_t count_if_uniform_
Definition sub_handle.h:193
ProxyType proxy_
Definition sub_handle.h:179
std::vector< IndexT > migrate_out_
Definition sub_handle.h:195
bool ready_
Definition sub_handle.h:190
static void destroyCollective(ProxyType proxy)
Definition sub_handle.impl.h:528
void deleteHandle()
Definition sub_handle.impl.h:481
bool dense_start_with_zero_
Definition sub_handle.h:199
Handle< uint64_t, E > loc_handle_
Definition sub_handle.h:188
void makeSubHandles(bool initial=true)
Definition sub_handle.impl.h:67
Handle< T, E, IndexT > addLocalIndex(IndexT index, uint64_t count)
Definition sub_handle.impl.h:423
std::vector< IndexT > migrate_in_
Definition sub_handle.h:196
std::size_t getCount(IndexT const &idx, Lock l=Lock::Shared)
Definition sub_handle.impl.h:337
bool is_migratable_
Definition sub_handle.h:180
void put(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition sub_handle.impl.h:369
IndexT::DenseIndexType linearize(IndexT idx)
Definition sub_handle.impl.h:145
bool ordered_opt_
Definition sub_handle.h:197
std::unordered_map< IndexT, int > ordered_local_offset_
Definition sub_handle.h:198
void updateInfo(IndexT const &idx, IndexInfo info, NodeType home)
Definition sub_handle.impl.h:187
vt::objgroup::proxy::Proxy< SubHandle< T, E, IndexT > > ProxyType
Definition sub_handle.h:67
std::size_t collection_expected_count_
Definition sub_handle.h:194
std::size_t getNumActiveHandles() const
Definition sub_handle.impl.h:476
bool ready() const
Definition sub_handle.h:145
std::unordered_map< IndexT, std::size_t > sub_handles_staged_
Definition sub_handle.h:184
RequestHolder rget(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition sub_handle.impl.h:347
void waitForHandleReady(Handle< U, E > const &h)
Definition sub_handle.impl.h:517
vt::HandlerType map_han_
Definition sub_handle.h:181
void migratedOutIndex(IndexT index)
Definition sub_handle.impl.h:544
RequestHolder rput(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition sub_handle.impl.h:358
int getOrderedOffset(IndexT idx, NodeType home_node)
Definition sub_handle.impl.h:163
IndexT range_
Definition sub_handle.h:182
bool mpi2_
Definition sub_handle.h:191
Handle< T, vt::rdma::HandleEnum::StaticSize, IndexT > HandleType
Definition sub_handle.h:66
static ProxyType construct(bool in_is_migratable, IndexT in_range, bool in_dense_start_with_zero)
Definition sub_handle.impl.h:493
RequestHolder raccum(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset, MPI_Op op)
Definition sub_handle.impl.h:379
std::size_t getNumHandles() const
Definition sub_handle.impl.h:471
void destroy()
Definition sub_handle.impl.h:522
std::size_t getNumDeletedHandles() const
Definition sub_handle.impl.h:486
void stageLocalIndex(IndexT index, uint64_t count)
Definition sub_handle.impl.h:434
bool isUniform() const
Definition sub_handle.h:126
std::vector< uint64_t > sub_prefix_
Definition sub_handle.h:186
void access(IndexT idx, Lock l, Callable fn, uint64_t offset)
Definition sub_handle.impl.h:413
IndexInfo fetchInfo(IndexT const &idx)
Definition sub_handle.impl.h:228
void afterLB()
Definition sub_handle.impl.h:574
Handle< T, E > data_handle_
Definition sub_handle.h:187
Cache< IndexT > cache_
Definition sub_handle.h:189
bool uniform_size_
Definition sub_handle.h:192
uint64_t totalLocalCount() const
Definition sub_handle.impl.h:462
std::size_t getCollectionExpected() const
Definition sub_handle.impl.h:534
void get(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset)
Definition sub_handle.impl.h:327
void accum(IndexT const &idx, Lock l, T *ptr, uint64_t len, int offset, MPI_Op op)
Definition sub_handle.impl.h:391
std::unordered_map< IndexT, SubInfo > sub_handles_
Definition sub_handle.h:183
NodeType getHomeNode(IndexT const &idx)
Definition sub_handle.impl.h:155
T fetchOp(IndexT const &idx, Lock l, T ptr, int offset, MPI_Op op)
Definition sub_handle.impl.h:402
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
void setCollectionExpected(std::size_t count)
Definition sub_handle.impl.h:539
IndexInfo resolveLocation(IndexT const &idx)
Definition sub_handle.impl.h:310
std::vector< IndexT > sub_layout_
Definition sub_handle.h:185
std::size_t deleted_count_
Definition sub_handle.h:200
void checkChanged(impl::ReduceLBMsg *msg)
Definition sub_handle.impl.h:592
Definition sub_handle.impl.h:565