21#include "../Index.hpp"
51template <
typename Cell>
class Grid {
75 Grid(sycl::range<2> range) : buffer(range) {}
85 Grid(sycl::buffer<Cell, 2> other_buffer) : buffer(other_buffer.get_range()) {
98 Grid(
Grid const &other_grid) : buffer(other_grid.buffer) {}
111 if (buffer.get_range() != other_buffer.get_range()) {
112 throw std::range_error(
"The target buffer has not the same size as the grid");
114 sycl::host_accessor buffer_ac(buffer, sycl::write_only);
115 sycl::host_accessor other_ac(other_buffer, sycl::read_only);
116 std::memcpy(buffer_ac.get_pointer(), other_ac.get_pointer(), buffer_ac.byte_size());
129 if (buffer.get_range() != other_buffer.get_range()) {
130 throw std::range_error(
"The target buffer has not the same size as the grid");
132 sycl::host_accessor buffer_ac(buffer, sycl::read_only);
133 sycl::host_accessor other_ac(other_buffer, sycl::write_only);
134 std::memcpy(other_ac.get_pointer(), buffer_ac.get_pointer(), buffer_ac.byte_size());
146 template <sycl::access::mode access_mode = sycl::access::mode::read_write>
147 class GridAccessor :
public sycl::host_accessor<Cell, Grid::dimensions, access_mode> {
153 : sycl::host_accessor<Cell,
Grid::
dimensions, access_mode>(grid.buffer) {}
174 sycl::buffer<Cell, 2> buffer;
An accessor for the grid.
Definition Grid.hpp:147
GridAccessor(Grid &grid)
Create a new accessor to the given grid.
Definition Grid.hpp:152
A grid class for the CPU backend.
Definition Grid.hpp:51
Grid(uindex_t c, uindex_t r)
Create a new, uninitialized grid with the given dimensions.
Definition Grid.hpp:67
void copy_to_buffer(sycl::buffer< Cell, 2 > other_buffer)
Copy the contents of the grid into the SYCL buffer.
Definition Grid.hpp:128
Grid(sycl::range< 2 > range)
Create a new, uninitialized grid with the given dimensions.
Definition Grid.hpp:75
void copy_from_buffer(sycl::buffer< Cell, 2 > other_buffer)
Copy the contents of the SYCL buffer into the grid.
Definition Grid.hpp:110
Grid(Grid const &other_grid)
Create a new reference to the given grid.
Definition Grid.hpp:98
Grid make_similar() const
Create an new, uninitialized grid with the same size as the current one.
Definition Grid.hpp:169
sycl::buffer< Cell, 2 > & get_buffer()
Definition Grid.hpp:171
uindex_t get_grid_height() const
Return the height, or number of rows, of the grid.
Definition Grid.hpp:164
uindex_t get_grid_width() const
Return the width, or number of columns, of the grid.
Definition Grid.hpp:159
static constexpr uindex_t dimensions
The number of dimensions of the grid.
Definition Grid.hpp:58
Grid(sycl::buffer< Cell, 2 > other_buffer)
Create a new grid with the same size and contents as the given SYCL buffer.
Definition Grid.hpp:85
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