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. 4.0
5 // Copyright (2022) 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 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 
17 #ifndef KOKKOS_FUNCTIONAL_HPP
18 #define KOKKOS_FUNCTIONAL_HPP
19 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE
21 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_FUNCTIONAL
22 #endif
23 
24 #include <Kokkos_Macros.hpp>
25 #include <impl/Kokkos_Functional_impl.hpp>
26 
27 namespace Kokkos {
28 
29 // These should work for most types
30 
31 template <typename T>
32 struct pod_hash {
33  KOKKOS_FORCEINLINE_FUNCTION
34  uint32_t operator()(T const& t) const {
35  return Impl::MurmurHash3_x86_32(&t, sizeof(T), 0);
36  }
37 
38  KOKKOS_FORCEINLINE_FUNCTION
39  uint32_t operator()(T const& t, uint32_t seed) const {
40  return Impl::MurmurHash3_x86_32(&t, sizeof(T), seed);
41  }
42 };
43 
44 template <typename T>
45 struct pod_equal_to {
46  KOKKOS_FORCEINLINE_FUNCTION
47  bool operator()(T const& a, T const& b) const {
48  return Impl::bitwise_equal(&a, &b);
49  }
50 };
51 
52 template <typename T>
53 struct pod_not_equal_to {
54  KOKKOS_FORCEINLINE_FUNCTION
55  bool operator()(T const& a, T const& b) const {
56  return !Impl::bitwise_equal(&a, &b);
57  }
58 };
59 
60 template <typename T>
61 struct equal_to {
62  KOKKOS_FORCEINLINE_FUNCTION
63  bool operator()(T const& a, T const& b) const { return a == b; }
64 };
65 
66 template <typename T>
67 struct not_equal_to {
68  KOKKOS_FORCEINLINE_FUNCTION
69  bool operator()(T const& a, T const& b) const { return a != b; }
70 };
71 
72 template <typename T>
73 struct greater {
74  KOKKOS_FORCEINLINE_FUNCTION
75  bool operator()(T const& a, T const& b) const { return a > b; }
76 };
77 
78 template <typename T>
79 struct less {
80  KOKKOS_FORCEINLINE_FUNCTION
81  bool operator()(T const& a, T const& b) const { return a < b; }
82 };
83 
84 template <typename T>
85 struct greater_equal {
86  KOKKOS_FORCEINLINE_FUNCTION
87  bool operator()(T const& a, T const& b) const { return a >= b; }
88 };
89 
90 template <typename T>
91 struct less_equal {
92  KOKKOS_FORCEINLINE_FUNCTION
93  bool operator()(T const& a, T const& b) const { return a <= b; }
94 };
95 
96 } // namespace Kokkos
97 
98 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_FUNCTIONAL
99 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
100 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_FUNCTIONAL
101 #endif
102 #endif // KOKKOS_FUNCTIONAL_HPP