Skip to content

Commit 4c58035

Browse files
AlexeySachkovbader
authored andcommitted
[SYCL] Avoid declaring unscoped enums in global namespace
According to C++ spec: Each enumerator becomes a named constant of the enumeration's type (that is, name), visible in the enclosing scope, and can be used whenever constants are required. Having unscoped enumerations defined in global namespace reserve some names and prohibits it's using in user's applications. For example, 'Device' might be used as user's class name and it might cause ambiguity. This patch aligns declaration of enums in spirv_types.hpp with ones from SPIRV-Headers project to avoid declaring identifiers in global namespace and simplify transition in the future. There are few exceptions: * uint32_t is used as base type for enum instead of unsigned. * '__spv' namespace is used instead of 'spv'. Signed-off-by: Alexey Sachkov <[email protected]>
1 parent 07358ac commit 4c58035

File tree

10 files changed

+210
-137
lines changed

10 files changed

+210
-137
lines changed

sycl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ else()
8282
add_custom_target(ocl-icd DEPENDS ${OpenCL_LIBRARIES} COMMENT "Copying OpenCL ICD Loader ...")
8383
endif()
8484

85-
set(SYCL_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/include/")
85+
set(SYCL_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include/")
8686
set(OPENCL_INCLUDE "${OpenCL_INCLUDE_DIRS}")
8787

8888
# Configure SYCL version macro

sycl/include/CL/__spirv/spirv_ops.hpp

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,61 @@
1414

1515
#ifdef __SYCL_DEVICE_ONLY__
1616
template <typename dataT>
17-
extern __ocl_event_t __spirv_GroupAsyncCopy(int32_t Scope, __local dataT *Dest,
18-
__global dataT *Src,
19-
size_t NumElements, size_t Stride,
20-
__ocl_event_t E) noexcept;
17+
extern __ocl_event_t
18+
__spirv_GroupAsyncCopy(__spv::Scope Execution, __local dataT *Dest,
19+
__global dataT *Src, size_t NumElements, size_t Stride,
20+
__ocl_event_t E) noexcept;
2121

2222
template <typename dataT>
23-
extern __ocl_event_t __spirv_GroupAsyncCopy(int32_t Scope, __global dataT *Dest,
24-
__local dataT *Src,
25-
size_t NumElements, size_t Stride,
26-
__ocl_event_t E) noexcept;
23+
extern __ocl_event_t
24+
__spirv_GroupAsyncCopy(__spv::Scope Execution, __global dataT *Dest,
25+
__local dataT *Src, size_t NumElements, size_t Stride,
26+
__ocl_event_t E) noexcept;
2727

2828
#define OpGroupAsyncCopyGlobalToLocal __spirv_GroupAsyncCopy
2929
#define OpGroupAsyncCopyLocalToGlobal __spirv_GroupAsyncCopy
3030

3131
// Atomic SPIR-V builtins
3232
#define __SPIRV_ATOMIC_LOAD(AS, Type) \
33-
extern Type __spirv_AtomicLoad(AS const Type *P, Scope S, MemorySemantics O);
33+
extern Type __spirv_AtomicLoad(AS const Type *P, __spv::Scope S, \
34+
__spv::MemorySemanticsMask O);
3435
#define __SPIRV_ATOMIC_STORE(AS, Type) \
35-
extern void __spirv_AtomicStore(AS Type *P, Scope S, MemorySemantics O, \
36-
Type V);
36+
extern void __spirv_AtomicStore(AS Type *P, __spv::Scope S, \
37+
__spv::MemorySemanticsMask O, Type V);
3738
#define __SPIRV_ATOMIC_EXCHANGE(AS, Type) \
38-
extern Type __spirv_AtomicExchange(AS Type *P, Scope S, MemorySemantics O, \
39-
Type V);
39+
extern Type __spirv_AtomicExchange(AS Type *P, __spv::Scope S, \
40+
__spv::MemorySemanticsMask O, Type V);
4041
#define __SPIRV_ATOMIC_CMP_EXCHANGE(AS, Type) \
4142
extern Type __spirv_AtomicCompareExchange( \
42-
AS Type *P, Scope S, MemorySemantics E, MemorySemantics U, Type V, \
43-
Type C);
43+
AS Type *P, __spv::Scope S, __spv::MemorySemanticsMask E, \
44+
__spv::MemorySemanticsMask U, Type V, Type C);
4445
#define __SPIRV_ATOMIC_IADD(AS, Type) \
45-
extern Type __spirv_AtomicIAdd(AS Type *P, Scope S, MemorySemantics O, \
46-
Type V);
46+
extern Type __spirv_AtomicIAdd(AS Type *P, __spv::Scope S, \
47+
__spv::MemorySemanticsMask O, Type V);
4748
#define __SPIRV_ATOMIC_ISUB(AS, Type) \
48-
extern Type __spirv_AtomicISub(AS Type *P, Scope S, MemorySemantics O, \
49-
Type V);
49+
extern Type __spirv_AtomicISub(AS Type *P, __spv::Scope S, \
50+
__spv::MemorySemanticsMask O, Type V);
5051
#define __SPIRV_ATOMIC_SMIN(AS, Type) \
51-
extern Type __spirv_AtomicSMin(AS Type *P, Scope S, MemorySemantics O, \
52-
Type V);
52+
extern Type __spirv_AtomicSMin(AS Type *P, __spv::Scope S, \
53+
__spv::MemorySemanticsMask O, Type V);
5354
#define __SPIRV_ATOMIC_UMIN(AS, Type) \
54-
extern Type __spirv_AtomicUMin(AS Type *P, Scope S, MemorySemantics O, \
55-
Type V);
55+
extern Type __spirv_AtomicUMin(AS Type *P, __spv::Scope S, \
56+
__spv::MemorySemanticsMask O, Type V);
5657
#define __SPIRV_ATOMIC_SMAX(AS, Type) \
57-
extern Type __spirv_AtomicSMax(AS Type *P, Scope S, MemorySemantics O, \
58-
Type V);
58+
extern Type __spirv_AtomicSMax(AS Type *P, __spv::Scope S, \
59+
__spv::MemorySemanticsMask O, Type V);
5960
#define __SPIRV_ATOMIC_UMAX(AS, Type) \
60-
extern Type __spirv_AtomicUMax(AS Type *P, Scope S, MemorySemantics O, \
61-
Type V);
61+
extern Type __spirv_AtomicUMax(AS Type *P, __spv::Scope S, \
62+
__spv::MemorySemanticsMask O, Type V);
6263
#define __SPIRV_ATOMIC_AND(AS, Type) \
63-
extern Type __spirv_AtomicAnd(AS Type *P, Scope S, MemorySemantics O, Type V);
64+
extern Type __spirv_AtomicAnd(AS Type *P, __spv::Scope S, \
65+
__spv::MemorySemanticsMask O, Type V);
6466
#define __SPIRV_ATOMIC_OR(AS, Type) \
65-
extern Type __spirv_AtomicOr(AS Type *P, Scope S, MemorySemantics O, Type V);
67+
extern Type __spirv_AtomicOr(AS Type *P, __spv::Scope S, \
68+
__spv::MemorySemanticsMask O, Type V);
6669
#define __SPIRV_ATOMIC_XOR(AS, Type) \
67-
extern Type __spirv_AtomicXor(AS Type *P, Scope S, MemorySemantics O, Type V);
70+
extern Type __spirv_AtomicXor(AS Type *P, __spv::Scope S, \
71+
__spv::MemorySemanticsMask O, Type V);
6872

6973
#define __SPIRV_ATOMIC_FLOAT(AS, Type) \
7074
__SPIRV_ATOMIC_LOAD(AS, Type) \
@@ -95,15 +99,15 @@ extern __ocl_event_t __spirv_GroupAsyncCopy(int32_t Scope, __global dataT *Dest,
9599
#define __SPIRV_ATOMIC_MINMAX(AS, Op) \
96100
template <typename T> \
97101
typename std::enable_if<std::is_signed<T>::value, T>::type \
98-
__spirv_Atomic##Op(AS T *Ptr, Scope Scope, MemorySemantics Semantics, \
99-
T Value) { \
100-
return __spirv_AtomicS##Op(Ptr, Scope, Semantics, Value); \
102+
__spirv_Atomic##Op(AS T *Ptr, __spv::Scope Memory, \
103+
__spv::MemorySemanticsMask Semantics, T Value) { \
104+
return __spirv_AtomicS##Op(Ptr, Memory, Semantics, Value); \
101105
} \
102106
template <typename T> \
103107
typename std::enable_if<!std::is_signed<T>::value, T>::type \
104-
__spirv_Atomic##Op(AS T *Ptr, Scope Scope, MemorySemantics Semantics, \
105-
T Value) { \
106-
return __spirv_AtomicU##Op(Ptr, Scope, Semantics, Value); \
108+
__spirv_Atomic##Op(AS T *Ptr, __spv::Scope Memory, \
109+
__spv::MemorySemanticsMask Semantics, T Value) { \
110+
return __spirv_AtomicU##Op(Ptr, Memory, Semantics, Value); \
107111
}
108112

