-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_iterator.hpp
43 lines (35 loc) · 1.4 KB
/
tile_iterator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* tile_iterator.hpp
*
* Created on: Nov 5, 2016
* Author: pfandedd
*/
#pragma once
#include <vector>
#include "tile_array.hpp"
#include "tile_view.hpp"
namespace memory_layout {
namespace detail {
template<size_t dim, size_t cur_dim, typename T, typename F>
typename std::enable_if<cur_dim == dim, void>::type iterate_tile_dim(std::vector<T> &tiled,
const std::vector<tiling_info_dim> &tiling_info, size_t (&tile_index)[dim], F f) {
memory_layout::tile_view<2, lattice::CELL_TYPES> v(tiled, tile_index, tiling_info);
f(std::move(v));
}
template<size_t dim, size_t cur_dim, typename T, typename F>
typename std::enable_if<cur_dim != dim, void>::type iterate_tile_dim(std::vector<T> &tiled,
const std::vector<tiling_info_dim> &tiling_info, size_t (&partial_tile_index)[dim], F f) {
const tiling_info_dim &cur_info = tiling_info[cur_dim];
size_t tiles_dim = cur_info.stride / cur_info.tile_size_dir;
for (size_t tile_index_1d = 0; tile_index_1d < tiles_dim; tile_index_1d += 1) {
partial_tile_index[cur_dim] = tile_index_1d;
iterate_tile_dim<dim, cur_dim + 1>(tiled, tiling_info, partial_tile_index, f);
}
}
}
template<size_t dim, typename T, typename F>
void iterate_tiles(std::vector<T> &tiled, const std::vector<tiling_info_dim> &tiling_info, F f) {
size_t tile_index[dim];
detail::iterate_tile_dim<dim, 0>(tiled, tiling_info, tile_index, f);
}
}