21#include "../AccessorSubscript.hpp"
22#include "../Concepts.hpp"
23#include "../GenericID.hpp"
72template <
typename Cell,
uindex_t tile_width = 1024,
uindex_t tile_height = 1024,
75 static_assert(2 * halo_radius < tile_height && 2 * halo_radius < tile_width);
93 : grid_buffer(sycl::range<2>(grid_width, grid_height)) {}
101 Grid(sycl::range<2> range) : grid_buffer(range) {}
111 Grid(sycl::buffer<Cell, 2> input_buffer) : grid_buffer(input_buffer.get_range()) {
124 Grid(
Grid const &other_grid) : grid_buffer(other_grid.grid_buffer) {}
168 requires(access_mode == sycl::access::mode::read)
180 requires(access_mode != sycl::access::mode::read)
186 sycl::host_accessor<Cell, 2, access_mode> accessor;
200 if (input_buffer.get_range() != grid_buffer.get_range()) {
201 throw std::out_of_range(
"The target buffer has not the same size as the grid");
204 sycl::host_accessor grid_ac{grid_buffer, sycl::write_only};
205 sycl::host_accessor input_ac{input_buffer, sycl::read_only};
208 grid_ac[c][r] = input_ac[c][r];
223 if (output_buffer.get_range() != grid_buffer.get_range()) {
224 throw std::out_of_range(
"The target buffer has not the same size as the grid");
227 sycl::host_accessor grid_ac{grid_buffer, sycl::read_only};
228 sycl::host_accessor output_ac{output_buffer, sycl::write_only};
231 output_ac[c][r] = grid_ac[c][r];
294 template <
typename in_pipe>
297 throw std::out_of_range(
"Tile index out of range!");
300 constexpr uindex_t column_bits = 1 + std::bit_width(tile_width + halo_radius);
301 constexpr uindex_t row_bits = 1 + std::bit_width(tile_height + halo_radius);
302 using index_c_t = ac_int<column_bits, true>;
303 using index_r_t = ac_int<row_bits, true>;
305 return queue.submit([&](sycl::handler &cgh) {
306 sycl::accessor grid_ac{grid_buffer, cgh, sycl::read_only};
310 cgh.single_task([=]() {
311 index_t c_offset = tile_c * tile_width;
312 index_c_t start_tile_c = -halo_radius;
313 index_c_t end_tile_c =
314 index_c_t(std::min(grid_width - tile_c * tile_width, tile_width)) + halo_radius;
316 index_t r_offset = tile_r * tile_height;
317 index_r_t start_tile_r = -halo_radius;
318 index_r_t end_tile_r =
319 index_r_t(std::min(grid_height - tile_r * tile_height, tile_height)) +
322 [[intel::loop_coalesce(2)]]
for (index_c_t tile_c = start_tile_c;
323 tile_c < end_tile_c; tile_c++) {
324 for (index_r_t tile_r = start_tile_r; tile_r < end_tile_r; tile_r++) {
325 index_t c = c_offset + tile_c.to_long();
326 index_t r = r_offset + tile_r.to_long();
329 if (c >= 0 && r >= 0 && c < grid_width && r < grid_height) {
330 value = grid_ac[c][r];
334 in_pipe::write(
value);
369 template <
typename out_pipe>
372 throw std::out_of_range(
"Tile index out of range!");
375 constexpr uindex_t column_bits = std::bit_width(tile_width);
376 constexpr uindex_t row_bits = std::bit_width(tile_height);
377 using uindex_c_t = ac_int<column_bits, false>;
378 using uindex_r_t = ac_int<row_bits, false>;
380 return queue.submit([&](sycl::handler &cgh) {
381 sycl::accessor grid_ac{grid_buffer, cgh, sycl::read_write};
385 cgh.single_task([=]() {
386 uindex_t c_offset = tile_c * tile_width;
387 uindex_c_t end_tile_c =
388 uindex_c_t(std::min(grid_width - tile_c * tile_width, tile_width));
390 uindex_t r_offset = tile_r * tile_height;
391 uindex_r_t end_tile_r =
392 uindex_r_t(std::min(grid_height - tile_r * tile_height, tile_height));
394 [[intel::loop_coalesce(2)]]
for (uindex_c_t tile_c = 0; tile_c < end_tile_c;
396 for (uindex_r_t tile_r = 0; tile_r < end_tile_r; tile_r++) {
397 grid_ac[c_offset + tile_c.to_long()][r_offset + tile_r.to_long()] =
406 sycl::buffer<Cell, 2> grid_buffer;
T value
Definition Helpers.hpp:0
A helper class to support the double-subscript idiom for GridAccessors.
Definition AccessorSubscript.hpp:49
A generic, two-dimensional index.
Definition GenericID.hpp:32
An accessor for the monotile grid.
Definition Grid.hpp:135
BaseSubscript operator[](uindex_t i)
Access/Dereference the first dimension.
Definition Grid.hpp:159
Cell & operator[](sycl::id< 2 > id)
Access a cell of the grid.
Definition Grid.hpp:179
Cell const & operator[](sycl::id< 2 > id)
Access a cell of the grid.
Definition Grid.hpp:167
AccessorSubscript< Cell, GridAccessor, access_mode > BaseSubscript
Shorthand for the used subscript type.
Definition Grid.hpp:150
static constexpr uindex_t dimensions
The number of dimensions of the underlying grid.
Definition Grid.hpp:140
GridAccessor(Grid &grid)
Create a new accessor to the given grid.
Definition Grid.hpp:145
A grid class for the tiling architecture.
Definition Grid.hpp:74
void copy_to_buffer(sycl::buffer< Cell, 2 > output_buffer)
Copy the contents of the grid into the SYCL buffer.
Definition Grid.hpp:222
static constexpr uindex_t dimensions
The number of dimensions of the grid.
Definition Grid.hpp:83
uindex_t get_grid_width() const
Return the width, or number of columns, of the grid.
Definition Grid.hpp:244
void copy_from_buffer(sycl::buffer< Cell, 2 > input_buffer)
Copy the contents of the SYCL buffer into the grid.
Definition Grid.hpp:199
GenericID< uindex_t > get_tile_range() const
Return the range of (central) tiles of the grid.
Definition Grid.hpp:260
sycl::event submit_write(sycl::queue queue, uindex_t tile_c, uindex_t tile_r)
Submit a kernel that receives cells from the pipe and writes them to the grid.
Definition Grid.hpp:370
sycl::event submit_read(sycl::queue &queue, uindex_t tile_c, uindex_t tile_r, Cell halo_value)
Submit a kernel that sends a tile of the grid into a pipe.
Definition Grid.hpp:295
Grid make_similar() const
Create an new, uninitialized grid with the same size as the current one.
Definition Grid.hpp:239
Grid(sycl::buffer< Cell, 2 > input_buffer)
Create a new grid with the same size and contents as the given SYCL buffer.
Definition Grid.hpp:111
Grid(uindex_t grid_width, uindex_t grid_height)
Create a new, uninitialized grid with the given dimensions.
Definition Grid.hpp:92
uindex_t get_grid_height() const
Return the height, or number of rows, of the grid.
Definition Grid.hpp:249
Grid(Grid const &other_grid)
Create a new reference to the given grid.
Definition Grid.hpp:124
Grid(sycl::range< 2 > range)
Create a new, uninitialized grid with the given dimensions.
Definition Grid.hpp:101
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
BOOST_PP_CAT(BOOST_PP_CAT(int, STENCIL_INDEX_WIDTH), _t) index_t
A signed integer of configurable width.
Definition Index.hpp:56