Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_MemoryTraits.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_IMPL_PUBLIC_INCLUDE
18 #include <Kokkos_Macros.hpp>
19 static_assert(false,
20  "Including non-public Kokkos header files is not allowed.");
21 #endif
22 #ifndef KOKKOS_MEMORYTRAITS_HPP
23 #define KOKKOS_MEMORYTRAITS_HPP
24 
25 #include <impl/Kokkos_Traits.hpp>
26 #include <Kokkos_BitManipulation.hpp>
27 
28 //----------------------------------------------------------------------------
29 
30 namespace Kokkos {
31 
40 enum MemoryTraitsFlags {
41  Unmanaged = 0x01,
42  RandomAccess = 0x02,
43  Atomic = 0x04,
44  Restrict = 0x08,
45  Aligned = 0x10
46 };
47 
48 template <unsigned T = 0>
49 struct MemoryTraits {
51  using memory_traits = MemoryTraits<T>;
52 
53  static constexpr unsigned impl_value = T;
54 
55  static constexpr bool is_unmanaged =
56  (unsigned(0) != (T & unsigned(Kokkos::Unmanaged)));
57  static constexpr bool is_random_access =
58  (unsigned(0) != (T & unsigned(Kokkos::RandomAccess)));
59  static constexpr bool is_atomic =
60  (unsigned(0) != (T & unsigned(Kokkos::Atomic)));
61  static constexpr bool is_restrict =
62  (unsigned(0) != (T & unsigned(Kokkos::Restrict)));
63  static constexpr bool is_aligned =
64  (unsigned(0) != (T & unsigned(Kokkos::Aligned)));
65 };
66 
67 } // namespace Kokkos
68 
69 //----------------------------------------------------------------------------
70 
71 namespace Kokkos {
72 
73 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
74 using MemoryManaged KOKKOS_DEPRECATED = Kokkos::MemoryTraits<>;
75 #endif
76 using MemoryUnmanaged = Kokkos::MemoryTraits<Kokkos::Unmanaged>;
77 using MemoryRandomAccess =
78  Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::RandomAccess>;
79 
80 } // namespace Kokkos
81 
82 //----------------------------------------------------------------------------
83 
84 namespace Kokkos {
85 namespace Impl {
86 
93 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
94 static constexpr unsigned MEMORY_ALIGNMENT = KOKKOS_IMPL_MEMORY_ALIGNMENT;
95 static constexpr unsigned MEMORY_ALIGNMENT_THRESHOLD =
96  KOKKOS_IMPL_MEMORY_ALIGNMENT_THRESHOLD;
97 #else
98 static constexpr unsigned MEMORY_ALIGNMENT = 64;
99 static constexpr unsigned MEMORY_ALIGNMENT_THRESHOLD = 1;
100 #endif
101 static_assert(has_single_bit(MEMORY_ALIGNMENT),
102  "MEMORY_ALIGNMENT must be a power of 2");
103 
104 // ------------------------------------------------------------------ //
105 // this identifies the default memory trait
106 //
107 template <typename Tp>
108 struct is_default_memory_trait : std::false_type {};
109 
110 template <>
111 struct is_default_memory_trait<Kokkos::MemoryTraits<>> : std::true_type {};
112 
113 } // namespace Impl
114 } // namespace Kokkos
115 
116 #endif /* #ifndef KOKKOS_MEMORYTRAITS_HPP */
static constexpr unsigned MEMORY_ALIGNMENT