Skip to content

Commit a5f2fda

Browse files
Fznamznonbader
authored andcommitted
[SYCL] Use SPIRV-friendly built-in naming scheme
This change allows to avoid re-flower pass using. Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent 7db9ce8 commit a5f2fda

File tree

17 files changed

+713
-697
lines changed

17 files changed

+713
-697
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static void buildArgTys(ASTContext &Context, CXXRecordDecl *KernelObj,
815815
assert(InitMethod && "sampler must have __init method");
816816

817817
// sampler __init method has only one parameter
818-
// void __init(__spirv::OpTypeSampler *Sampler)
818+
// void __init(__ocl_sampler_t *Sampler)
819819
auto *FuncDecl = cast<FunctionDecl>(InitMethod);
820820
ParmVarDecl *SamplerArg = FuncDecl->getParamDecl(0);
821821
assert(SamplerArg && "sampler __init method must have sampler parameter");
@@ -918,7 +918,7 @@ static void populateIntHeader(SYCLIntegrationHeader &H, const StringRef Name,
918918
assert(InitMethod && "sampler must have __init method");
919919

920920
// sampler __init method has only one argument
921-
// void __init(__spirv::OpTypeSampler *Sampler)
921+
// void __init(__ocl_sampler_t *Sampler)
922922
auto *FuncDecl = cast<FunctionDecl>(InitMethod);
923923
ParmVarDecl *SamplerArg = FuncDecl->getParamDecl(0);
924924
assert(SamplerArg && "sampler __init method must have sampler parameter");

sycl/include/CL/__spirv/spirv_ops.hpp

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,59 @@
1212
#include <cstdint>
1313
#include <type_traits>
1414

15-
namespace cl {
16-
namespace __spirv {
17-
1815
#ifdef __SYCL_DEVICE_ONLY__
19-
2016
template <typename dataT>
21-
extern OpTypeEvent *
22-
OpGroupAsyncCopy(int32_t Scope, __local dataT *Dest, __global dataT *Src,
23-
size_t NumElements, size_t Stride, OpTypeEvent *E) noexcept;
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;
2421

2522
template <typename dataT>
26-
extern OpTypeEvent *
27-
OpGroupAsyncCopy(int32_t Scope, __global dataT *Dest, __local dataT *Src,
28-
size_t NumElements, size_t Stride, OpTypeEvent *E) noexcept;
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;
2927

30-
#define OpGroupAsyncCopyGlobalToLocal OpGroupAsyncCopy
31-
#define OpGroupAsyncCopyLocalToGlobal OpGroupAsyncCopy
28+
#define OpGroupAsyncCopyGlobalToLocal __spirv_GroupAsyncCopy
29+
#define OpGroupAsyncCopyLocalToGlobal __spirv_GroupAsyncCopy
3230

3331
// Atomic SPIR-V builtins
3432
#define __SPIRV_ATOMIC_LOAD(AS, Type) \
35-
extern Type OpAtomicLoad(AS const Type *P, Scope S, MemorySemantics O);
33+
extern Type __spirv_AtomicLoad(AS const Type *P, Scope S, MemorySemantics O);
3634
#define __SPIRV_ATOMIC_STORE(AS, Type) \
37-
extern void OpAtomicStore(AS Type *P, Scope S, MemorySemantics O, Type V);
35+
extern void __spirv_AtomicStore(AS Type *P, Scope S, MemorySemantics O, \
36+
Type V);
3837
#define __SPIRV_ATOMIC_EXCHANGE(AS, Type) \
39-
extern Type OpAtomicExchange(AS Type *P, Scope S, MemorySemantics O, Type V);
38+
extern Type __spirv_AtomicExchange(AS Type *P, Scope S, MemorySemantics O, \
39+
Type V);
4040
#define __SPIRV_ATOMIC_CMP_EXCHANGE(AS, Type) \
41-
extern Type OpAtomicCompareExchange(AS Type *P, Scope S, MemorySemantics E, \
42-
MemorySemantics U, Type V, Type C);
41+
extern Type __spirv_AtomicCompareExchange( \
42+
AS Type *P, Scope S, MemorySemantics E, MemorySemantics U, Type V, \
43+
Type C);
4344
#define __SPIRV_ATOMIC_IADD(AS, Type) \
44-
extern Type OpAtomicIAdd(AS Type *P, Scope S, MemorySemantics O, Type V);
45+
extern Type __spirv_AtomicIAdd(AS Type *P, Scope S, MemorySemantics O, \
46+
Type V);
4547
#define __SPIRV_ATOMIC_ISUB(AS, Type) \
46-
extern Type OpAtomicISub(AS Type *P, Scope S, MemorySemantics O, Type V);
48+
extern Type __spirv_AtomicISub(AS Type *P, Scope S, MemorySemantics O, \
49+
Type V);
4750
#define __SPIRV_ATOMIC_SMIN(AS, Type) \
48-
extern Type OpAtomicSMin(AS Type *P, Scope S, MemorySemantics O, Type V);
51+
extern Type __spirv_AtomicSMin(AS Type *P, Scope S, MemorySemantics O, \
52+
Type V);
4953
#define __SPIRV_ATOMIC_UMIN(AS, Type) \
50-
extern Type OpAtomicUMin(AS Type *P, Scope S, MemorySemantics O, Type V);
54+
extern Type __spirv_AtomicUMin(AS Type *P, Scope S, MemorySemantics O, \
55+
Type V);
5156
#define __SPIRV_ATOMIC_SMAX(AS, Type) \
52-
extern Type OpAtomicSMax(AS Type *P, Scope S, MemorySemantics O, Type V);
57+
extern Type __spirv_AtomicSMax(AS Type *P, Scope S, MemorySemantics O, \
58+
Type V);
5359
#define __SPIRV_ATOMIC_UMAX(AS, Type) \
54-
extern Type OpAtomicUMax(AS Type *P, Scope S, MemorySemantics O, Type V);
60+
extern Type __spirv_AtomicUMax(AS Type *P, Scope S, MemorySemantics O, \
61+
Type V);
5562
#define __SPIRV_ATOMIC_AND(AS, Type) \
56-
extern Type OpAtomicAnd(AS Type *P, Scope S, MemorySemantics O, Type V);
63+
extern Type __spirv_AtomicAnd(AS Type *P, Scope S, MemorySemantics O, Type V);
5764
#define __SPIRV_ATOMIC_OR(AS, Type) \
58-
extern Type OpAtomicOr(AS Type *P, Scope S, MemorySemantics O, Type V);
65+
extern Type __spirv_AtomicOr(AS Type *P, Scope S, MemorySemantics O, Type V);
5966
#define __SPIRV_ATOMIC_XOR(AS, Type) \
60-
extern Type OpAtomicXor(AS Type *P, Scope S, MemorySemantics O, Type V);
67+
extern Type __spirv_AtomicXor(AS Type *P, Scope S, MemorySemantics O, Type V);
6168

6269
#define __SPIRV_ATOMIC_FLOAT(AS, Type) \
6370
__SPIRV_ATOMIC_LOAD(AS, Type) \
@@ -87,14 +94,16 @@ OpGroupAsyncCopy(int32_t Scope, __global dataT *Dest, __local dataT *Src,
8794
// of atomic min/max based on the signed-ness of the type
8895
#define __SPIRV_ATOMIC_MINMAX(AS, Op) \
8996
template <typename T> \
90-
typename std::enable_if<std::is_signed<T>::value, T>::type OpAtomic##Op( \
91-
AS T *Ptr, Scope Scope, MemorySemantics Semantics, T Value) { \
92-
return OpAtomicS##Op(Ptr, Scope, Semantics, Value); \
97+
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); \
93101
} \
94102
template <typename T> \
95-
typename std::enable_if<!std::is_signed<T>::value, T>::type OpAtomic##Op( \
96-
AS T *Ptr, Scope Scope, MemorySemantics Semantics, T Value) { \
97-
return OpAtomicU##Op(Ptr, Scope, Semantics, Value); \
103+
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); \
98107
}
99108

100109
#define __SPIRV_ATOMICS(macro, Arg) macro(__global, Arg) macro(__local, Arg)
@@ -109,64 +118,69 @@ __SPIRV_ATOMICS(__SPIRV_ATOMIC_UNSIGNED, unsigned long long)
109118
__SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Min)
110119
__SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Max)
111120

