DPC++ Runtime
Runtime libraries for oneAPI DPC++
memory_enums.hpp
Go to the documentation of this file.
1 //==-------------- memory_enums.hpp --- SYCL enums -------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/detail/pi.h> // for PI_MEMORY_ORDER_ACQUIRE, PI_MEMORY_ORDER_ACQ_REL
12 
13 #include <atomic> // for memory_order
14 #include <vector> // for vector
15 
16 namespace sycl {
17 inline namespace _V1 {
18 
19 enum class memory_order : int {
20  relaxed = 0,
21  acquire = 1,
23  2, // helps optimizer when mapping to std::memory_order
24  release = 3,
25  acq_rel = 4,
26  seq_cst = 5
27 };
28 
29 enum class memory_scope : int {
30  work_item = 0,
31  sub_group = 1,
32  work_group = 2,
33  device = 3,
34  system = 4
35 };
36 
40 inline constexpr auto memory_scope_device = memory_scope::device;
41 inline constexpr auto memory_scope_system = memory_scope::system;
42 
48 
49 namespace detail {
50 
51 inline std::vector<memory_order>
53  std::vector<memory_order> result;
54  if (bits & PI_MEMORY_ORDER_RELAXED)
55  result.push_back(memory_order::relaxed);
56  if (bits & PI_MEMORY_ORDER_ACQUIRE)
57  result.push_back(memory_order::acquire);
58  if (bits & PI_MEMORY_ORDER_RELEASE)
59  result.push_back(memory_order::release);
60  if (bits & PI_MEMORY_ORDER_ACQ_REL)
61  result.push_back(memory_order::acq_rel);
62  if (bits & PI_MEMORY_ORDER_SEQ_CST)
63  result.push_back(memory_order::seq_cst);
64  return result;
65 }
66 
67 inline std::vector<memory_scope>
69  std::vector<memory_scope> result;
70  if (bits & PI_MEMORY_SCOPE_WORK_ITEM)
71  result.push_back(memory_scope::work_item);
72  if (bits & PI_MEMORY_SCOPE_SUB_GROUP)
73  result.push_back(memory_scope::sub_group);
74  if (bits & PI_MEMORY_SCOPE_WORK_GROUP)
75  result.push_back(memory_scope::work_group);
76  if (bits & PI_MEMORY_SCOPE_DEVICE)
77  result.push_back(memory_scope::device);
78  if (bits & PI_MEMORY_SCOPE_SYSTEM)
79  result.push_back(memory_scope::system);
80  return result;
81 }
82 
83 #ifndef __SYCL_DEVICE_ONLY__
85  switch (order) {
89  return std::memory_order_consume;
98  }
99  // Return default value here to avoid compiler warnings.
100  // default case in switch doesn't help because some compiler warn about
101  // having a default case while all values of enum are handled.
103 }
104 #endif // __SYCL_DEVICE_ONLY__
105 
106 } // namespace detail
107 } // namespace _V1
108 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
std::vector< memory_scope > readMemoryScopeBitfield(pi_memory_scope_capabilities bits)
std::vector< memory_order > readMemoryOrderBitfield(pi_memory_order_capabilities bits)
std::memory_order getStdMemoryOrder(__spv::MemorySemanticsMask::Flag)
Definition: atomic.hpp:82
constexpr auto memory_scope_work_group
constexpr auto memory_scope_sub_group
constexpr auto memory_order_release
constexpr auto memory_order_relaxed
constexpr auto memory_order_acq_rel
constexpr auto memory_scope_system
constexpr auto memory_scope_device
constexpr auto memory_order_seq_cst
constexpr auto memory_order_acquire
constexpr auto memory_scope_work_item
Definition: access.hpp:18
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_WORK_GROUP
Definition: pi.h:819
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_WORK_ITEM
Definition: pi.h:817
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_ACQUIRE
Definition: pi.h:811
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_ACQ_REL
Definition: pi.h:813
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_RELEASE
Definition: pi.h:812
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_RELAXED
Definition: pi.h:810
pi_bitfield pi_memory_scope_capabilities
Definition: pi.h:816
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_DEVICE
Definition: pi.h:820
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_SYSTEM
Definition: pi.h:821
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_SUB_GROUP
Definition: pi.h:818
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_SEQ_CST
Definition: pi.h:814
pi_bitfield pi_memory_order_capabilities
Definition: pi.h:809