StencilStream v3.0.0
SYCL-based Stencil Simulation Framework Targeting FPGAs
Loading...
Searching...
No Matches
Stencil.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2020-2024 Jan-Oliver Opdenhövel, Paderborn Center for Parallel Computing, Paderborn
3 * University
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6 * associated documentation files (the “Software”), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
8 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all copies or
12 * substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
20#pragma once
21#include "GenericID.hpp"
22#include "Helpers.hpp"
23#include "Index.hpp"
24#include <bit>
25#include <sycl/ext/intel/ac_types/ac_int.hpp>
26#include <variant>
27
28namespace stencil {
29
46template <typename Cell, uindex_t stencil_radius, typename TimeDependentValue = std::monostate>
47 requires std::semiregular<Cell> && (stencil_radius >= 1)
48class Stencil {
49 public:
51 static constexpr uindex_t diameter = 2 * stencil_radius + 1;
52
54 static constexpr unsigned long bits_stencil = std::bit_width(diameter);
55
57 using index_stencil_t = ac_int<bits_stencil, true>;
58
60 using uindex_stencil_t = ac_int<bits_stencil, false>;
61
64
67
77 Stencil(ID id, UID grid_range, uindex_t iteration, uindex_t subiteration,
78 TimeDependentValue tdv)
79 : id(id), iteration(iteration), subiteration(subiteration), grid_range(grid_range),
80 time_dependent_value(tdv), internal() {}
81
92 Stencil(ID id, UID grid_range, uindex_t iteration, uindex_t subiteration,
93 TimeDependentValue tdv, Cell raw[diameter][diameter])
94 : id(id), iteration(iteration), subiteration(subiteration), grid_range(grid_range),
95 time_dependent_value(tdv), internal() {
96#pragma unroll
97 for (uindex_t c = 0; c < diameter; c++) {
98#pragma unroll
99 for (uindex_t r = 0; r < diameter; r++) {
100 internal[c][r] = raw[c][r];
101 }
102 }
103 }
104
110 Cell const &operator[](ID id) const {
111 return internal[id.c + stencil_radius][id.r + stencil_radius];
112 }
113
119 Cell &operator[](ID id) { return internal[id.c + stencil_radius][id.r + stencil_radius]; }
120
126 Cell const &operator[](StencilID id) const {
127 return internal[id.c + index_stencil_t(stencil_radius)]
128 [id.r + index_stencil_t(stencil_radius)];
129 }
130
137 return internal[id.c + index_stencil_t(stencil_radius)]
138 [id.r + index_stencil_t(stencil_radius)];
139 }
140
147 Cell const &operator[](UID id) const { return internal[id.c][id.r]; }
148
155 Cell &operator[](UID id) { return internal[id.c][id.r]; }
156
163 Cell const &operator[](StencilUID id) const { return internal[id.c][id.r]; }
164
171 Cell &operator[](StencilUID id) { return internal[id.c][id.r]; }
172
174 const ID id;
175
178
181
184
186 const TimeDependentValue time_dependent_value;
187
188 private:
189 Cell internal[diameter][diameter];
190};
191} // namespace stencil
A generic, two-dimensional index.
Definition GenericID.hpp:32
The stencil buffer.
Definition Stencil.hpp:48
const UID grid_range
The range of the underlying grid.
Definition Stencil.hpp:183
Cell const & operator[](ID id) const
Access a cell in the stencil.
Definition Stencil.hpp:110
Stencil(ID id, UID grid_range, uindex_t iteration, uindex_t subiteration, TimeDependentValue tdv, Cell raw[diameter][diameter])
Create a new stencil with the given contents.
Definition Stencil.hpp:92
Cell & operator[](ID id)
Access a cell in the stencil.
Definition Stencil.hpp:119
Cell & operator[](StencilUID id)
Access a cell in the stencil.
Definition Stencil.hpp:171
ac_int< bits_stencil, false > uindex_stencil_t
An unsigned index type for column and row indices in this stencil.
Definition Stencil.hpp:60
const ID id
The position of the central cell in the global grid.
Definition Stencil.hpp:174
Cell & operator[](UID id)
Access a cell in the stencil.
Definition Stencil.hpp:155
ac_int< bits_stencil, true > index_stencil_t
A signed index type for column and row indices in this stencil.
Definition Stencil.hpp:57
const uindex_t iteration
The present iteration index of the cells in the stencil.
Definition Stencil.hpp:177
Cell const & operator[](UID id) const
Access a cell in the stencil.
Definition Stencil.hpp:147
Stencil(ID id, UID grid_range, uindex_t iteration, uindex_t subiteration, TimeDependentValue tdv)
Create a new stencil with an uninitialized buffer.
Definition Stencil.hpp:77
Cell const & operator[](StencilID id) const
Access a cell in the stencil.
Definition Stencil.hpp:126
const uindex_t subiteration
The present sub-iteration index of the cells in the stencil.
Definition Stencil.hpp:180
const TimeDependentValue time_dependent_value
The time-dependent value for this iteration.
Definition Stencil.hpp:186
Cell const & operator[](StencilUID id) const
Access a cell in the stencil.
Definition Stencil.hpp:163
Cell & operator[](StencilID id)
Access a cell in the stencil.
Definition Stencil.hpp:136
Definition AccessorSubscript.hpp:24
BOOST_PP_CAT(BOOST_PP_CAT(uint, STENCIL_INDEX_WIDTH), _t) uindex_t
An unsigned integer of configurable width.
Definition Index.hpp:42