109113
#define __SPIRV_ATOMICS(macro, Arg) macro(__global, Arg) macro(__local, Arg)
@@ -118,30 +122,38 @@ __SPIRV_ATOMICS(__SPIRV_ATOMIC_UNSIGNED, unsigned long long)
118122
__SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Min)
119123
__SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Max)
120124

121-
extern bool __spirv_GroupAll(int32_t Scope, bool Predicate) noexcept;
125+
extern bool __spirv_GroupAll(__spv::Scope Execution, bool Predicate) noexcept;
122126

123-
extern bool __spirv_GroupAny(int32_t Scope, bool Predicate) noexcept;
127+
extern bool __spirv_GroupAny(__spv::Scope Execution, bool Predicate) noexcept;
124128

125129
template <typename dataT>
126-
extern dataT __spirv_GroupBroadcast(int32_t Scope, dataT Value,
130+
extern dataT __spirv_GroupBroadcast(__spv::Scope Execution, dataT Value,
127131
uint32_t LocalId) noexcept;
128132

129133
template <typename dataT>
130-
extern dataT __spirv_GroupIAdd(int32_t Scope, int32_t Op, dataT Value) noexcept;
134+
extern dataT __spirv_GroupIAdd(__spv::Scope Execution, __spv::GroupOperation Op,
135+
dataT Value) noexcept;
131136
template <typename dataT>
132-
extern dataT __spirv_GroupFAdd(int32_t Scope, int32_t Op, dataT Value) noexcept;
137+
extern dataT __spirv_GroupFAdd(__spv::Scope Execution, __spv::GroupOperation Op,
138+
dataT Value) noexcept;
133139
template <typename dataT>
134-
extern dataT __spirv_GroupUMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
140+
extern dataT __spirv_GroupUMin(__spv::Scope Execution, __spv::GroupOperation Op,
141+
dataT Value) noexcept;
135142
template <typename dataT>
136-
extern dataT __spirv_GroupSMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
143+
extern dataT __spirv_GroupSMin(__spv::Scope Execution, __spv::GroupOperation Op,
144+
dataT Value) noexcept;
137145
template <typename dataT>
138-
extern dataT __spirv_GroupFMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
146+
extern dataT __spirv_GroupFMin(__spv::Scope Execution, __spv::GroupOperation Op,
147+
dataT Value) noexcept;
139148
template <typename dataT>
140-
extern dataT __spirv_GroupUMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
149+
extern dataT __spirv_GroupUMax(__spv::Scope Execution, __spv::GroupOperation Op,
150+
dataT Value) noexcept;
141151
template <typename dataT>
142-
extern dataT __spirv_GroupSMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
152+
extern dataT __spirv_GroupSMax(__spv::Scope Execution, __spv::GroupOperation Op,
153+
dataT Value) noexcept;
143154
template <typename dataT>
144-
extern dataT __spirv_GroupFMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
155+
extern dataT __spirv_GroupFMax(__spv::Scope Execution, __spv::GroupOperation Op,
156+
dataT Value) noexcept;
145157
template <typename dataT>
146158
extern dataT __spirv_SubgroupShuffleINTEL(dataT Data,
147159
uint32_t InvocationId) noexcept;
@@ -178,7 +190,7 @@ extern void __spirv_ocl_prefetch(const __global char *Ptr,
178190

179191
template <typename dataT>
180192
extern __ocl_event_t
181-
OpGroupAsyncCopyGlobalToLocal(int32_t Scope, dataT *Dest, dataT *Src,
193+
OpGroupAsyncCopyGlobalToLocal(__spv::Scope Execution, dataT *Dest, dataT *Src,
182194
size_t NumElements, size_t Stride,
183195
__ocl_event_t E) noexcept {
184196
for (int i = 0; i < NumElements; i++) {
@@ -190,7 +202,7 @@ OpGroupAsyncCopyGlobalToLocal(int32_t Scope, dataT *Dest, dataT *Src,
190202

191203
template <typename dataT>
192204
extern __ocl_event_t
193-
OpGroupAsyncCopyLocalToGlobal(int32_t Scope, dataT *Dest, dataT *Src,
205+
OpGroupAsyncCopyLocalToGlobal(__spv::Scope Execution, dataT *Dest, dataT *Src,
194206
size_t NumElements, size_t Stride,
195207
__ocl_event_t E) noexcept {
196208
for (int i = 0; i < NumElements; i++) {
@@ -204,11 +216,12 @@ extern void __spirv_ocl_prefetch(const char *Ptr, size_t NumBytes) noexcept;
204216

205217
#endif // !__SYCL_DEVICE_ONLY__
206218

207-
extern void __spirv_ControlBarrier(Scope Execution, Scope Memory,
219+
extern void __spirv_ControlBarrier(__spv::Scope Execution, __spv::Scope Memory,
208220
uint32_t Semantics) noexcept;
209221

210-
extern void __spirv_MemoryBarrier(Scope Memory, uint32_t Semantics) noexcept;
222+
extern void __spirv_MemoryBarrier(__spv::Scope Memory,
223+
uint32_t Semantics) noexcept;
211224

212-
extern void __spirv_GroupWaitEvents(int32_t Scope, uint32_t NumEvents,
225+
extern void __spirv_GroupWaitEvents(__spv::Scope Execution, uint32_t NumEvents,
213226
__ocl_event_t *WaitEvents) noexcept;
214227

sycl/include/CL/__spirv/spirv_types.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
// TODO: include the header file with SPIR-V declarations from SPIRV-Headers
1414
// project.
1515

16-
enum Scope {
16+
// Declarations of enums below is aligned with corresponding declarations in
17+
// SPIRV-Headers repo with a few exceptions:
18+
// - base types changed from uint to uint32_t
19+
// - spv namespace renamed to __spv
20+
namespace __spv {
21+
22+
enum class Scope : uint32_t {
1723
CrossDevice = 0,
1824
Device = 1,
1925
Workgroup = 2,
@@ -22,7 +28,7 @@ enum Scope {
2228
};
2329

2430

25-
enum MemorySemantics {
31+
enum class MemorySemanticsMask : uint32_t {
2632
None = 0x0,
2733
Acquire = 0x2,
2834
Release = 0x4,
@@ -36,6 +42,14 @@ enum MemorySemantics {
3642
ImageMemory = 0x800,
3743
};
3844

45+
enum class GroupOperation : uint32_t {
46+
Reduce = 0,
47+
InclusiveScan = 1,
48+
ExclusiveScan = 2
49+
};
50+
51+
} // namespace __spv
52+
3953
// This class does not have definition, it is only predeclared here.
4054
// The pointers to this class objects can be passed to or returned from
4155
// SPIRV built-in functions.
@@ -44,5 +58,3 @@ enum MemorySemantics {
4458
typedef void* __ocl_event_t;
4559
typedef void* __ocl_sampler_t;
4660
#endif
47-
48-
enum GroupOperation { Reduce = 0, InclusiveScan = 1, ExclusiveScan = 2 };

0 commit comments

Comments
 (0)