RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
TypedViewBase.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_util_TypedViewBase_HPP
21 #define RAJA_util_TypedViewBase_HPP
22 
23 #include <type_traits>
24 
25 #include "RAJA/config.hpp"
26 
27 #include "RAJA/pattern/atomic.hpp"
28 
29 #if defined(RAJA_ENABLE_VECTORIZATION)
30 #include "RAJA/pattern/tensor.hpp"
31 #endif
32 
33 #include "RAJA/util/Layout.hpp"
36 
37 namespace RAJA
38 {
39 
40 namespace internal
41 {
42 
43 template<camp::idx_t, typename T>
45 {
46  using type = T;
47 };
48 
49 template<typename IdxSeq, typename T>
51 
52 template<camp::idx_t... Perm, typename T>
53 struct SequenceToType<camp::idx_seq<Perm...>, T>
54 {
55  using type = camp::list<typename IndexToType<Perm, T>::type...>;
56 };
57 
58 template<typename Perm>
61 
62 // Helpers to convert
63 // layouts -> OffsetLayouts
64 // Typedlayouts -> TypedOffsetLayouts
65 template<typename layout>
66 struct add_offset
67 {
69 };
70 
71 template<typename IdxLin, typename... DimTypes>
72 struct add_offset<RAJA::TypedLayout<IdxLin, camp::tuple<DimTypes...>>>
73 {
74  using type = RAJA::TypedOffsetLayout<IdxLin, camp::tuple<DimTypes...>>;
75 };
76 
77 
78 #if defined(RAJA_ENABLE_VECTORIZATION)
79 namespace detail
80 {
81 /*
82  * Returns the argument number which contains a VectorIndex
83  *
84  * returns -1 if none of the arguments are VectorIndexs
85  */
86 
87 template<camp::idx_t DIM, typename ARGS, typename IDX_SEQ>
88 struct GetTensorArgIdxExpanded;
89 
90 template<camp::idx_t DIM, typename... ARGS, camp::idx_t... IDX>
91 struct GetTensorArgIdxExpanded<DIM, camp::list<ARGS...>, camp::idx_seq<IDX...>>
92 {
93 
94  static constexpr camp::idx_t value = RAJA::max<camp::idx_t>(
95  (internal::expt::isTensorIndex<ARGS>() &&
96  internal::expt::getTensorDim<ARGS>() == DIM
97  ? IDX
98  : -1)...);
99 };
100 
101 
102 } // namespace detail
103 #endif
104 
105 
106 /*
107  * Returns the number of arguments which are VectorIndexs
108  */
109 template<typename... ARGS>
111 {
112  static constexpr camp::idx_t value =
113 #if defined(RAJA_ENABLE_VECTORIZATION)
114  RAJA::sum<camp::idx_t>(
115  (internal::expt::isTensorIndex<ARGS>() ? 1 : 0)...);
116 #else
117  0; // There should be 0 Tensor indices if not vectorizing.
118 #endif
119 };
120 
121 #if defined(RAJA_ENABLE_VECTORIZATION)
122 /*
123  * Returns which argument has a vector index
124  */
125 template<camp::idx_t DIM, typename... ARGS>
126 struct GetTensorArgIdx
127 {
128  static constexpr camp::idx_t value = detail::GetTensorArgIdxExpanded<
129  DIM,
130  camp::list<ARGS...>,
131  camp::make_idx_seq_t<sizeof...(ARGS)>>::value;
132 };
133 
134 template<camp::idx_t DIM, typename... ARGS>
135 struct GetTensorArgIdx<DIM, camp::list<ARGS...>>
136 {
137  static constexpr camp::idx_t value = detail::GetTensorArgIdxExpanded<
138  DIM,
139  camp::list<ARGS...>,
140  camp::make_idx_seq_t<sizeof...(ARGS)>>::value;
141 };
142 
143 /*
144  * Returns the beginning index in a vector argument
145  */
146 template<camp::idx_t DIM, typename LAYOUT, typename... ARGS>
147 RAJA_INLINE RAJA_HOST_DEVICE static constexpr camp::idx_t get_tensor_args_begin(
148  LAYOUT const& layout,
149  ARGS... args)
150 {
151  return RAJA::max<camp::idx_t>(
152  internal::expt::getTensorDim<ARGS>() == DIM
153  ? internal::expt::getTensorBegin<ARGS>(
154  args, layout.template get_dim_begin<
155  GetTensorArgIdx<DIM, ARGS...>::value>())
156  : 0 ...);
157 }
158 
159 /*
160  * Returns the number of elements in the vector argument
161  */
162 template<camp::idx_t DIM, typename LAYOUT, typename... ARGS>
163 RAJA_INLINE RAJA_HOST_DEVICE static constexpr camp::idx_t get_tensor_args_size(
164  LAYOUT const& layout,
165  ARGS... args)
166 {
167  return RAJA::max<camp::idx_t>(
168  internal::expt::getTensorDim<ARGS>() == DIM
169  ? internal::expt::getTensorSize<ARGS>(
170  args, layout.template get_dim_size<
171  GetTensorArgIdx<DIM, ARGS...>::value>())
172  : 0 ...);
173 }
174 #endif
175 
176 
177 namespace detail
178 {
179 
188 template<typename VecSeq,
189  typename Args,
190  typename ElementType,
191  typename PointerType,
192  typename LinIdx,
193  typename LayoutType>
195 
196 /*
197  * Specialization for Scalar return types
198  */
199 template<typename... Args,
200  typename ElementType,
201  typename PointerType,
202  typename LinIdx,
203  typename LayoutType>
204 struct ViewReturnHelper<camp::idx_seq<>,
205  camp::list<Args...>,
206  ElementType,
207  PointerType,
208  LinIdx,
209  LayoutType>
210 {
211  using return_type = ElementType&;
212 
213  RAJA_INLINE RAJA_HOST_DEVICE static constexpr return_type make_return(
214  LayoutType const& layout,
215  PointerType const& data,
216  Args const&... args)
217  {
218  return data[stripIndexType(layout(args...))];
219  }
220 };
221 
222 
223 #if defined(RAJA_ENABLE_VECTORIZATION)
224 /*
225  * Specialization for Tensor return types
226  */
227 template<camp::idx_t VecHead,
228  camp::idx_t... VecSeq,
229  typename... Args,
230  typename ElementType,
231  typename PointerType,
232  typename LinIdx,
233  typename LayoutType>
234 struct ViewReturnHelper<camp::idx_seq<VecHead, VecSeq...>,
235  camp::list<Args...>,
236  ElementType,
237  PointerType,
238  LinIdx,
239  LayoutType>
240 {
241 
242  static constexpr camp::idx_t s_num_dims = sizeof...(VecSeq) + 1;
243 
244  // This is the stride-one dimensions w.r.t. the tensor not the View
245  // For example:
246  // For a vector, s_stride_one_dim is either 0 (packed) or -1 (strided)
247  // For a matrix, s_stride_one_dim is either:
248  // -1 neither row nor column are packed
249  // 0 rows are stride-one
250  // 1 columns are stride-one
251  static constexpr camp::idx_t s_stride_one_dim = RAJA::max<camp::idx_t>(
252  (GetTensorArgIdx<VecHead, Args...>::value == LayoutType::stride_one_dim
253  ? VecHead
254  : -1),
255  (GetTensorArgIdx<VecSeq, Args...>::value == LayoutType::stride_one_dim
256  ? VecSeq
257  : -1)...);
258 
259 
260  using tensor_reg_type =
261  typename camp::at_v<camp::list<Args...>,
262  GetTensorArgIdx<0, Args...>::value>::tensor_type;
263  using ref_type = internal::expt::TensorRef<ElementType*,
264  LinIdx,
266  s_num_dims,
267  s_stride_one_dim>;
268  using return_type =
270 
271  RAJA_INLINE RAJA_HOST_DEVICE static constexpr return_type make_return(
272  LayoutType const& layout,
273  PointerType const& data,
274  Args const&... args)
275  {
276 
277  return return_type(ref_type {
278  // data pointer
279  &data[0] +
280  layout(internal::expt::isTensorIndex<Args>()
281  ? LinIdx {0}
282  : (LinIdx)stripIndexType(
284  // strides
285  {(LinIdx)layout.template get_dim_stride<
286  GetTensorArgIdx<VecHead, Args...>::value>(),
287  (LinIdx)layout.template get_dim_stride<
288  GetTensorArgIdx<VecSeq, Args...>::value>()...},
289  // tile
290  {// begin
291  {(LinIdx)(get_tensor_args_begin<VecHead>(layout, args...)),
292  (LinIdx)(get_tensor_args_begin<VecSeq>(layout, args...))...},
293 
294  // size
295  {(LinIdx)get_tensor_args_size<VecHead>(layout, args...),
296  (LinIdx)get_tensor_args_size<VecSeq>(layout, args...)...}}});
297  }
298 };
299 
300 /*
301  * Specialization for Tensor return types and static layout types
302  */
303 template<camp::idx_t VecHead,
304  camp::idx_t... VecSeq,
305  typename... INDEX_TYPES,
306  typename ElementType,
307  typename PointerType,
308  typename LinIdx,
309  LinIdx... RangeInts,
310  LinIdx... SizeInts,
311  LinIdx... StrideInts,
312  typename DIM_LIST>
313 struct ViewReturnHelper<
314  camp::idx_seq<VecHead, VecSeq...>,
315  camp::list<RAJA::expt::StaticTensorIndex<INDEX_TYPES>...>,
316  ElementType,
317  PointerType,
318  LinIdx,
320  camp::int_seq<LinIdx, RangeInts...>,
321  camp::int_seq<LinIdx, SizeInts...>,
322  camp::int_seq<LinIdx, StrideInts...>,
323  DIM_LIST>>
324 {
325  static constexpr camp::idx_t s_num_dims = sizeof...(VecSeq) + 1;
326 
327  using index_list = camp::list<RAJA::expt::StaticTensorIndex<INDEX_TYPES>...>;
328 
329  using range_seq = camp::int_seq<LinIdx, RangeInts...>;
330  using size_seq = camp::int_seq<LinIdx, SizeInts...>;
331  using stride_seq = camp::int_seq<LinIdx, StrideInts...>;
332  using LayoutType = RAJA::detail::
333  StaticLayoutBase_impl<LinIdx, range_seq, size_seq, stride_seq, DIM_LIST>;
334 
335  // This is the stride-one dimensions w.r.t. the tensor not the View
336  // For example:
337  // For a vector, s_stride_one_dim is either 0 (packed) or -1 (strided)
338  // For a matrix, s_stride_one_dim is either:
339  // -1 neither row nor column are packed
340  // 0 rows are stride-one
341  // 1 columns are stride-one
342  static constexpr camp::idx_t s_stride_one_dim = RAJA::max<camp::idx_t>(
343  (GetTensorArgIdx<VecHead, index_list>::value == LayoutType::stride_one_dim
344  ? VecHead
345  : -1),
346  (GetTensorArgIdx<VecSeq, index_list>::value == LayoutType::stride_one_dim
347  ? VecSeq
348  : -1)...);
349 
350 
351  using new_begin_seq =
352  camp::int_seq<LinIdx,
353  (LinIdx)get_tensor_args_begin<VecHead>(
354  LayoutType(),
356  (LinIdx)get_tensor_args_begin<VecSeq>(
357  LayoutType(),
359  using new_size_seq =
360  camp::int_seq<LinIdx,
361  (LinIdx)get_tensor_args_size<VecHead>(
362  LayoutType(),
364  (LinIdx)get_tensor_args_size<VecSeq>(
365  LayoutType(),
367 
368  using new_begin_type = internal::expt::StaticIndexArray<new_begin_seq>;
369  using new_size_type = internal::expt::StaticIndexArray<new_size_seq>;
370 
371 
372  using tensor_reg_type =
373  typename camp::at_v<index_list,
374  GetTensorArgIdx<0, index_list>::value>::tensor_type;
375  using ref_type =
376  internal::expt::StaticTensorRef<ElementType*,
377  LinIdx,
379  stride_seq,
380  new_begin_seq,
381  new_size_seq,
382  s_stride_one_dim>;
383  using return_type =
384  internal::expt::ET::TensorLoadStore<tensor_reg_type, ref_type>;
385 
386  RAJA_INLINE RAJA_HOST_DEVICE static constexpr return_type make_return(
387  LayoutType const& layout,
388  PointerType const& data,
390  {
391 
392  return return_type(ref_type {
393  // data pointer
394  &data[0] +
397  INDEX_TYPES>::base_type>()
398  ? LinIdx {0}
399  : (LinIdx)stripIndexType(
401  // strides
402  typename ref_type::stride_type(),
403  // tile
404  {new_begin_type(), new_size_type()}});
405  }
406 };
407 #endif
408 
409 
410 } // namespace detail
411 
412 /*
413  * Computes the return type of a view.
414  *
415  * If any of the arguments are a VectorIndex, it creates a VectorRef
416  * return type.
417  *
418  * Otherwise it produces the usual scalar reference return type
419  */
420 template<typename ElementType,
421  typename PointerType,
422  typename LinIdx,
423  typename LayoutType,
424  typename... Args>
426  camp::make_idx_seq_t<count_num_tensor_args<Args...>::value>,
427  camp::list<Args...>,
428  ElementType,
429  PointerType,
430  LinIdx,
431  LayoutType>::return_type;
432 
433 /*
434  * Creates the return value for a View
435  *
436  * If any of the arguments are a VectorIndex, it creates a VectorRef
437  * return value.
438  *
439  * Otherwise it produces the usual scalar reference return value
440  */
441 template<typename ElementType,
442  typename LinIdx,
443  typename LayoutType,
444  typename PointerType,
445  typename... Args>
446 RAJA_INLINE RAJA_HOST_DEVICE constexpr view_return_type_t<ElementType,
447  PointerType,
448  LinIdx,
449  LayoutType,
450  Args...>
451 view_make_return_value(LayoutType const& layout,
452  PointerType const& data,
453  Args const&... args)
454 {
456  camp::make_idx_seq_t<count_num_tensor_args<Args...>::value>,
457  camp::list<Args...>, ElementType, PointerType, LinIdx,
458  LayoutType>::make_return(layout, data, args...);
459 }
460 
461 namespace detail
462 {
463 
474 template<typename Expected, typename Arg>
476 {
477  static_assert(std::is_convertible<strip_index_type_t<Arg>,
479  "Argument isn't compatible");
480 
482 
483  static RAJA_HOST_DEVICE RAJA_INLINE constexpr type extract(Arg arg)
484  {
485  return stripIndexType(arg);
486  }
487 };
488 
489 
490 #if defined(RAJA_ENABLE_VECTORIZATION)
497 template<typename Expected, typename Arg, typename VectorType, camp::idx_t DIM>
498 struct MatchTypedViewArgHelper<Expected,
499  RAJA::expt::TensorIndex<Arg, VectorType, DIM>>
500 {
501 
502  static_assert(std::is_convertible<strip_index_type_t<Arg>,
504  "Argument isn't compatible");
505 
506  using arg_type = strip_index_type_t<Arg>;
507 
509 
510  static constexpr RAJA_HOST_DEVICE RAJA_INLINE type
512  {
513  return type(stripIndexType(*vec_arg), vec_arg.size());
514  }
515 };
516 
523 template<typename Expected,
524  typename Arg,
525  typename VectorType,
526  camp::idx_t DIM,
527  Arg BEGIN,
528  strip_index_type_t<Arg> LENGTH>
529 struct MatchTypedViewArgHelper<
530  Expected,
531  RAJA::expt::StaticTensorIndex<
532  RAJA::expt::
533  StaticTensorIndexInner<Arg, VectorType, DIM, BEGIN, LENGTH>>>
534 {
535 
536  static_assert(std::is_convertible<strip_index_type_t<Arg>,
537  strip_index_type_t<Expected>>::value,
538  "Argument isn't compatible");
539 
540  using arg_type = strip_index_type_t<Arg>;
541 
543  RAJA::expt::
544  StaticTensorIndexInner<arg_type, VectorType, DIM, BEGIN, LENGTH>>;
545 
546  static constexpr RAJA_HOST_DEVICE RAJA_INLINE type extract(
548  RAJA::expt::
549  StaticTensorIndexInner<Arg, VectorType, DIM, BEGIN, LENGTH>>
550  RAJA_UNUSED_ARG(vec_arg))
551  {
552  return type();
553  }
554 };
555 #endif
556 
557 } // namespace detail
558 
559 template<typename Expected, typename Arg>
560 RAJA_HOST_DEVICE RAJA_INLINE constexpr
562  match_typed_view_arg(Arg const& arg)
563 {
565 }
566 
567 template<typename ValueType, typename PointerType, typename LayoutType>
568 class ViewBase
569 {
570 
571 public:
572  using value_type = ValueType;
573  using pointer_type = PointerType;
574  using layout_type = LayoutType;
575  using linear_index_type = typename layout_type::IndexLinear;
576  using nc_value_type = typename std::remove_const<value_type>::type;
577  using nc_pointer_type = typename std::add_pointer<typename std::remove_const<
578  typename std::remove_pointer<pointer_type>::type>::type>::type;
579 
582 
585 
586 protected:
589 
590 public:
591  /*
592  * Defaulted operators (AJK):
593  *
594  * OpenMP Target currently needs the View classes to be trivially copyable,
595  * which means that we need to use the default ctor's and assignment
596  * operators.
597  *
598  * These defaulted operators cause issues with some versions of CUDA, so
599  * in the case that CUDA is enabled, we switch to explicitly defined
600  * operators.
601  */
602 #if (defined(RAJA_ENABLE_CUDA) || defined(RAJA_ENABLE_CLANG_CUDA))
604  RAJA_INLINE
605  constexpr ViewBase() {};
606 
607  RAJA_HOST_DEVICE RAJA_INLINE constexpr ViewBase(ViewBase const& c)
608  : m_layout(c.m_layout),
609  m_data(c.m_data)
610  {}
611 
612  RAJA_HOST_DEVICE RAJA_INLINE constexpr ViewBase& operator=(ViewBase const& c)
613  {
614  m_layout = c.m_layout;
615  m_data = c.m_data;
616  }
617 #else
618  constexpr ViewBase() = default;
619  RAJA_INLINE constexpr ViewBase(ViewBase const&) = default;
620  RAJA_INLINE constexpr ViewBase(ViewBase&&) = default;
621  RAJA_INLINE constexpr ViewBase& operator=(ViewBase const&) = default;
622  RAJA_INLINE constexpr ViewBase& operator=(ViewBase&&) = default;
623 
624 #endif
625 
627 
628  RAJA_INLINE
629  constexpr ViewBase(pointer_type data, layout_type&& layout)
630  : m_data(data),
631  m_layout(layout)
632  {}
633 
634  template<typename... Args>
635  RAJA_HOST_DEVICE RAJA_INLINE constexpr ViewBase(pointer_type data,
636  Args... dim_sizes)
637  : m_data(data),
638  m_layout(dim_sizes...)
639  {}
640 
641  template<bool IsConstView = std::is_const<value_type>::value>
642  RAJA_HOST_DEVICE RAJA_INLINE constexpr ViewBase(
643  typename std::enable_if<IsConstView, NonConstView>::type const& rhs)
644  : m_data(rhs.get_data()),
645  m_layout(rhs.get_layout())
646  {}
647 
648  RAJA_HOST_DEVICE RAJA_INLINE constexpr void set_data(PointerType data_ptr)
649  {
650  m_data = data_ptr;
651  }
652 
653  RAJA_HOST_DEVICE RAJA_INLINE constexpr pointer_type const& get_data() const
654  {
655  return m_data;
656  }
657 
658  RAJA_HOST_DEVICE RAJA_INLINE constexpr layout_type const& get_layout() const
659  {
660  return m_layout;
661  }
662 
663  RAJA_HOST_DEVICE RAJA_INLINE constexpr linear_index_type size() const
664  {
665  return m_layout.size();
666  }
667 
668  template<camp::idx_t DIM>
669  RAJA_HOST_DEVICE RAJA_INLINE constexpr linear_index_type get_dim_size() const
670  {
671  return m_layout.template get_dim_size<DIM>();
672  }
673 
674  template<typename... Args>
675  RAJA_HOST_DEVICE RAJA_INLINE constexpr view_return_type_t<value_type,
676  pointer_type,
678  layout_type,
679  Args...>
680  operator()(Args... args) const
681  {
682  return view_make_return_value<value_type, linear_index_type>(
683  m_layout, m_data, args...);
684  }
685 
686  /*
687  * Compatibility note (AJK):
688  * We are using variadic arguments even though operator[] takes exactly 1
689  * argument This gets around a template instantiation bug in CUDA/nvcc 9.1,
690  * which seems to have been fixed in CUDA 9.2+
691  */
692  template<typename... Args>
693  RAJA_HOST_DEVICE RAJA_INLINE constexpr view_return_type_t<value_type,
694  pointer_type,
696  layout_type,
697  Args...>
698  operator[](Args... args) const
699  {
700  return view_make_return_value<value_type, linear_index_type>(
701  m_layout, m_data, args...);
702  }
703 
704  // why doesn't this return a shifted copy instead of shifting this view?
705  template<size_t n_dims = layout_type::n_dims,
706  typename IdxLin = linear_index_type>
707  RAJA_HOST_DEVICE RAJA_INLINE constexpr ShiftedView shift(
708  const std::array<IdxLin, n_dims>& shift)
709  {
710  static_assert(n_dims == layout_type::n_dims,
711  "Dimension mismatch in ViewBase shift");
712 
713  shifted_layout_type shift_layout(m_layout);
714  shift_layout.shift(shift);
715 
716  return ShiftedView(m_data, shift_layout);
717  }
718 };
719 
720 
721 template<typename ValueType,
722  typename PointerType,
723  typename LayoutType,
724  typename IndexTypes>
726 
727 template<typename ValueType,
728  typename PointerType,
729  typename LayoutType,
730  typename... IndexTypes>
731 class TypedViewBase<ValueType,
732  PointerType,
733  LayoutType,
734  camp::list<IndexTypes...>>
735  : public ViewBase<ValueType, PointerType, LayoutType>
736 {
737 
738 public:
739  using value_type = ValueType;
740  using pointer_type = PointerType;
741  using layout_type = LayoutType;
742  using linear_index_type = typename layout_type::IndexLinear;
743  using nc_value_type = typename std::remove_const<value_type>::type;
744  using nc_pointer_type = typename std::add_pointer<typename std::remove_const<
745  typename std::remove_pointer<pointer_type>::type>::type>::type;
746 
749  pointer_type,
750  layout_type,
751  camp::list<IndexTypes...>>;
754  layout_type,
755  camp::list<IndexTypes...>>;
756 
759  pointer_type,
761  camp::list<IndexTypes...>>;
762 
763  static constexpr size_t n_dims = sizeof...(IndexTypes);
764 
765  using Base::Base;
766 
767  template<typename... Args>
768  RAJA_HOST_DEVICE RAJA_INLINE constexpr view_return_type_t<value_type,
769  pointer_type,
771  layout_type,
772  Args...>
773  operator()(Args... args) const
774  {
775  return view_make_return_value<value_type, linear_index_type>(
776  Base::m_layout, Base::m_data,
777  match_typed_view_arg<IndexTypes>(args)...);
778  }
779 
780  /*
781  * Compatibility note (AJK):
782  * We are using variadic arguments even though operator[] takes exactly 1
783  * argument This gets around a template instantiation bug in CUDA/nvcc 9.1,
784  * which seems to have been fixed in CUDA 9.2+
785  */
786  template<typename... Args>
787  RAJA_HOST_DEVICE RAJA_INLINE constexpr view_return_type_t<value_type,
788  pointer_type,
789  linear_index_type,
790  layout_type,
791  Args...>
792  operator[](Args... args) const
793  {
794  return view_make_return_value<value_type, linear_index_type>(
795  Base::m_layout, Base::m_data,
796  match_typed_view_arg<IndexTypes>(args)...);
797  }
798 
799  // why doesn't this return a shifted copy instead of shifting this view?
800  template<size_t n_dims = sizeof...(IndexTypes),
801  typename IdxLin = linear_index_type>
802  RAJA_HOST_DEVICE RAJA_INLINE constexpr ShiftedView shift(
803  const std::array<IdxLin, n_dims>& shift)
804  {
805  static_assert(n_dims == layout_type::n_dims,
806  "Dimension mismatch in TypedViewBase shift");
807 
808  shifted_layout_type shift_layout(Base::get_layout());
809  shift_layout.shift(shift);
810 
811  return ShiftedView(Base::get_data(), shift_layout);
812  }
813 };
814 
815 
816 } // namespace internal
817 
818 } // namespace RAJA
819 
820 #endif
RAJA header file defining Layout, a N-dimensional index calculator.
RAJA header file defining Layout, a N-dimensional index calculator with offset indices.
RAJA header file defining Layout, a N-dimensional index calculator with compile-time defined sizes an...
Definition: TensorIndex.hpp:45
RAJA_INLINE constexpr RAJA_HOST_DEVICE value_type size() const
Definition: TensorIndex.hpp:151
RAJA_HOST_DEVICE constexpr RAJA_INLINE view_return_type_t< value_type, pointer_type, linear_index_type, layout_type, Args... > operator()(Args... args) const
Definition: TypedViewBase.hpp:773
RAJA_HOST_DEVICE constexpr RAJA_INLINE view_return_type_t< value_type, pointer_type, linear_index_type, layout_type, Args... > operator[](Args... args) const
Definition: TypedViewBase.hpp:792
RAJA_HOST_DEVICE constexpr RAJA_INLINE ShiftedView shift(const std::array< IdxLin, n_dims > &shift)
Definition: TypedViewBase.hpp:802
Definition: TypedViewBase.hpp:725
Definition: TypedViewBase.hpp:569
RAJA_HOST_DEVICE constexpr RAJA_INLINE ViewBase(pointer_type data, Args... dim_sizes)
Definition: TypedViewBase.hpp:635
RAJA_HOST_DEVICE constexpr RAJA_INLINE ViewBase(pointer_type data, layout_type &&layout)
Definition: TypedViewBase.hpp:629
ViewBase< value_type, pointer_type, shifted_layout_type > ShiftedView
Definition: TypedViewBase.hpp:584
RAJA_HOST_DEVICE constexpr RAJA_INLINE linear_index_type size() const
Definition: TypedViewBase.hpp:663
LayoutType layout_type
Definition: TypedViewBase.hpp:574
RAJA_HOST_DEVICE constexpr RAJA_INLINE view_return_type_t< value_type, pointer_type, linear_index_type, layout_type, Args... > operator[](Args... args) const
Definition: TypedViewBase.hpp:698
pointer_type m_data
Definition: TypedViewBase.hpp:587
RAJA_HOST_DEVICE constexpr RAJA_INLINE ViewBase(typename std::enable_if< IsConstView, NonConstView >::type const &rhs)
Definition: TypedViewBase.hpp:642
typename std::remove_const< value_type >::type nc_value_type
Definition: TypedViewBase.hpp:576
constexpr RAJA_INLINE ViewBase & operator=(ViewBase const &)=default
constexpr ViewBase()=default
typename std::add_pointer< typename std::remove_const< typename std::remove_pointer< pointer_type >::type >::type >::type nc_pointer_type
Definition: TypedViewBase.hpp:578
RAJA_HOST_DEVICE constexpr RAJA_INLINE pointer_type const & get_data() const
Definition: TypedViewBase.hpp:653
PointerType pointer_type
Definition: TypedViewBase.hpp:573
RAJA_HOST_DEVICE constexpr RAJA_INLINE ShiftedView shift(const std::array< IdxLin, n_dims > &shift)
Definition: TypedViewBase.hpp:707
RAJA_HOST_DEVICE constexpr RAJA_INLINE layout_type const & get_layout() const
Definition: TypedViewBase.hpp:658
layout_type const m_layout
Definition: TypedViewBase.hpp:588
typename add_offset< layout_type >::type shifted_layout_type
Definition: TypedViewBase.hpp:583
constexpr RAJA_INLINE ViewBase(ViewBase &&)=default
RAJA_HOST_DEVICE constexpr RAJA_INLINE view_return_type_t< value_type, pointer_type, linear_index_type, layout_type, Args... > operator()(Args... args) const
Definition: TypedViewBase.hpp:680
ValueType value_type
Definition: TypedViewBase.hpp:572
RAJA_HOST_DEVICE constexpr RAJA_INLINE void set_data(PointerType data_ptr)
Definition: TypedViewBase.hpp:648
constexpr RAJA_INLINE ViewBase & operator=(ViewBase &&)=default
constexpr RAJA_INLINE ViewBase(ViewBase const &)=default
typename layout_type::IndexLinear linear_index_type
Definition: TypedViewBase.hpp:575
RAJA_HOST_DEVICE constexpr RAJA_INLINE linear_index_type get_dim_size() const
Definition: TypedViewBase.hpp:669
Definition: TensorLoadStore.hpp:75
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_UNUSED_ARG(x)
Definition: macros.hpp:97
Args args
Definition: WorkRunner.hpp:212
Definition: TypeTraits.hpp:30
RAJA_INLINE constexpr RAJA_HOST_DEVICE auto stripTensorIndexByValue(ARG const arg) -> typename TensorIndexTraits< ARG >::arg_type const
Definition: TensorIndexTraits.hpp:224
@ TENSOR_MULTIPLE
Definition: TensorRef.hpp:237
RAJA_INLINE constexpr RAJA_HOST_DEVICE bool isTensorIndex()
Definition: TensorIndexTraits.hpp:211
typename SequenceToType< Perm, RAJA::Index_type >::type getDefaultIndexTypes
Definition: TypedViewBase.hpp:60
typename detail::ViewReturnHelper< camp::make_idx_seq_t< count_num_tensor_args< Args... >::value >, camp::list< Args... >, ElementType, PointerType, LinIdx, LayoutType >::return_type view_return_type_t
Definition: TypedViewBase.hpp:431
RAJA_HOST_DEVICE constexpr RAJA_INLINE detail::MatchTypedViewArgHelper< Expected, Arg >::type match_typed_view_arg(Arg const &arg)
Definition: TypedViewBase.hpp:562
RAJA_INLINE constexpr RAJA_HOST_DEVICE view_return_type_t< ElementType, PointerType, LinIdx, LayoutType, Args... > view_make_return_value(LayoutType const &layout, PointerType const &data, Args const &... args)
Definition: TypedViewBase.hpp:451
Definition: AlignedRangeIndexSetBuilders.cpp:35
typename internal::StripIndexTypeT< FROM >::type strip_index_type_t
Strips a strongly typed index to its underlying type In the case of a non-strongly typed index,...
Definition: IndexValue.hpp:364
constexpr RAJA_HOST_DEVICE RAJA_INLINE std::enable_if< std::is_base_of< IndexValueBase, FROM >::value, typename FROM::value_type >::type stripIndexType(FROM const val)
Function that strips the strongly typed Index<> and returns its underlying value_type value.
Definition: IndexValue.hpp:323
camp::idx_seq< Ints... > Perm
Definition: PermutedLayout.hpp:101
RAJA header file defining atomic operations.
RAJA header file defining SIMD/SIMT register operations.
Definition: OffsetLayout.hpp:172
Definition: Layout.hpp:329
Definition: OffsetLayout.hpp:188
Definition: StaticLayout.hpp:48
Definition: TensorIndex.hpp:41
Definition: TypedViewBase.hpp:45
T type
Definition: TypedViewBase.hpp:46
camp::list< typename IndexToType< Perm, T >::type... > type
Definition: TypedViewBase.hpp:55
Definition: TypedViewBase.hpp:50
Definition: TypedViewBase.hpp:67
Definition: TypedViewBase.hpp:111
static constexpr camp::idx_t value
Definition: TypedViewBase.hpp:112
Definition: TypedViewBase.hpp:476
strip_index_type_t< Arg > type
Definition: TypedViewBase.hpp:481
static RAJA_HOST_DEVICE constexpr RAJA_INLINE type extract(Arg arg)
Definition: TypedViewBase.hpp:483
RAJA_INLINE static constexpr RAJA_HOST_DEVICE return_type make_return(LayoutType const &layout, PointerType const &data, Args const &... args)
Definition: TypedViewBase.hpp:213
Definition: TypedViewBase.hpp:194
Definition: TensorRef.hpp:426