112-
extern bool OpGroupAll(int32_t Scope, bool Predicate) noexcept;
121+
extern bool __spirv_GroupAll(int32_t Scope, bool Predicate) noexcept;
113122

114-
extern bool OpGroupAny(int32_t Scope, bool Predicate) noexcept;
123+
extern bool __spirv_GroupAny(int32_t Scope, bool Predicate) noexcept;
115124

116125
template <typename dataT>
117-
extern dataT OpGroupBroadcast(int32_t Scope, dataT Value,
118-
uint32_t LocalId) noexcept;
126+
extern dataT __spirv_GroupBroadcast(int32_t Scope, dataT Value,
127+
uint32_t LocalId) noexcept;
119128

120129
template <typename dataT>
121-
extern dataT OpGroupIAdd(int32_t Scope, int32_t Op, dataT Value) noexcept;
130+
extern dataT __spirv_GroupIAdd(int32_t Scope, int32_t Op, dataT Value) noexcept;
122131
template <typename dataT>
123-
extern dataT OpGroupFAdd(int32_t Scope, int32_t Op, dataT Value) noexcept;
132+
extern dataT __spirv_GroupFAdd(int32_t Scope, int32_t Op, dataT Value) noexcept;
124133
template <typename dataT>
125-
extern dataT OpGroupUMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
134+
extern dataT __spirv_GroupUMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
126135
template <typename dataT>
127-
extern dataT OpGroupSMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
136+
extern dataT __spirv_GroupSMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
128137
template <typename dataT>
129-
extern dataT OpGroupFMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
138+
extern dataT __spirv_GroupFMin(int32_t Scope, int32_t Op, dataT Value) noexcept;
130139
template <typename dataT>
131-
extern dataT OpGroupUMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
140+
extern dataT __spirv_GroupUMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
132141
template <typename dataT>
133-
extern dataT OpGroupSMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
142+
extern dataT __spirv_GroupSMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
134143
template <typename dataT>
135-
extern dataT OpGroupFMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
144+
extern dataT __spirv_GroupFMax(int32_t Scope, int32_t Op, dataT Value) noexcept;
136145
template <typename dataT>
137-
extern dataT OpSubgroupShuffleINTEL(dataT Data, uint32_t InvocationId) noexcept;
146+
extern dataT __spirv_SubgroupShuffleINTEL(dataT Data,
147+
uint32_t InvocationId) noexcept;
138148
template <typename dataT>
139-
extern dataT OpSubgroupShuffleDownINTEL(dataT Current, dataT Next,
140-
uint32_t Delta) noexcept;
149+
extern dataT __spirv_SubgroupShuffleDownINTEL(dataT Current, dataT Next,
150+
uint32_t Delta) noexcept;
141151
template <typename dataT>
142-
extern dataT OpSubgroupShuffleUpINTEL(dataT Previous, dataT Current,
143-
uint32_t Delta) noexcept;
152+
extern dataT __spirv_SubgroupShuffleUpINTEL(dataT Previous, dataT Current,
153+
uint32_t Delta) noexcept;
144154
template <typename dataT>
145-
extern dataT OpSubgroupShuffleXorINTEL(dataT Data, uint32_t Value) noexcept;
155+
extern dataT __spirv_SubgroupShuffleXorINTEL(dataT Data,
156+
uint32_t Value) noexcept;
146157

