Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
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>
19static_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
30namespace Kokkos {
31
40enum MemoryTraitsFlags {
41 Unmanaged = 0x01,
42 RandomAccess = 0x02,
43 Atomic = 0x04,
44 Restrict = 0x08,
45 Aligned = 0x10
46};
47
48template <unsigned T = 0>
49struct 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
71namespace Kokkos {
72
73#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
74using MemoryManaged KOKKOS_DEPRECATED = Kokkos::MemoryTraits<>;
75#endif
76using MemoryUnmanaged = Kokkos::MemoryTraits<Kokkos::Unmanaged>;
77using MemoryRandomAccess =
79
80} // namespace Kokkos
81
82//----------------------------------------------------------------------------
83
84namespace Kokkos {
85namespace Impl {
86
93#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
94static constexpr unsigned MEMORY_ALIGNMENT = KOKKOS_IMPL_MEMORY_ALIGNMENT;
95static constexpr unsigned MEMORY_ALIGNMENT_THRESHOLD =
96 KOKKOS_IMPL_MEMORY_ALIGNMENT_THRESHOLD;
97#else
98static constexpr unsigned MEMORY_ALIGNMENT = 64;
99static constexpr unsigned MEMORY_ALIGNMENT_THRESHOLD = 1;
100#endif
101static_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//
107template <typename Tp>
108struct is_default_memory_trait : std::false_type {};
109
110template <>
111struct is_default_memory_trait<Kokkos::MemoryTraits<>> : std::true_type {};
112
113} // namespace Impl
114} // namespace Kokkos
115
116#endif /* #ifndef KOKKOS_MEMORYTRAITS_HPP */
A thread safe view to a bitset.
static constexpr unsigned MEMORY_ALIGNMENT
Memory alignment settings.