RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
scalar.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_policy_vector_register_scalar_HPP
21 #define RAJA_policy_vector_register_scalar_HPP
22 
24 
25 namespace RAJA
26 {
27 namespace expt
28 {
29 
35 template<typename T>
37  : public internal::expt::RegisterBase<Register<T, scalar_register>>
38 {
39 public:
41 
44  using element_type = T;
45  using register_type = T;
46 
49  T>::int_element_type,
51 
52 
53 private:
54  T m_value;
55 
56 public:
57  static constexpr camp::idx_t s_num_elem = 1;
58 
63 
64  RAJA_INLINE
65  constexpr Register() : base_type(), m_value(0) {}
66 
71 
72  RAJA_INLINE
73  constexpr Register(element_type const& c) : base_type(), m_value(c) {}
74 
79 
80  RAJA_INLINE
81  constexpr Register(self_type const& c) : base_type(), m_value(c.m_value) {}
82 
87 
88  RAJA_INLINE
90  {
91  m_value = c.m_value;
92  return *this;
93  }
94 
100 
101  RAJA_INLINE
103  {
104  m_value = ptr[0];
105  return *this;
106  }
107 
114 
115  RAJA_INLINE
116  self_type& load_packed_n(element_type const* ptr, camp::idx_t N)
117  {
118  if (N > 0)
119  {
120  m_value = ptr[0];
121  }
122  else
123  {
124  m_value = element_type(0);
125  }
126  return *this;
127  }
128 
134 
135  RAJA_INLINE
136  self_type& load_strided(element_type const* ptr, camp::idx_t)
137  {
138  m_value = ptr[0];
139  return *this;
140  }
141 
148 
149  RAJA_INLINE
150  self_type& load_strided_n(element_type const* ptr, camp::idx_t, camp::idx_t N)
151  {
152  if (N > 0)
153  {
154  m_value = ptr[0];
155  }
156  else
157  {
158  m_value = element_type(0);
159  }
160  return *this;
161  }
162 
172  RAJA_INLINE
174  {
175 
176  m_value = ptr[offsets.get(0)];
177 
178  return *this;
179  }
180 
190  RAJA_INLINE
192  int_vector_type offsets,
193  camp::idx_t N)
194  {
195  if (N > 0)
196  {
197  m_value = ptr[offsets.get(0)];
198  }
199  else
200  {
201  m_value = element_type(0);
202  }
203  return *this;
204  }
205 
211 
212  RAJA_INLINE
214  {
215  ptr[0] = m_value;
216  return *this;
217  }
218 
224 
225  RAJA_INLINE
226  self_type const& store_packed_n(element_type* ptr, camp::idx_t N) const
227  {
228  if (N > 0)
229  {
230  ptr[0] = m_value;
231  }
232  return *this;
233  }
234 
240 
241  RAJA_INLINE
242  self_type const& store_strided(element_type* ptr, camp::idx_t) const
243  {
244  ptr[0] = m_value;
245  return *this;
246  }
247 
253 
254  RAJA_INLINE
256  camp::idx_t,
257  camp::idx_t N) const
258  {
259  if (N > 0)
260  {
261  ptr[0] = m_value;
262  }
263  return *this;
264  }
265 
275  RAJA_INLINE
276  self_type const& scatter(element_type* ptr, int_vector_type offsets) const
277  {
278 
279  ptr[offsets.get(0)] = m_value;
280 
281  return *this;
282  }
283 
293  RAJA_INLINE
295  int_vector_type offsets,
296  camp::idx_t N) const
297  {
298  if (N > 0)
299  {
300  ptr[offsets.get(0)] = m_value;
301  }
302  return *this;
303  }
304 
310  constexpr RAJA_INLINE RAJA_HOST_DEVICE element_type get(camp::idx_t) const
311  {
312  return m_value;
313  }
314 
320  RAJA_INLINE
321 
323  self_type& set(element_type value, camp::idx_t)
324  {
325  m_value = value;
326  return *this;
327  }
328 
330 
331  RAJA_INLINE
333  {
334  m_value = a;
335  return *this;
336  }
337 
339 
340  RAJA_INLINE
341  self_type& copy(self_type const& src)
342  {
343  m_value = src.m_value;
344  return *this;
345  }
346 
348 
349  RAJA_INLINE
350  self_type add(self_type const& b) const
351  {
352  return self_type(m_value + b.m_value);
353  }
354 
356 
357  RAJA_INLINE
358  self_type subtract(self_type const& b) const
359  {
360  return self_type(m_value - b.m_value);
361  }
362 
364 
365  RAJA_INLINE
366  self_type multiply(self_type const& b) const
367  {
368  return self_type(m_value * b.m_value);
369  }
370 
372 
373  RAJA_INLINE
374  self_type divide(self_type const& b) const
375  {
376  return self_type(m_value / b.m_value);
377  }
378 
388  RAJA_INLINE
389 
391  self_type multiply_add(self_type const& b, self_type const& c) const
392  {
393  return m_value * b.m_value + c.m_value;
394  }
395 
405  RAJA_INLINE
406 
408  self_type multiply_subtract(self_type const& b, self_type const& c) const
409  {
410  return m_value * b.m_value - c.m_value;
411  }
412 
418 
419  RAJA_INLINE
420  constexpr element_type sum() const { return m_value; }
421 
427 
428  RAJA_INLINE
429  constexpr element_type dot(self_type const& b) const
430  {
431  return m_value * b.m_value;
432  }
433 
439 
440  RAJA_INLINE
441  constexpr element_type max() const { return m_value; }
442 
448 
449  RAJA_INLINE
450  element_type max_n(camp::idx_t N) const
451  {
452  return N ? m_value : RAJA::operators::limits<element_type>::min();
453  ;
454  }
455 
461 
462  RAJA_INLINE
464  {
465  return self_type(RAJA::max<element_type>(m_value, a.m_value));
466  }
467 
473 
474  RAJA_INLINE
475  element_type min() const { return m_value; }
476 
482 
483  RAJA_INLINE
484  element_type min_n(camp::idx_t N) const
485  {
486  return N ? m_value : RAJA::operators::limits<element_type>::max();
487  ;
488  }
489 
495 
496  RAJA_INLINE
498  {
499  return self_type(RAJA::min<element_type>(m_value, a.m_value));
500  }
501 };
502 } // namespace expt
503 } // namespace RAJA
504 
505 
506 #endif
RAJA header file defining SIMD/SIMT register operations.
RAJA_INLINE RAJA_HOST_DEVICE self_type multiply_subtract(self_type const &b, self_type const &c) const
Fused multiply subtract: fms(b, c) = (*this)*b-c.
Definition: scalar.hpp:408
RAJA_HOST_DEVICE RAJA_INLINE self_type & load_packed(element_type const *ptr)
Load a full register from a stride-one memory location.
Definition: scalar.hpp:102
RAJA_HOST_DEVICE constexpr RAJA_INLINE Register(element_type const &c)
Copy constructor from underlying simd register.
Definition: scalar.hpp:73
RAJA_HOST_DEVICE RAJA_INLINE element_type min() const
Returns the smallest element.
Definition: scalar.hpp:475
RAJA_HOST_DEVICE RAJA_INLINE self_type const & store_packed_n(element_type *ptr, camp::idx_t N) const
Store entire register to consecutive memory locations.
Definition: scalar.hpp:226
RAJA_HOST_DEVICE RAJA_INLINE self_type vmax(self_type a) const
Returns element-wise largest values.
Definition: scalar.hpp:463
RAJA_HOST_DEVICE RAJA_INLINE self_type & load_packed_n(element_type const *ptr, camp::idx_t N)
Partially load a register from a stride-one memory location given a run-time number of elements.
Definition: scalar.hpp:116
RAJA_HOST_DEVICE RAJA_INLINE self_type const & store_strided(element_type *ptr, camp::idx_t) const
Store entire register to consecutive memory locations.
Definition: scalar.hpp:242
RAJA_HOST_DEVICE RAJA_INLINE self_type subtract(self_type const &b) const
Definition: scalar.hpp:358
RAJA_HOST_DEVICE RAJA_INLINE self_type add(self_type const &b) const
Definition: scalar.hpp:350
RAJA_INLINE RAJA_HOST_DEVICE self_type multiply_add(self_type const &b, self_type const &c) const
Fused multiply add: fma(b, c) = (*this)*b+c.
Definition: scalar.hpp:391
RAJA_HOST_DEVICE RAJA_INLINE self_type & copy(self_type const &src)
Definition: scalar.hpp:341
RAJA_HOST_DEVICE RAJA_INLINE self_type divide(self_type const &b) const
Definition: scalar.hpp:374
T register_type
Definition: scalar.hpp:45
RAJA_HOST_DEVICE constexpr RAJA_INLINE Register()
Default constructor, zeros register contents.
Definition: scalar.hpp:65
RAJA_HOST_DEVICE RAJA_INLINE self_type & broadcast(element_type const &a)
Definition: scalar.hpp:332
RAJA_HOST_DEVICE constexpr RAJA_INLINE Register(self_type const &c)
Copy constructor.
Definition: scalar.hpp:81
RAJA_HOST_DEVICE RAJA_INLINE self_type const & store_packed(element_type *ptr) const
Store entire register to consecutive memory locations.
Definition: scalar.hpp:213
RAJA_HOST_DEVICE RAJA_INLINE self_type & load_strided(element_type const *ptr, camp::idx_t)
Gather a full register from a strided memory location.
Definition: scalar.hpp:136
RAJA_INLINE RAJA_HOST_DEVICE self_type & set(element_type value, camp::idx_t)
Set scalar value in vector register.
Definition: scalar.hpp:323
RAJA_HOST_DEVICE RAJA_INLINE self_type vmin(self_type a) const
Returns element-wise largest values.
Definition: scalar.hpp:497
RAJA_HOST_DEVICE constexpr RAJA_INLINE element_type sum() const
Sum the elements of this vector.
Definition: scalar.hpp:420
RAJA_INLINE self_type & gather(element_type const *ptr, int_vector_type offsets)
Generic gather operation for full vector.
Definition: scalar.hpp:173
RAJA_HOST_DEVICE RAJA_INLINE self_type const & store_strided_n(element_type *ptr, camp::idx_t, camp::idx_t N) const
Store partial register to consecutive memory locations.
Definition: scalar.hpp:255
RAJA_HOST_DEVICE constexpr RAJA_INLINE element_type max() const
Returns the largest element.
Definition: scalar.hpp:441
RAJA_HOST_DEVICE RAJA_INLINE element_type min_n(camp::idx_t N) const
Returns the smallest element from first N lanes.
Definition: scalar.hpp:484
T element_type
Definition: scalar.hpp:44
RAJA_INLINE self_type & gather_n(element_type const *ptr, int_vector_type offsets, camp::idx_t N)
Generic gather operation for n-length subvector.
Definition: scalar.hpp:191
RAJA_INLINE self_type const & scatter_n(element_type *ptr, int_vector_type offsets, camp::idx_t N) const
Generic scatter operation for n-length subvector.
Definition: scalar.hpp:294
RAJA_INLINE self_type const & scatter(element_type *ptr, int_vector_type offsets) const
Generic scatter operation for full vector.
Definition: scalar.hpp:276
RAJA_HOST_DEVICE RAJA_INLINE self_type & operator=(self_type const &c)
Copy assignment constructor.
Definition: scalar.hpp:89
RAJA_HOST_DEVICE RAJA_INLINE self_type & load_strided_n(element_type const *ptr, camp::idx_t, camp::idx_t N)
Partially load a register from a stride-one memory location given a run-time number of elements.
Definition: scalar.hpp:150
RAJA_HOST_DEVICE constexpr RAJA_INLINE element_type dot(self_type const &b) const
Sum the elements of this vector.
Definition: scalar.hpp:429
RAJA_HOST_DEVICE RAJA_INLINE element_type max_n(camp::idx_t N) const
Returns the largest element from first N lanes.
Definition: scalar.hpp:450
RAJA_HOST_DEVICE RAJA_INLINE self_type multiply(self_type const &b) const
Definition: scalar.hpp:366
constexpr RAJA_INLINE RAJA_HOST_DEVICE element_type get(camp::idx_t) const
Get scalar value from vector register.
Definition: scalar.hpp:310
Definition: RegisterBase.hpp:39
Definition: RegisterBase.hpp:117
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result min(Args... args)
Definition: foldl.hpp:161
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result max(Args... args)
Definition: foldl.hpp:155
Definition: arch.hpp:114