1 #ifndef DASH__HALO_HALOCOORDINATEACCESS_H 2 #define DASH__HALO_HALOCOORDINATEACCESS_H 4 #include <dash/halo/Halo.h> 10 using namespace internal;
13 template<
typename HaloBlockT>
16 template<
typename CoordinateAccessT>
19 template<
typename CoordinateInnerAccessT, dim_t CurrentDimension>
27 using Offsets_t =
typename CoordinateInnerAccessT::Offsets_t;
28 using Element_t =
typename CoordinateInnerAccessT::Element_t;
29 using index_t =
typename CoordinateInnerAccessT::index_t;
34 : _offsets(offsets), _mem(mem) {
37 template<dim_t _CurrentDimension = CurrentDimension + 1>
38 std::enable_if_t<(_CurrentDimension != NumDimensions), DataInnerAccess<CoordinateInnerAccessT, CurrentDimension+1>>
39 operator[](index_t pos) {
44 template<dim_t _CurrentDimension = CurrentDimension + 1>
45 std::enable_if_t<(_CurrentDimension == NumDimensions), Element_t>&
46 operator[](index_t pos) {
51 const Offsets_t* _offsets;
55 template<
typename CoordinateAccessT>
61 static constexpr
auto MemoryArrange = CoordinateAccessT::memory_order();
64 using Element_t =
typename CoordinateAccessT::Element_t;
65 using index_t =
typename CoordinateAccessT::index_t;
66 using ViewSpec_t =
typename CoordinateAccessT::ViewSpec_t;
67 using Offsets_t =
typename CoordinateAccessT::Offsets_t;
69 using ViewRange_t =
typename CoordinateAccessT::ViewRange_t;
70 using AllViewRanges_t =
typename CoordinateAccessT::AllViewRanges_t;
78 , _data_access(DataInnerAccess_t(_offsets, _mem)) {
81 static constexpr decltype(
auto)
ndim() {
return NumDimensions; }
83 static constexpr decltype(
auto) memory_order() {
return MemoryArrange; }
85 ViewRange_t range_dim(
dim_t dim) {
89 AllViewRanges_t ranges() {
93 decltype(
auto) operator[] (index_t pos) {
94 return _data_access[pos];
97 decltype(
auto) operator[] (index_t pos)
const {
98 return _data_access[pos];
102 AllViewRanges_t _ranges;
104 const Offsets_t* _offsets;
105 DataInnerAccess_t _data_access;
109 template<
typename CoordinateAccessT, dim_t CurrentDimension>
115 static constexpr
auto MemoryArrange = CoordinateAccessT::memory_order();
118 static constexpr
auto RegIndexCenter = RegCoords_t::center_index();
121 using Element_t =
typename CoordinateAccessT::Element_t;
122 using index_t =
typename CoordinateAccessT::index_t;
123 using Coords_t =
typename CoordinateAccessT::Coords_t;
127 DataAccess(
const CoordinateAccessT* access, Element_t* mem,
const Coords_t& coords, region_index_t reg_index,
bool halo)
128 : _access(access), _mem(mem), _coords(coords), _reg_index(reg_index), _halo(halo) {
131 template<dim_t _CurrentDimension = CurrentDimension + 1>
132 std::enable_if_t<(_CurrentDimension != NumDimensions), DataAccess<CoordinateAccessT, CurrentDimension+1>>
133 operator[](index_t pos) {
134 _coords[CurrentDimension] = pos;
135 _reg_index *= REGION_INDEX_BASE;
136 if(_halo || pos < 0 || pos >= static_cast<index_t>(_access->_view_local->extent(CurrentDimension))) {
141 if(pos >= static_cast<index_t>(_access->_view_local->extent(CurrentDimension))) {
151 template<dim_t _CurrentDimension = CurrentDimension + 1>
152 std::enable_if_t<(_CurrentDimension == NumDimensions), Element_t>&
153 operator[](index_t pos) {
154 if(_halo || pos < 0 || pos >= static_cast<index_t>(_access->_view_local->extent(CurrentDimension))) {
155 _reg_index *= REGION_INDEX_BASE;
161 if(pos >= static_cast<index_t>(_access->_view_local->extent(CurrentDimension))) {
165 _coords[CurrentDimension] = pos;
166 auto halo_memory = _access->_halo_memory;
167 halo_memory->to_halo_mem_coords(_reg_index, _coords);
169 return *(halo_memory->first_element_at(_reg_index)
170 + halo_memory->offset(_reg_index, _coords));
177 const CoordinateAccessT* _access;
180 region_index_t _reg_index;
184 template<
typename CoordinateAccessT>
190 static constexpr
auto MemoryArrange = CoordinateAccessT::memory_order();
193 using Element_t =
typename CoordinateAccessT::Element_t;
194 using index_t =
typename CoordinateAccessT::index_t;
195 using ViewSpec_t =
typename CoordinateAccessT::ViewSpec_t;
196 using Offsets_t =
typename CoordinateAccessT::Offsets_t;
198 using ViewRange_t =
typename CoordinateAccessT::ViewRange_t;
199 using AllViewRanges_t =
typename CoordinateAccessT::AllViewRanges_t;
200 using AllBndViewRanges = std::vector<AllViewRanges_t>;
202 using HaloBlock_t =
typename CoordinateAccessT::HaloBlock_t;
203 using HaloMemory_t =
typename CoordinateAccessT::HaloMemory_t;
204 using Coords_t =
typename CoordinateAccessT::Coords_t;
209 , _data_access(_access->_data_access)
210 , _ranges(set_ranges(_access->_halo_block)) {
213 static constexpr decltype(
auto)
ndim() {
return NumDimensions; }
215 static constexpr decltype(
auto) memory_order() {
return MemoryArrange; }
217 AllBndViewRanges ranges() {
221 decltype(
auto) operator[] (index_t pos) {
222 return _data_access[pos];
225 decltype(
auto) operator[] (index_t pos)
const {
226 return _data_access[pos];
231 AllBndViewRanges set_ranges(
const HaloBlock_t* halo_block)
const {
232 AllBndViewRanges all_ranges;
233 const auto& bnd_views = halo_block->boundary_views();
234 all_ranges.reserve(bnd_views.size());
236 for(
const auto& view : bnd_views) {
237 AllViewRanges_t ranges;
238 for(
dim_t d = 0; d < NumDimensions; ++d) {
239 ranges[d] = {
static_cast<index_t
>(view.offset(d)),
240 static_cast<index_t>(view.offset(d) + view.extent(d))};
242 all_ranges.push_back(ranges);
250 const CoordinateAccessT* _access;
252 AllBndViewRanges _ranges;
255 template<
typename HaloBlockT>
259 using Pattern_t =
typename HaloBlockT::Pattern_t;
264 template <
typename _CA>
267 template <
typename _CA>
270 template <
typename _CA, dim_t CurrentDim>
273 template <
typename _CA, dim_t CurrentDim>
277 using Element_t =
typename HaloBlockT::Element_t;
278 using HaloBlock_t = HaloBlockT;
280 using index_t =
typename std::make_signed<typename Pattern_t::index_type>::type;
281 using uindex_t =
typename std::make_unsigned<index_t>::type;
282 using ViewSpec_t =
typename HaloBlockT::ViewSpec_t;
283 using Offsets_t = std::array<index_t, NumDimensions>;
285 using Coords_t =
typename HaloMemory_t::ElementCoords_t;
287 using AllViewRanges_t = std::array<ViewRange_t, NumDimensions>;
294 Element_t* local_memory,
295 HaloMemory_t* halomemory)
296 : _halo_block(haloblock)
297 , _local_memory(local_memory)
298 , _halo_memory(halomemory)
299 , _view_local(&(haloblock->view_local()))
300 , _offsets(set_offsets())
301 , _data_access(
DataAccess_t(
this, _local_memory, Coords_t(), 0,
false))
302 , _ranges(set_ranges(_halo_block->view_inner_with_boundaries()))
303 , _ranges_local(set_ranges(_halo_block->view_local()))
304 , _ranges_halo(set_ranges_halo(_halo_block->view_inner_with_boundaries()))
305 , inner(set_ranges(_halo_block->view_inner()), _local_memory, &_offsets)
309 static constexpr decltype(
auto)
ndim() {
return NumDimensions; }
311 static constexpr decltype(
auto) memory_order() {
return MemoryArrange; }
313 ViewRange_t range_dim(
dim_t dim) {
317 AllViewRanges_t ranges() {
321 ViewRange_t range_local_dim(
dim_t dim) {
322 return _ranges_local(dim);
325 AllViewRanges_t ranges_local() {
326 return _ranges_local;
329 ViewRange_t range_halo_dim(
dim_t dim) {
330 return _ranges_halo(dim);
333 AllViewRanges_t ranges_halo() {
337 decltype(
auto) operator[] (index_t pos) {
338 return _data_access[pos];
341 decltype(
auto) operator[] (index_t pos)
const {
342 return _data_access[pos];
346 Offsets_t set_offsets() {
348 if(MemoryArrange == ROW_MAJOR) {
349 offsets[NumDimensions - 1] = 1;
350 for(
dim_t d = NumDimensions - 1; d > 0;) {
353 for(
dim_t d_tmp = d + 1; d_tmp < NumDimensions; ++d_tmp) {
354 offsets[d] *= _view_local->extent(d_tmp);
359 for(
dim_t d = 1; d < NumDimensions; ++d) {
361 for(
dim_t d_tmp = 0; d_tmp < d; ++d_tmp) {
362 offsets[d] *= _view_local->extent(d_tmp);
370 AllViewRanges_t set_ranges(ViewSpec_t view)
const {
371 AllViewRanges_t ranges;
372 for(
dim_t d = 0; d < NumDimensions; ++d) {
373 ranges[d] = {
static_cast<index_t
>(view.offset(d)),
374 static_cast<index_t>(view.offset(d) + view.extent(d))};
380 AllViewRanges_t set_ranges_halo(ViewSpec_t view)
const {
381 AllViewRanges_t ranges;
382 for(
dim_t d = 0; d < NumDimensions; ++d) {
383 const auto& ext_max = _halo_block->halo_spec().halo_extension_max(d);
384 ranges[d] = {
static_cast<index_t
>(view.offset(d)) - ext_max.first,
385 static_cast<index_t>(view.offset(d) + view.extent(d)) + ext_max.second};
393 const HaloBlock_t* _halo_block;
394 Element_t* _local_memory;
395 HaloMemory_t* _halo_memory;
396 const ViewSpec_t* _view_local;
399 AllViewRanges_t _ranges;
400 AllViewRanges_t _ranges_local;
401 AllViewRanges_t _ranges_halo;
404 CoordInnerAcc_t inner;
405 CoordHaloAcc_t boundary;
412 #endif // DASH__HALO_HALOCOORDINATEACCESS_H Defines how a list of global indices is mapped to single units within a Team.
This class is a simple memory pool which holds allocates elements of size ValueType.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
N-Dimensional region coordinates and associated indices for all possible Halo/Boundary regions of a H...
static constexpr dim_t ndim() noexcept
Number of dimensions of the cartesian space partitioned by the pattern.
constexpr dim_t ndim(const DimensionalType &d)
static constexpr MemArrange memory_order() noexcept
Memory order followed by the pattern.