147158
template <typename dataT>
148-
extern dataT OpSubgroupBlockReadINTEL(const __global uint16_t *Ptr) noexcept;
159+
extern dataT
160+
__spirv_SubgroupBlockReadINTEL(const __global uint16_t *Ptr) noexcept;
149161

150162
template <typename dataT>
151-
extern void OpSubgroupBlockWriteINTEL(__global uint16_t *Ptr,
152-
dataT Data) noexcept;
163+
extern void __spirv_SubgroupBlockWriteINTEL(__global uint16_t *Ptr,
164+
dataT Data) noexcept;
153165

154166
template <typename dataT>
155-
extern dataT OpSubgroupBlockReadINTEL(const __global uint32_t *Ptr) noexcept;
167+
extern dataT
168+
__spirv_SubgroupBlockReadINTEL(const __global uint32_t *Ptr) noexcept;
156169

157170
template <typename dataT>
158-
extern void OpSubgroupBlockWriteINTEL(__global uint32_t *Ptr,
159-
dataT Data) noexcept;
171+
extern void __spirv_SubgroupBlockWriteINTEL(__global uint32_t *Ptr,
172+
dataT Data) noexcept;
160173

161-
extern void prefetch(const __global char *Ptr, size_t NumBytes) noexcept;
174+
extern void __spirv_ocl_prefetch(const __global char *Ptr,
175+
size_t NumBytes) noexcept;
162176

