Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_Functional.hpp
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 3.0
5 // Copyright (2020) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
43 #ifndef KOKKOS_FUNCTIONAL_HPP
44 #define KOKKOS_FUNCTIONAL_HPP
45 
46 #include <Kokkos_Macros.hpp>
47 #include <impl/Kokkos_Functional_impl.hpp>
48 
49 namespace Kokkos {
50 
51 // These should work for most types
52 
53 template <typename T>
54 struct pod_hash {
55  typedef T argument_type;
56  typedef T first_argument_type;
57  typedef uint32_t second_argument_type;
58  typedef uint32_t result_type;
59 
60  KOKKOS_FORCEINLINE_FUNCTION
61  uint32_t operator()(T const& t) const {
62  return Impl::MurmurHash3_x86_32(&t, sizeof(T), 0);
63  }
64 
65  KOKKOS_FORCEINLINE_FUNCTION
66  uint32_t operator()(T const& t, uint32_t seed) const {
67  return Impl::MurmurHash3_x86_32(&t, sizeof(T), seed);
68  }
69 };
70 
71 template <typename T>
72 struct pod_equal_to {
73  typedef T first_argument_type;
74  typedef T second_argument_type;
75  typedef bool result_type;
76 
77  KOKKOS_FORCEINLINE_FUNCTION
78  bool operator()(T const& a, T const& b) const {
79  return Impl::bitwise_equal(&a, &b);
80  }
81 };
82 
83 template <typename T>
84 struct pod_not_equal_to {
85  typedef T first_argument_type;
86  typedef T second_argument_type;
87  typedef bool result_type;
88 
89  KOKKOS_FORCEINLINE_FUNCTION
90  bool operator()(T const& a, T const& b) const {
91  return !Impl::bitwise_equal(&a, &b);
92  }
93 };
94 
95 template <typename T>
96 struct equal_to {
97  typedef T first_argument_type;
98  typedef T second_argument_type;
99  typedef bool result_type;
100 
101  KOKKOS_FORCEINLINE_FUNCTION
102  bool operator()(T const& a, T const& b) const { return a == b; }
103 };
104 
105 template <typename T>
106 struct not_equal_to {
107  typedef T first_argument_type;
108  typedef T second_argument_type;
109  typedef bool result_type;
110 
111  KOKKOS_FORCEINLINE_FUNCTION
112  bool operator()(T const& a, T const& b) const { return a != b; }
113 };
114 
115 template <typename T>
116 struct greater {
117  typedef T first_argument_type;
118  typedef T second_argument_type;
119  typedef bool result_type;
120 
121  KOKKOS_FORCEINLINE_FUNCTION
122  bool operator()(T const& a, T const& b) const { return a > b; }
123 };
124 
125 template <typename T>
126 struct less {
127  typedef T first_argument_type;
128  typedef T second_argument_type;
129  typedef bool result_type;
130 
131  KOKKOS_FORCEINLINE_FUNCTION
132  bool operator()(T const& a, T const& b) const { return a < b; }
133 };
134 
135 template <typename T>
136 struct greater_equal {
137  typedef T first_argument_type;
138  typedef T second_argument_type;
139  typedef bool result_type;
140 
141  KOKKOS_FORCEINLINE_FUNCTION
142  bool operator()(T const& a, T const& b) const { return a >= b; }
143 };
144 
145 template <typename T>
146 struct less_equal {
147  typedef T first_argument_type;
148  typedef T second_argument_type;
149  typedef bool result_type;
150 
151  KOKKOS_FORCEINLINE_FUNCTION
152  bool operator()(T const& a, T const& b) const { return a <= b; }
153 };
154 
155 } // namespace Kokkos
156 
157 #endif // KOKKOS_FUNCTIONAL_HPP