QUDA: quda/include/externals/generics/detail/array.h Source File

QUDA  v1.1.0
A library for QCD on GPUs
array.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace detail {
4 
5 template<typename T, int m>
6  struct array {
7   typedef T value_type;
8   typedef T head_type;
9   typedef array<T, m-1> tail_type;
10   static const int size = m;
11   head_type head;
12   tail_type tail;
13  __host__ __device__ __forceinline__
14   array(head_type h, const tail_type& t) : head(h), tail(t) {}
15  __host__ __device__ __forceinline__
16   array() : head(), tail() {}
17  __host__ __device__ __forceinline__
18   array(const array& other) : head(other.head), tail(other.tail) {}
19  __host__ __device__ __forceinline__
20   array& operator=(const array& other) {
21  head = other.head;
22  tail = other.tail;
23  return *this;
24  }
25  __host__ __device__ __forceinline__
26   bool operator==(const array& other) const {
27  return (head == other.head) && (tail == other.tail);
28  }
29  __host__ __device__ __forceinline__
30   bool operator!=(const array& other) const {
31  return !operator==(other);
32  }
33 };
34 
35 template<typename T>
36  struct array<T, 1> {
37   typedef T value_type;
38   typedef T head_type;
39   static const int size = 1;
40   head_type head;
41  __host__ __device__ __forceinline__
42   array(head_type h) : head(h){}
43  __host__ __device__ __forceinline__
44   array() : head() {}
45  __host__ __device__ __forceinline__
46   array(const array& other) : head(other.head) {}
47  __host__ __device__ __forceinline__
48   array& operator=(const array& other) {
49  head = other.head;
50  return *this;
51  }
52  __host__ __device__ __forceinline__
53   bool operator==(const array& other) const {
54  return (head == other.head);
55  }
56  __host__ __device__ __forceinline__
57   bool operator!=(const array& other) const {
58  return !operator==(other);
59  }
60 };
61 
62 template<typename T>
63  struct array<T, 0>{};
64 
65 template<typename T, int m, int i>
66  struct get_impl {
67   __host__ __device__ __forceinline__ static T& impl(array<T, m>& src) {
68  return get_impl<T, m-1, i-1>::impl(src.tail);
69  }
70   __host__ __device__ __forceinline__ static T impl(const array<T, m>& src) {
71  return get_impl<T, m-1, i-1>::impl(src.tail);
72  }
73 };
74 
75 template<typename T, int m>
76  struct get_impl<T, m, 0> {
77   __host__ __device__ __forceinline__ static T& impl(array<T, m>& src) {
78  return src.head;
79  }
80   __host__ __device__ __forceinline__ static T impl(const array<T, m>& src) {
81  return src.head;
82  }
83 };
84 
85 template<int i, typename T, int m>
86 __host__ __device__ __forceinline__
87  T& get(array<T, m>& src) {
88  return detail::get_impl<T, m, i>::impl(src);
89 }
90 
91 template<int i, typename T, int m>
92 __host__ __device__ __forceinline__
93  T get(const array<T, m>& src) {
94  return detail::get_impl<T, m, i>::impl(src);
95 }
96 
97 } //end namespace detail
detail
Definition: alias.h:4
detail::get
__host__ __device__ __forceinline__ T & get(array< T, m > &src)
Definition: array.h:87
detail::array< T, 1 >::array
__host__ __device__ __forceinline__ array(const array &other)
Definition: array.h:46
detail::array< T, 1 >::array
__host__ __device__ __forceinline__ array()
Definition: array.h:44
detail::array< T, 1 >::head
head_type head
Definition: array.h:40
detail::array< T, 1 >::operator==
__host__ __device__ __forceinline__ bool operator==(const array &other) const
Definition: array.h:53
detail::array< T, 1 >::operator!=
__host__ __device__ __forceinline__ bool operator!=(const array &other) const
Definition: array.h:57
detail::array< T, 1 >::operator=
__host__ __device__ __forceinline__ array & operator=(const array &other)
Definition: array.h:48
detail::array< T, 1 >::array
__host__ __device__ __forceinline__ array(head_type h)
Definition: array.h:42
detail::array::tail_type
array< T, m-1 > tail_type
Definition: array.h:9
detail::array::size
static const int size
Definition: array.h:10
detail::array::operator=
__host__ __device__ __forceinline__ array & operator=(const array &other)
Definition: array.h:20
detail::array::value_type
T value_type
Definition: array.h:7
detail::array::tail
tail_type tail
Definition: array.h:12
detail::array::head_type
T head_type
Definition: array.h:8
detail::array::array
__host__ __device__ __forceinline__ array(const array &other)
Definition: array.h:18
detail::array::array
__host__ __device__ __forceinline__ array()
Definition: array.h:16
detail::array::operator==
__host__ __device__ __forceinline__ bool operator==(const array &other) const
Definition: array.h:26
detail::array::array
__host__ __device__ __forceinline__ array(head_type h, const tail_type &t)
Definition: array.h:14
detail::array::head
head_type head
Definition: array.h:11
detail::array::operator!=
__host__ __device__ __forceinline__ bool operator!=(const array &other) const
Definition: array.h:30
detail::get_impl< T, m, 0 >::impl
__host__ __device__ static __forceinline__ T impl(const array< T, m > &src)
Definition: array.h:80
detail::get_impl< T, m, 0 >::impl
__host__ __device__ static __forceinline__ T & impl(array< T, m > &src)
Definition: array.h:77
detail::get_impl::impl
__host__ __device__ static __forceinline__ T impl(const array< T, m > &src)
Definition: array.h:70
detail::get_impl::impl
__host__ __device__ static __forceinline__ T & impl(array< T, m > &src)
Definition: array.h:67

Generated on Thu Oct 28 2021 16:10:26 for QUDA by doxygen 1.9.1

AltStyle によって変換されたページ (->オリジナル) /