163177
#else // if !__SYCL_DEVICE_ONLY__
164178

165179
template <typename dataT>
166-
extern OpTypeEvent *
180+
extern __ocl_event_t
167181
OpGroupAsyncCopyGlobalToLocal(int32_t Scope, dataT *Dest, dataT *Src,
168182
size_t NumElements, size_t Stride,
169-
OpTypeEvent *E) noexcept {
183+
__ocl_event_t E) noexcept {
170184
for (int i = 0; i < NumElements; i++) {
171185
Dest[i] = Src[i * Stride];
172186
}
@@ -175,28 +189,26 @@ OpGroupAsyncCopyGlobalToLocal(int32_t Scope, dataT *Dest, dataT *Src,
175189
}
176190

177191
template <typename dataT>
178-
extern OpTypeEvent *
192+
extern __ocl_event_t
179193
OpGroupAsyncCopyLocalToGlobal(int32_t Scope, dataT *Dest, dataT *Src,
180194
size_t NumElements, size_t Stride,
181-
OpTypeEvent *E) noexcept {
195+
__ocl_event_t E) noexcept {
182196
for (int i = 0; i < NumElements; i++) {
183197
Dest[i * Stride] = Src[i];
184198
}
185199
// A real instance of the class is not needed, return dummy pointer.
186200
return nullptr;
187201
}
188202

189-
extern void prefetch(const char *Ptr, size_t NumBytes) noexcept;
203+
extern void __spirv_ocl_prefetch(const char *Ptr, size_t NumBytes) noexcept;
190204

191205
#endif // !__SYCL_DEVICE_ONLY__
192206

193-
extern void OpControlBarrier(Scope Execution, Scope Memory,
194-
uint32_t Semantics) noexcept;
207+
extern void __spirv_ControlBarrier(Scope Execution, Scope Memory,
208+
uint32_t Semantics) noexcept;
195209

196-
extern void OpMemoryBarrier(Scope Memory, uint32_t Semantics) noexcept;
210+
extern void __spirv_MemoryBarrier(Scope Memory, uint32_t Semantics) noexcept;
197211

198-
extern void OpGroupWaitEvents(int32_t Scope, uint32_t NumEvents,
199-
OpTypeEvent ** WaitEvents) noexcept;
212+
extern void __spirv_GroupWaitEvents(int32_t Scope, uint32_t NumEvents,
213+
__ocl_event_t *WaitEvents) noexcept;
200214

201-
} // namespace __spirv
202-
} // namespace cl

sycl/include/CL/__spirv/spirv_types.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010

1111
#include <cstdint>
1212

