Kokkos Core Kernels Package  Version of the Day
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 
27 //----------------------------------------------------------------------------
28 
29 namespace Kokkos {
30 
39 enum MemoryTraitsFlags {
40  Unmanaged = 0x01,
41  RandomAccess = 0x02,
42  Atomic = 0x04,
43  Restrict = 0x08,
44  Aligned = 0x10
45 };
46 
47 template <unsigned T>
48 struct MemoryTraits {
50  using memory_traits = MemoryTraits<T>;
51  enum : bool {
52  is_unmanaged = (unsigned(0) != (T & unsigned(Kokkos::Unmanaged)))
53  };
54  enum : bool {
55  is_random_access = (unsigned(0) != (T & unsigned(Kokkos::RandomAccess)))
56  };
57  enum : bool { is_atomic = (unsigned(0) != (T & unsigned(Kokkos::Atomic))) };
58  enum : bool {
59  is_restrict = (unsigned(0) != (T & unsigned(Kokkos::Restrict)))
60  };
61  enum : bool { is_aligned = (unsigned(0) != (T & unsigned(Kokkos::Aligned))) };
62 };
63 
64 } // namespace Kokkos
65 
66 //----------------------------------------------------------------------------
67 
68 namespace Kokkos {
69 
70 using MemoryManaged = Kokkos::MemoryTraits<0>;
71 using MemoryUnmanaged = Kokkos::MemoryTraits<Kokkos::Unmanaged>;
72 using MemoryRandomAccess =
73  Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::RandomAccess>;
74 
75 } // namespace Kokkos
76 
77 //----------------------------------------------------------------------------
78 
79 namespace Kokkos {
80 namespace Impl {
81 
82 static_assert((0 < int(KOKKOS_MEMORY_ALIGNMENT)) &&
83  (0 == (int(KOKKOS_MEMORY_ALIGNMENT) &
84  (int(KOKKOS_MEMORY_ALIGNMENT) - 1))),
85  "KOKKOS_MEMORY_ALIGNMENT must be a power of two");
86 
93 enum : unsigned {
94  MEMORY_ALIGNMENT = KOKKOS_MEMORY_ALIGNMENT,
95  MEMORY_ALIGNMENT_THRESHOLD = KOKKOS_MEMORY_ALIGNMENT_THRESHOLD
96 };
97 
98 // ------------------------------------------------------------------ //
99 // this identifies the default memory trait
100 //
101 template <typename Tp>
102 struct is_default_memory_trait : std::false_type {};
103 
104 template <>
105 struct is_default_memory_trait<Kokkos::MemoryTraits<0>> : std::true_type {};
106 
107 } // namespace Impl
108 } // namespace Kokkos
109 
110 #endif /* #ifndef KOKKOS_MEMORYTRAITS_HPP */
Definition: dummy.cpp:17