StencilStream v3.0.0
SYCL-based Stencil Simulation Framework Targeting FPGAs
Loading...
Searching...
No Matches
AccessorSubscript.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 "Index.hpp"
22#include <CL/sycl.hpp>
23
24namespace stencil {
47template <typename Cell, typename Accessor, sycl::access::mode access_mode,
48 uindex_t current_subdim = 0>
50 public:
52 static constexpr uindex_t dimensions = Accessor::dimensions;
53
64 AccessorSubscript(Accessor &ac, uindex_t i)
65 requires(current_subdim == 0)
66 : ac(ac), id_prefix() {
67 id_prefix[current_subdim] = i;
68 }
69
80 AccessorSubscript(Accessor &ac, sycl::id<dimensions> id_prefix, uindex_t i)
81 : ac(ac), id_prefix(id_prefix) {
82 id_prefix[current_subdim] = i;
83 }
84
97 requires(current_subdim < dimensions - 2)
98 {
99 return AccessorSubscript(ac, id_prefix, i);
100 }
101
113 Cell const &operator[](uindex_t i)
114 requires(current_subdim == dimensions - 2 && access_mode == sycl::access::mode::read)
115 {
116 sycl::id<dimensions> id = id_prefix;
117 id[current_subdim + 1] = i;
118 return ac[id];
119 }
120
132 requires(current_subdim == dimensions - 2 && access_mode != sycl::access::mode::read)
133 {
134 sycl::id<dimensions> id = id_prefix;
135 id[current_subdim + 1] = i;
136 return ac[id];
137 }
138
139 private:
140 Accessor &ac;
141 sycl::id<dimensions> id_prefix;
142};
143} // namespace stencil
A helper class to support the double-subscript idiom for GridAccessors.
Definition AccessorSubscript.hpp:49
Cell & operator[](uindex_t i)
Access the cell.
Definition AccessorSubscript.hpp:131
AccessorSubscript< Cell, Accessor, access_mode, current_subdim+1 > operator[](uindex_t i)
Access the next dimension's accessor subscript.
Definition AccessorSubscript.hpp:96
AccessorSubscript(Accessor &ac, uindex_t i)
Instantiate a new accessor subscript object with the given index as the prefix.
Definition AccessorSubscript.hpp:64
Cell const & operator[](uindex_t i)
Access the cell.
Definition AccessorSubscript.hpp:113
AccessorSubscript(Accessor &ac, sycl::id< dimensions > id_prefix, uindex_t i)
Instantiate a new subscript object with the given prefix and subscript index.
Definition AccessorSubscript.hpp:80
static constexpr uindex_t dimensions
The number of dimensions in the accessed grid.
Definition AccessorSubscript.hpp:52
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