13-
namespace cl {
14-
namespace __spirv {
15-
1613
// TODO: include the header file with SPIR-V declarations from SPIRV-Headers
1714
// project.
15+
1816
enum Scope {
1917
CrossDevice = 0,
2018
Device = 1,
@@ -23,6 +21,7 @@ enum Scope {
2321
Invocation = 4,
2422
};
2523

24+
2625
enum MemorySemantics {
2726
None = 0x0,
2827
Acquire = 0x2,
@@ -40,12 +39,10 @@ enum MemorySemantics {
4039
// This class does not have definition, it is only predeclared here.
4140
// The pointers to this class objects can be passed to or returned from
4241
// SPIRV built-in functions.
43-
// Only in such cases the class is recognized as SPIRV type OpTypeEvent.
44-
class OpTypeEvent;
45-
46-
// SPIRV type for sampler class
47-
class OpTypeSampler;
42+
// Only in such cases the class is recognized as SPIRV type __ocl_event_t.
43+
#ifndef __SYCL_DEVICE_ONLY__
44+
typedef void* __ocl_event_t;
45+
typedef void* __ocl_sampler_t;
46+
#endif
4847

4948
enum GroupOperation { Reduce = 0, InclusiveScan = 1, ExclusiveScan = 2 };
50-
} // namespace __spirv
51-
} // namespace cl

sycl/include/CL/__spirv/spirv_vars.hpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@
1010

1111
#ifdef __SYCL_DEVICE_ONLY__
1212

13-
namespace cl {
14-
namespace __spirv {
1513
typedef size_t size_t_vec __attribute__((ext_vector_type(3)));
16-
17-
extern const __constant size_t_vec VarGlobalSize;
18-
extern const __constant size_t_vec VarGlobalInvocationId;
19-
extern const __constant size_t_vec VarWorkgroupSize;
20-
extern const __constant size_t_vec VarLocalInvocationId;
21-
extern const __constant size_t_vec VarWorkgroupId;
22-
extern const __constant size_t_vec VarGlobalOffset;
14+
extern "C" const __constant size_t_vec __spirv_BuiltInGlobalSize;
15+
extern "C" const __constant size_t_vec __spirv_BuiltInGlobalInvocationId;
16+
extern "C" const __constant size_t_vec __spirv_BuiltInWorkgroupSize;
17+
extern "C" const __constant size_t_vec __spirv_BuiltInLocalInvocationId;
18+
extern "C" const __constant size_t_vec __spirv_BuiltInWorkgroupId;
19+
extern "C" const __constant size_t_vec __spirv_BuiltInGlobalOffset;
2320

2421
#define DEFINE_INT_ID_TO_XYZ_CONVERTER(POSTFIX) \
2522
template <int ID> static size_t get##POSTFIX(); \
26-
template <> size_t get##POSTFIX<0>() { return Var##POSTFIX.x; } \
27-
template <> size_t get##POSTFIX<1>() { return Var##POSTFIX.y; } \
28-
template <> size_t get##POSTFIX<2>() { return Var##POSTFIX.z; }
23+
template <> size_t get##POSTFIX<0>() { return __spirv_BuiltIn##POSTFIX.x; } \
24+
template <> size_t get##POSTFIX<1>() { return __spirv_BuiltIn##POSTFIX.y; } \
25+
template <> size_t get##POSTFIX<2>() { return __spirv_BuiltIn##POSTFIX.z; }
2926

3027
DEFINE_INT_ID_TO_XYZ_CONVERTER(GlobalSize);
3128
DEFINE_INT_ID_TO_XYZ_CONVERTER(GlobalInvocationId)
@@ -36,13 +33,11 @@ DEFINE_INT_ID_TO_XYZ_CONVERTER(GlobalOffset)
3633

3734
#undef DEFINE_INT_ID_TO_XYZ_CONVERTER
3835

39-
extern const __constant uint32_t VarSubgroupSize;
40-
extern const __constant uint32_t VarSubgroupMaxSize;
41-
extern const __constant uint32_t VarNumSubgroups;
42-
extern const __constant uint32_t VarNumEnqueuedSubgroups;
43-
extern const __constant uint32_t VarSubgroupId;
44-
extern const __constant uint32_t VarSubgroupLocalInvocationId;
36+
extern "C" const __constant uint32_t __spirv_BuiltInSubgroupSize;
37+
extern "C" const __constant uint32_t __spirv_BuiltInSubgroupMaxSize;
38+
extern "C" const __constant uint32_t __spirv_BuiltInNumSubgroups;
39+
extern "C" const __constant uint32_t __spirv_BuiltInNumEnqueuedSubgroups;
40+
extern "C" const __constant uint32_t __spirv_BuiltInSubgroupId;
41+
extern "C" const __constant uint32_t __spirv_BuiltInSubgroupLocalInvocationId;
4542

46-
} // namespace __spirv
47-
} // namespace cl
4843
#endif // __SYCL_DEVICE_ONLY__

0 commit comments

Comments
 (0)