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 
12 
13 namespace sycl {
15 
16 enum class memory_order : int {
17  relaxed = 0,
18  acquire = 1,
20  2, // helps optimizer when mapping to std::memory_order
21  release = 3,
22  acq_rel = 4,
23  seq_cst = 5
24 };
25 
26 enum class memory_scope : int {
27  work_item = 0,
28  sub_group = 1,
29  work_group = 2,
30  device = 3,
31  system = 4
32 };
33 
34 #if __cplusplus >= 201703L
35 inline constexpr auto memory_scope_work_item = memory_scope::work_item;
36 inline constexpr auto memory_scope_sub_group = memory_scope::sub_group;
37 inline constexpr auto memory_scope_work_group = memory_scope::work_group;
38 inline constexpr auto memory_scope_device = memory_scope::device;
39 inline constexpr auto memory_scope_system = memory_scope::system;
40 
41 inline constexpr auto memory_order_relaxed = memory_order::relaxed;
42 inline constexpr auto memory_order_acquire = memory_order::acquire;
43 inline constexpr auto memory_order_release = memory_order::release;
44 inline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
45 inline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
46 #endif
47 
48 namespace detail {
49 
50 inline std::vector<memory_order>
52  std::vector<memory_order> result;
53  if (bits & PI_MEMORY_ORDER_RELAXED)
54  result.push_back(memory_order::relaxed);
55  if (bits & PI_MEMORY_ORDER_ACQUIRE)
56  result.push_back(memory_order::acquire);
57  if (bits & PI_MEMORY_ORDER_RELEASE)
58  result.push_back(memory_order::release);
59  if (bits & PI_MEMORY_ORDER_ACQ_REL)
60  result.push_back(memory_order::acq_rel);
61  if (bits & PI_MEMORY_ORDER_SEQ_CST)
62  result.push_back(memory_order::seq_cst);
63  return result;
64 }
65 
66 inline std::vector<memory_scope>
68  std::vector<memory_scope> result;
69  if (bits & PI_MEMORY_SCOPE_WORK_ITEM)
70  result.push_back(memory_scope::work_item);
71  if (bits & PI_MEMORY_SCOPE_SUB_GROUP)
72  result.push_back(memory_scope::sub_group);
73  if (bits & PI_MEMORY_SCOPE_WORK_GROUP)
74  result.push_back(memory_scope::work_group);
75  if (bits & PI_MEMORY_SCOPE_DEVICE)
76  result.push_back(memory_scope::device);
77  if (bits & PI_MEMORY_SCOPE_SYSTEM)
78  result.push_back(memory_scope::system);
79  return result;
80 }
81 
82 #ifndef __SYCL_DEVICE_ONLY__
84  switch (order) {
85  case memory_order::relaxed:
86  return std::memory_order_relaxed;
87  case memory_order::__consume_unsupported:
88  return std::memory_order_consume;
89  case memory_order::acquire:
90  return std::memory_order_acquire;
91  case memory_order::release:
92  return std::memory_order_release;
93  case memory_order::acq_rel:
94  return std::memory_order_acq_rel;
95  case memory_order::seq_cst:
96  return std::memory_order_seq_cst;
97  }
98  // Return default value here to avoid compiler warnings.
99  // default case in switch doesn't help because some compiler warn about
100  // having a default case while all values of enum are handled.
101  return std::memory_order_acq_rel;
102 }
103 #endif // __SYCL_DEVICE_ONLY__
104 
105 } // namespace detail
106 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
107 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
#define __SYCL_INLINE_VER_NAMESPACE(X)
std::vector< memory_scope > readMemoryScopeBitfield(pi_memory_scope_capabilities bits)
std::vector< memory_order > readMemoryOrderBitfield(pi_memory_order_capabilities bits)
static constexpr std::memory_order getStdMemoryOrder(sycl::memory_order order)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_WORK_GROUP
Definition: pi.h:529
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_WORK_ITEM
Definition: pi.h:527
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_ACQUIRE
Definition: pi.h:521
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_ACQ_REL
Definition: pi.h:523
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_RELEASE
Definition: pi.h:522
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_RELAXED
Definition: pi.h:520
pi_bitfield pi_memory_scope_capabilities
Definition: pi.h:526
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_DEVICE
Definition: pi.h:530
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_SYSTEM
Definition: pi.h:531
constexpr pi_memory_scope_capabilities PI_MEMORY_SCOPE_SUB_GROUP
Definition: pi.h:528
constexpr pi_memory_order_capabilities PI_MEMORY_ORDER_SEQ_CST
Definition: pi.h:524
pi_bitfield pi_memory_order_capabilities
Definition: pi.h:519