37 base(std::size_t
size,
int n_inter_ranks,
int n_intra_ranks)
63 template <block_
size_t BlockSize>
66 block(std::size_t
size,
int n_inter_ranks,
int n_intra_ranks)
67 :
base(
size, n_inter_ranks, n_intra_ranks),
68 n_blk_((
size + BlockSize - 1) / BlockSize) {}
70 std::size_t
block_size()
const override {
return BlockSize; }
74 auto [blk_id_b, blk_id_e] = get_seg_range(seg_id);
75 return std::max(std::size_t(1), blk_id_e - blk_id_b) * BlockSize;
79 return n_blk_ * BlockSize;
85 std::size_t blk_id = offset / BlockSize;
88 auto [blk_id_b, blk_id_e] = get_seg_range(seg_id);
103 std::size_t blk_id = pm_offset / BlockSize;
113 blk_id_b * BlockSize,
114 blk_id_e * BlockSize};
122 std::tuple<std::size_t, std::size_t> get_seg_range(
int seg_id)
const {
125 return {blk_id_b, blk_id_e};
131 ITYR_TEST_CASE(
"[ityr::ori::mem_mapper::block] calculate local block size") {
133 auto local_block_size = [](std::size_t
size,
int n_inter_ranks,
int inter_rank) -> std::size_t {
136 ITYR_CHECK(local_block_size(bs * 4 , 4, 0) == bs );
137 ITYR_CHECK(local_block_size(bs * 12 , 4, 0) == bs * 3);
138 ITYR_CHECK(local_block_size(bs * 14 , 4, 0) == bs * 4);
139 ITYR_CHECK(local_block_size(bs * 14 , 4, 1) == bs * 3);
140 ITYR_CHECK(local_block_size(bs * 14 , 4, 2) == bs * 4);
141 ITYR_CHECK(local_block_size(bs * 14 , 4, 3) == bs * 3);
142 ITYR_CHECK(local_block_size(1 , 4, 0) == bs );
143 ITYR_CHECK(local_block_size(1 , 4, 1) == bs );
144 ITYR_CHECK(local_block_size(1 , 1, 0) == bs );
145 ITYR_CHECK(local_block_size(bs * 3 , 1, 0) == bs * 3);
148 ITYR_TEST_CASE(
"[ityr::ori::mem_mapper::block] get block information at specified offset") {
150 auto get_segment = [](std::size_t
size,
int n_inter_ranks, std::size_t offset) -> segment {
151 return block<bs>(
size, n_inter_ranks, 1).get_segment(offset);
153 ITYR_CHECK(get_segment(bs * 4 , 4, 0 ) == (segment{0, 0 , bs , 0}));
154 ITYR_CHECK(get_segment(bs * 4 , 4, bs ) == (segment{1, bs , bs * 2 , 0}));
155 ITYR_CHECK(get_segment(bs * 4 , 4, bs * 2 ) == (segment{2, bs * 2 , bs * 3 , 0}));
156 ITYR_CHECK(get_segment(bs * 4 , 4, bs * 3 ) == (segment{3, bs * 3 , bs * 4 , 0}));
157 ITYR_CHECK(get_segment(bs * 4 , 4, bs * 4 - 1 ) == (segment{3, bs * 3 , bs * 4 , 0}));
158 ITYR_CHECK(get_segment(bs * 14 , 4, 0 ) == (segment{0, 0 , bs * 4 , 0}));
159 ITYR_CHECK(get_segment(bs * 14 , 4, bs ) == (segment{0, 0 , bs * 4 , 0}));
160 ITYR_CHECK(get_segment(bs * 14 , 4, bs * 5 ) == (segment{1, bs * 4 , bs * 7 , 0}));
161 ITYR_CHECK(get_segment(bs * 14 - 1, 4, bs * 14 - 1) == (segment{3, bs * 11, bs * 14, 0}));
164 template <block_
size_t BlockSize>
167 cyclic(std::size_t
size,
int n_inter_ranks,
int n_intra_ranks, std::size_t seg_size = BlockSize)
168 :
base(
size, n_inter_ranks, n_intra_ranks),
169 seg_size_(seg_size) {
174 std::size_t
block_size()
const override {
return BlockSize; }
177 return local_size_impl();
186 std::size_t blk_id_g = offset / seg_size_;
189 blk_id_g * seg_size_,
190 (blk_id_g + 1) * seg_size_,
191 blk_id_l * seg_size_};
205 std::size_t local_size_impl()
const {
206 std::size_t n_blk_g = (
size_ + seg_size_ - 1) / seg_size_;
208 return n_blk_l * seg_size_;
211 std::size_t seg_size_;
214 ITYR_TEST_CASE(
"[ityr::ori::mem_mapper::cyclic] calculate local block size") {
216 std::size_t ss = bs * 2;
217 auto local_block_size = [=](std::size_t
size,
int n_inter_ranks,
int inter_rank) -> std::size_t {
218 return cyclic<bs>(
size, n_inter_ranks, 1, ss).local_size(
inter_rank);
220 ITYR_CHECK(local_block_size(ss * 4 , 4, 0) == ss );
221 ITYR_CHECK(local_block_size(ss * 12 , 4, 0) == ss * 3);
222 ITYR_CHECK(local_block_size(ss * 13 , 4, 0) == ss * 4);
223 ITYR_CHECK(local_block_size(ss * 12 + 1, 4, 0) == ss * 4);
224 ITYR_CHECK(local_block_size(ss * 12 - 1, 4, 0) == ss * 3);
225 ITYR_CHECK(local_block_size(1 , 4, 0) == ss );
226 ITYR_CHECK(local_block_size(1 , 1, 0) == ss );
227 ITYR_CHECK(local_block_size(ss * 3 , 1, 0) == ss * 3);
230 ITYR_TEST_CASE(
"[ityr::ori::mem_mapper::cyclic] get block information at specified offset") {
232 std::size_t ss = bs * 2;
233 auto get_segment = [=](std::size_t
size,
int n_inter_ranks, std::size_t offset) -> segment {
234 return cyclic<bs>(
size, n_inter_ranks, 1, ss).get_segment(offset);
236 ITYR_CHECK(get_segment(ss * 4 , 4, 0 ) == (segment{0, 0 , ss , 0 }));
237 ITYR_CHECK(get_segment(ss * 4 , 4, ss ) == (segment{1, ss , ss * 2 , 0 }));
238 ITYR_CHECK(get_segment(ss * 4 , 4, ss * 2 ) == (segment{2, ss * 2 , ss * 3 , 0 }));
239 ITYR_CHECK(get_segment(ss * 4 , 4, ss * 3 ) == (segment{3, ss * 3 , ss * 4 , 0 }));
240 ITYR_CHECK(get_segment(ss * 4 , 4, ss * 4 - 1) == (segment{3, ss * 3 , ss * 4 , 0 }));
241 ITYR_CHECK(get_segment(ss * 12 , 4, 0 ) == (segment{0, 0 , ss , 0 }));
242 ITYR_CHECK(get_segment(ss * 12 , 4, ss ) == (segment{1, ss , ss * 2 , 0 }));
243 ITYR_CHECK(get_segment(ss * 12 , 4, ss * 3 ) == (segment{3, ss * 3 , ss * 4 , 0 }));
244 ITYR_CHECK(get_segment(ss * 12 , 4, ss * 5 + 2) == (segment{1, ss * 5 , ss * 6 , ss }));
245 ITYR_CHECK(get_segment(ss * 12 - 1, 4, ss * 11 ) == (segment{3, ss * 11, ss * 12, ss * 2}));
248 template <block_
size_t BlockSize>
252 :
base(
size, n_inter_ranks, n_intra_ranks),
253 n_blk_((
size + BlockSize - 1) / BlockSize) {}
255 std::size_t
block_size()
const override {
return BlockSize; }
259 auto [blk_id_b, blk_id_e] = get_seg_range(seg_id);
260 return std::max(std::size_t(1), blk_id_e - blk_id_b) * BlockSize;
264 return n_blk_ * BlockSize;
270 std::size_t blk_id = offset / BlockSize;
271 int seg_id = ((blk_id + 1) *
n_inter_ranks_ + n_blk_ - 1) / n_blk_ - 1;
273 auto [blk_id_b, blk_id_e] = get_seg_range(seg_id);
278 blk_id_b * BlockSize,
279 blk_id_e * BlockSize,
288 std::size_t blk_id = pm_offset / BlockSize;
289 int seg_id = ((blk_id + 1) *
n_intra_ranks_ + n_numa_blk - 1) / n_numa_blk - 1;
292 std::size_t blk_id_e = ((seg_id + 1) * n_numa_blk) /
n_intra_ranks_;
298 blk_id_b * BlockSize,
299 blk_id_e * BlockSize};
307 std::tuple<std::size_t, std::size_t> get_seg_range(
int seg_id)
const {
310 return {blk_id_b, blk_id_e};
Definition: mem_mapper.hpp:35
int n_intra_ranks_
Definition: mem_mapper.hpp:60
virtual numa_segment get_numa_segment(int inter_rank, std::size_t pm_offset) const =0
virtual bool should_map_all_home() const =0
base(std::size_t size, int n_inter_ranks, int n_intra_ranks)
Definition: mem_mapper.hpp:37
virtual std::size_t local_size(int inter_rank) const =0
virtual std::size_t effective_size() const =0
std::size_t size_
Definition: mem_mapper.hpp:58
int n_inter_ranks_
Definition: mem_mapper.hpp:59
virtual segment get_segment(std::size_t offset) const =0
virtual std::size_t block_size() const =0
Definition: mem_mapper.hpp:249
std::size_t local_size(int inter_rank) const override
Definition: mem_mapper.hpp:257
std::size_t block_size() const override
Definition: mem_mapper.hpp:255
segment get_segment(std::size_t offset) const override
Definition: mem_mapper.hpp:267
std::size_t effective_size() const override
Definition: mem_mapper.hpp:263
block_adws(std::size_t size, int n_inter_ranks, int n_intra_ranks)
Definition: mem_mapper.hpp:251
bool should_map_all_home() const override
Definition: mem_mapper.hpp:302
numa_segment get_numa_segment(int inter_rank, std::size_t pm_offset) const override
Definition: mem_mapper.hpp:283
Definition: mem_mapper.hpp:64
std::size_t block_size() const override
Definition: mem_mapper.hpp:70
std::size_t effective_size() const override
Definition: mem_mapper.hpp:78
segment get_segment(std::size_t offset) const override
Definition: mem_mapper.hpp:82
block(std::size_t size, int n_inter_ranks, int n_intra_ranks)
Definition: mem_mapper.hpp:66
numa_segment get_numa_segment(int inter_rank, std::size_t pm_offset) const override
Definition: mem_mapper.hpp:98
bool should_map_all_home() const override
Definition: mem_mapper.hpp:117
std::size_t local_size(int inter_rank) const override
Definition: mem_mapper.hpp:72
Definition: mem_mapper.hpp:165
bool should_map_all_home() const override
Definition: mem_mapper.hpp:199
std::size_t local_size(int) const override
Definition: mem_mapper.hpp:176
segment get_segment(std::size_t offset) const override
Definition: mem_mapper.hpp:184
numa_segment get_numa_segment(int inter_rank, std::size_t) const override
Definition: mem_mapper.hpp:194
cyclic(std::size_t size, int n_inter_ranks, int n_intra_ranks, std::size_t seg_size=BlockSize)
Definition: mem_mapper.hpp:167
std::size_t effective_size() const override
Definition: mem_mapper.hpp:180
std::size_t block_size() const override
Definition: mem_mapper.hpp:174
#define ITYR_CHECK(cond)
Definition: util.hpp:48
rank_t inter_rank(rank_t global_rank)
Definition: topology.hpp:219
Definition: mem_mapper.hpp:6
uint32_t block_size_t
Definition: util.hpp:30
monoid< T, max_functor<>, lowest< T > > max
Definition: reducer.hpp:104
constexpr auto size(const checkout_span< T, Mode > &cs) noexcept
Definition: checkout_span.hpp:178
Definition: mem_mapper.hpp:22
bool operator!=(const numa_segment &b) const
Definition: mem_mapper.hpp:30
std::size_t pm_offset_e
Definition: mem_mapper.hpp:25
std::size_t pm_offset_b
Definition: mem_mapper.hpp:24
int owner
Definition: mem_mapper.hpp:23
bool operator==(const numa_segment &b) const
Definition: mem_mapper.hpp:27
Definition: mem_mapper.hpp:8
int owner
Definition: mem_mapper.hpp:9
bool operator==(const segment &b) const
Definition: mem_mapper.hpp:14
bool operator!=(const segment &b) const
Definition: mem_mapper.hpp:17
std::size_t pm_offset
Definition: mem_mapper.hpp:12
std::size_t offset_e
Definition: mem_mapper.hpp:11
std::size_t offset_b
Definition: mem_mapper.hpp:10