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 <ur_api.h> // for ur_memory_order_capability_flags_t
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>
52 readMemoryOrderBitfield(ur_memory_order_capability_flags_t bits) {
53  std::vector<memory_order> result;
54  if (bits & UR_MEMORY_ORDER_CAPABILITY_FLAG_RELAXED)
55  result.push_back(memory_order::relaxed);
56  if (bits & UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQUIRE)
57  result.push_back(memory_order::acquire);
58  if (bits & UR_MEMORY_ORDER_CAPABILITY_FLAG_RELEASE)
59  result.push_back(memory_order::release);
60  if (bits & UR_MEMORY_ORDER_CAPABILITY_FLAG_ACQ_REL)
61  result.push_back(memory_order::acq_rel);
62  if (bits & UR_MEMORY_ORDER_CAPABILITY_FLAG_SEQ_CST)
63  result.push_back(memory_order::seq_cst);
64  return result;
65 }
66 
67 inline std::vector<memory_scope>
68 readMemoryScopeBitfield(ur_memory_scope_capability_flags_t bits) {
69  std::vector<memory_scope> result;
70  if (bits & UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_ITEM)
71  result.push_back(memory_scope::work_item);
72  if (bits & UR_MEMORY_SCOPE_CAPABILITY_FLAG_SUB_GROUP)
73  result.push_back(memory_scope::sub_group);
74  if (bits & UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_GROUP)
75  result.push_back(memory_scope::work_group);
76  if (bits & UR_MEMORY_SCOPE_CAPABILITY_FLAG_DEVICE)
77  result.push_back(memory_scope::device);
78  if (bits & UR_MEMORY_SCOPE_CAPABILITY_FLAG_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(ur_memory_scope_capability_flags_t bits)
std::vector< memory_order > readMemoryOrderBitfield(ur_memory_order_capability_flags_t 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