alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
memoryOrder.hpp
Go to the documentation of this file.
1/* Copyright 2025 Mehmet Yusufoglu, René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include <string>
8
9/**
10 * @brief Provides scopes for atomic and memory fence operations, analogous to NVIDIA CUDA's atomic and fence scopes.
11 *
12 * This namespace defines the visibility scopes for atomic operations and memory fences,
13 * which control the visibility of memory operations across threads, blocks, and devices.
14 * The provided scopes are:
15 * - Block: Visibility within a thread block.
16 * - Device: Visibility across all thread blocks on the same device.
17 * - System: System-wide visibility, mapped to the strongest available atomic/fence by the backend.
18 *
19 * @see alpaka::onAcc::atomicAdd, alpaka::onAcc::memFence
20 */
21namespace alpaka::onAcc
22{
23 namespace order
24 {
25
26 /**
27 * @brief Base tag for memory order types.
28 *
29 * This tag can be used to constrain APIs that accept only valid memory orders.
30 */
32 {
33 };
34
35 /**
36 * @brief Sequentially consistent memory ordering.
37 *
38 * This is the strongest memory ordering and provides a single global order
39 * for all sequentially consistent operations.
40 */
42 {
43 static std::string getName()
44 {
45 return "SeqCst";
46 }
47 };
48
49 inline constexpr SeqCst seq_cst{};
50
51 /**
52 * @brief Acquire-release memory ordering.
53 *
54 * Ensures both acquire and release semantics. This ordering is typically
55 * used for read-modify-write operations.
56 */
58 {
59 static std::string getName()
60 {
61 return "AcqRel";
62 }
63 };
64
65 inline constexpr AcqRel acq_rel{};
66
67 /**
68 * @brief Release memory ordering.
69 *
70 * Ensures that all writes before the operation become visible before the
71 * release operation itself becomes visible.
72 */
74 {
75 static std::string getName()
76 {
77 return "Release";
78 }
79 };
80
81 inline constexpr Release release{};
82
83 /**
84 * @brief Acquire memory ordering.
85 *
86 * Ensures that all reads and writes after the operation observe effects
87 * that became visible before the acquire operation.
88 */
90 {
91 static std::string getName()
92 {
93 return "Acquire";
94 }
95 };
96
97 inline constexpr Acquire acquire{};
98
99 /**
100 * @brief Relaxed memory ordering.
101 *
102 * Provides atomicity without additional ordering guarantees.
103 */
105 {
106 static std::string getName()
107 {
108 return "Relaxed";
109 }
110 };
111
112 inline constexpr Relaxed relaxed{};
113 } // namespace order
114
115 namespace concepts
116 {
117 template<typename T>
118 concept MemoryOrder = std::derived_from<T, order::MemoryOrderTag>;
119 } // namespace concepts
120
121} // namespace alpaka::onAcc
constexpr Release release
constexpr AcqRel acq_rel
constexpr Relaxed relaxed
constexpr Acquire acquire
constexpr SeqCst seq_cst
functionality which is usable on the accelerator compute device from within a kernel.
Definition executor.hpp:38
Acquire-release memory ordering.
static std::string getName()
Acquire memory ordering.
static std::string getName()
Base tag for memory order types.
Relaxed memory ordering.
static std::string getName()
Release memory ordering.
static std::string getName()
Sequentially consistent memory ordering.
static std::string getName()