StencilStream v3.0.0
SYCL-based Stencil Simulation Framework Targeting FPGAs
Loading...
Searching...
No Matches
SinglePassStrategies.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 "../Concepts.hpp"
22
23namespace stencil {
24namespace tdv {
25
31namespace single_pass {
32
47template <typename T, typename TransFunc>
48concept LocalState =
49 stencil::concepts::TransitionFunction<TransFunc> && requires(T const &local_state, uindex_t i) {
50 {
51 local_state.get_time_dependent_value(i)
52 } -> std::same_as<typename TransFunc::TimeDependentValue>;
53 };
54
64template <typename T, typename TransFunc>
67 std::constructible_from<typename T::LocalState, T const &>;
68
84template <typename T, typename TransFunc>
85concept GlobalState =
87 std::constructible_from<T, TransFunc, uindex_t, uindex_t> &&
89 std::constructible_from<typename T::KernelArgument, T &, sycl::handler &, uindex_t, uindex_t>;
90
98template <typename T, typename TransFunc, uindex_t max_n_iterations>
99concept Strategy =
102
115 template <stencil::concepts::TransitionFunction TransFunc, uindex_t max_n_iterations>
116 struct GlobalState {
117 using TDV = typename TransFunc::TimeDependentValue;
118
119 GlobalState(TransFunc trans_func, uindex_t iteration_offset, uindex_t n_iterations)
120 : trans_func(trans_func) {}
121
123 KernelArgument(GlobalState &global_state, sycl::handler &cgh, uindex_t iteration_offset,
124 uindex_t n_iterations)
125 : trans_func(global_state.trans_func), iteration_offset(iteration_offset) {}
126
128
130 return trans_func.get_time_dependent_value(iteration_offset + i_iteration);
131 }
132
133 private:
134 TransFunc trans_func;
135 uindex_t iteration_offset;
136 };
137
138 private:
139 TransFunc trans_func;
140 };
141};
142
153 template <stencil::concepts::TransitionFunction TransFunc, uindex_t max_n_iterations>
154 struct GlobalState {
155 using TDV = typename TransFunc::TimeDependentValue;
156
157 GlobalState(TransFunc trans_func, uindex_t iteration_offset, uindex_t n_iterations)
158 : trans_func(trans_func) {}
159
161 KernelArgument(GlobalState &global_state, sycl::handler &cgh, uindex_t iteration_offset,
162 uindex_t n_iterations)
163 : trans_func(global_state.trans_func), iteration_offset(iteration_offset) {}
164
165 struct LocalState {
166 LocalState(KernelArgument const &kernel_argument) : values() {
167 for (uindex_t i = 0; i < max_n_iterations; i++) {
168 values[i] = kernel_argument.trans_func.get_time_dependent_value(
169 kernel_argument.iteration_offset + i);
170 }
171 }
172
174 return values[i_iteration];
175 }
176
177 private:
178 TDV values[max_n_iterations];
179 };
180
181 private:
182 TransFunc trans_func;
183 uindex_t iteration_offset;
184 };
185
186 private:
187 TransFunc trans_func;
188 };
189};
190
201 template <stencil::concepts::TransitionFunction TransFunc, uindex_t max_n_iterations>
203 public:
204 using TDV = typename TransFunc::TimeDependentValue;
205
206 GlobalState(TransFunc function, uindex_t iteration_offset, uindex_t n_iterations)
207 : function(function), iteration_offset(iteration_offset),
208 value_buffer(sycl::range<1>(n_iterations)) {
209 sycl::host_accessor ac(value_buffer, sycl::read_write);
210 for (uindex_t i = 0; i < n_iterations; i++) {
211 ac[i] = function.get_time_dependent_value(iteration_offset + i);
212 }
213 }
214
216 : function(other.function), iteration_offset(other.iteration_offset),
217 value_buffer(other.value_buffer) {}
218
220 KernelArgument(GlobalState &global_state, sycl::handler &cgh, uindex_t i_iteration,
221 uindex_t n_iterations)
222 : ac() {
223 assert(n_iterations <= max_n_iterations);
224 assert(i_iteration >= global_state.iteration_offset);
225 assert(i_iteration + n_iterations <=
226 global_state.iteration_offset + global_state.value_buffer.get_range()[0]);
227
228 sycl::range<1> access_range(n_iterations);
229 sycl::id<1> access_offset(i_iteration - global_state.iteration_offset);
230 ac = sycl::accessor<TDV, 1, sycl::access::mode::read>(
231 global_state.value_buffer, cgh, access_range, access_offset);
232 }
233
234 struct LocalState {
235 LocalState(KernelArgument const &kernel_argument) : values() {
236 uindex_t n_values =
237 std::min(max_n_iterations, uindex_t(kernel_argument.ac.get_range()[0]));
238
239 for (uindex_t i = 0; i < n_values; i++)
240 values[i] = kernel_argument.ac[i];
241 }
242
243 TDV get_time_dependent_value(uindex_t i) const { return values[i]; }
244
245 private:
246 TDV values[max_n_iterations];
247 };
248
249 private:
250 sycl::accessor<TDV, 1, sycl::access::mode::read> ac;
251 };
252
253 private:
254 TransFunc function;
255 uindex_t iteration_offset;
256 sycl::buffer<TDV, 1> value_buffer;
257 };
258};
259
260} // namespace single_pass
261} // namespace tdv
262} // namespace stencil
GlobalState(TransFunc function, uindex_t iteration_offset, uindex_t n_iterations)
Definition SinglePassStrategies.hpp:206
typename TransFunc::TimeDependentValue TDV
Definition SinglePassStrategies.hpp:204
GlobalState(GlobalState const &other)
Definition SinglePassStrategies.hpp:215
A technical definition of a stencil transition function.
Definition Concepts.hpp:62
The requirements for a TDV system's global state.
Definition SinglePassStrategies.hpp:85
The requirements for a TDV kernel argument.
Definition SinglePassStrategies.hpp:65
The requirements for a pass-local TDV system state.
Definition SinglePassStrategies.hpp:48
Requirements for a TDV implementation strategy.
Definition SinglePassStrategies.hpp:99
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
KernelArgument(GlobalState &global_state, sycl::handler &cgh, uindex_t iteration_offset, uindex_t n_iterations)
Definition SinglePassStrategies.hpp:123
TDV get_time_dependent_value(uindex_t i_iteration) const
Definition SinglePassStrategies.hpp:129
typename TransFunc::TimeDependentValue TDV
Definition SinglePassStrategies.hpp:117
GlobalState(TransFunc trans_func, uindex_t iteration_offset, uindex_t n_iterations)
Definition SinglePassStrategies.hpp:119
A TDV implementation strategy that inlines the TDV function into the transition function.
Definition SinglePassStrategies.hpp:114
LocalState(KernelArgument const &kernel_argument)
Definition SinglePassStrategies.hpp:166
TDV get_time_dependent_value(uindex_t i_iteration) const
Definition SinglePassStrategies.hpp:173
KernelArgument(GlobalState &global_state, sycl::handler &cgh, uindex_t iteration_offset, uindex_t n_iterations)
Definition SinglePassStrategies.hpp:161
GlobalState(TransFunc trans_func, uindex_t iteration_offset, uindex_t n_iterations)
Definition SinglePassStrategies.hpp:157
typename TransFunc::TimeDependentValue TDV
Definition SinglePassStrategies.hpp:155
A TDV implementation strategy that precomputes TDVs on the device.
Definition SinglePassStrategies.hpp:152
LocalState(KernelArgument const &kernel_argument)
Definition SinglePassStrategies.hpp:235
TDV get_time_dependent_value(uindex_t i) const
Definition SinglePassStrategies.hpp:243
KernelArgument(GlobalState &global_state, sycl::handler &cgh, uindex_t i_iteration, uindex_t n_iterations)
Definition SinglePassStrategies.hpp:220
A TDV implementation strategy that precomputes TDVs on the host.
Definition SinglePassStrategies.hpp:200