Skip to content

Commit 47f0c4a

Browse files
committed
Merge remote-tracking branch 'remote/sycl' into max-attr-scratch
2 parents af4f734 + d4180f4 commit 47f0c4a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1455
-316
lines changed

.github/workflows/linux_post_commit.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ jobs:
2727
;;
2828
SharedLibs)
2929
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
30-
sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main"
30+
sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main"
3131
sudo apt-get update
32-
sudo apt-get install -y clang-13
32+
sudo apt-get install -y clang-12
3333
export ARGS="--shared-libs"
34-
export CC="clang-13"
35-
export CXX="clang++-13"
34+
export CC="clang-12"
35+
export CXX="clang++-12"
3636
;;
3737
NoAssertions)
3838
export ARGS="--no-assertions"

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ def SYCL : LangOpt<"SYCL">;
337337
def SYCLIsDevice : LangOpt<"SYCLIsDevice">;
338338
def SYCLIsHost : LangOpt<"SYCLIsHost">;
339339
def SilentlyIgnoreSYCLIsHost : LangOpt<"SYCLIsHost", "", 1>;
340-
def SYCLExplicitSIMD : LangOpt<"SYCLExplicitSIMD">;
341340
def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
342341
def CPlusPlus : LangOpt<"CPlusPlus">;
343342
def OpenCL : LangOpt<"OpenCL">;
@@ -1195,7 +1194,6 @@ def SYCLSimd : InheritableAttr {
11951194
let Spellings = [GNU<"sycl_explicit_simd">,
11961195
CXX11<"intel", "sycl_explicit_simd">];
11971196
let Subjects = SubjectList<[Function, GlobalVar]>;
1198-
let LangOpts = [SYCLExplicitSIMD];
11991197
let Documentation = [SYCLSimdDocs];
12001198
let SupportsNonconformingLambdaSyntax = 1;
12011199
}
@@ -1208,7 +1206,6 @@ def SYCLRegisterNum : InheritableAttr {
12081206
let Subjects = SubjectList<[GlobalVar]>;
12091207
// This attribute is applied to file-scope variables and must be compilable
12101208
// for the host device as well
1211-
let LangOpts = [SYCLExplicitSIMD];
12121209
let Documentation = [SYCLRegisterNumDocs];
12131210
}
12141211

@@ -1221,7 +1218,6 @@ def SYCLSimdAccessorPtr : InheritableAttr {
12211218
// No spelling, as this attribute can't be created in the source code.
12221219
let Spellings = [];
12231220
let Subjects = SubjectList<[ParmVar]>;
1224-
let LangOpts = [SYCLExplicitSIMD];
12251221
let Documentation = [Undocumented];
12261222
}
12271223

clang/test/CodeGenSYCL/esimd-accessor-ptr-md.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// separate. So, we can split this test into 2, where one
44
// will be testing code generation and the second ESIMD lowering.
55
//
6-
// RUN: %clang_cc1 -fsycl-explicit-simd -fsycl-is-device \
6+
// RUN: %clang_cc1 -fsycl-is-device \
77
// RUN: -internal-isystem %S/Inputs -triple spir64-unknown-unknown-sycldevice \
88
// RUN: -disable-llvm-passes -emit-llvm %s -o %t
99
// RUN: sycl-post-link -split-esimd -lower-esimd -O0 -S %t -o %t.table

clang/test/CodeGenSYCL/esimd-private-global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// will be testing code generation and the second ESIMD lowering.
55
//
66
// RUN: %clang_cc1 -disable-llvm-passes -triple spir64-unknown-unknown-sycldevice \
7-
// RUN: -fsycl-is-device -fsycl-explicit-simd -emit-llvm %s -o %t
7+
// RUN: -fsycl-is-device -emit-llvm %s -o %t
88
// RUN: sycl-post-link -split-esimd -lower-esimd -O0 -S %t -o %t.table
99
// RUN: FileCheck %s -input-file=%t_esimd_0.ll
1010

clang/test/CodeGenSYCL/esimd_metadata1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -disable-llvm-passes -triple spir64-unknown-unknown-sycldevice \
2-
// RUN: -fsycl-is-device -fsycl-explicit-simd -S -emit-llvm %s -o - | \
2+
// RUN: -fsycl-is-device -S -emit-llvm %s -o - | \
33
// RUN: FileCheck %s
44

55
// The test checks that:

clang/test/CodeGenSYCL/esimd_metadata2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -disable-llvm-passes -triple spir64-unknown-unknown-sycldevice -fsycl-is-device -fsycl-explicit-simd -S -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-ESIMD
1+
// RUN: %clang_cc1 -disable-llvm-passes -triple spir64-unknown-unknown-sycldevice -fsycl-is-device -S -emit-llvm %s -o - | FileCheck %s --check-prefixes CHECK,CHECK-ESIMD
22

33
// This test checks that attribute !intel_reqd_sub_group_size !1
44
// is added for kernels with !sycl_explicit_simd

clang/test/CodeGenSYCL/int_header_esimd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-explicit-simd -fsycl-is-device -internal-isystem %S/Inputs -fsycl-int-header=%t.h %s
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -fsycl-int-header=%t.h %s
22
// RUN: FileCheck -input-file=%t.h %s
33

44
// This test checks that
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -fsycl-explicit-simd -fsyntax-only -verify %s
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
22
// expected-no-diagnostics
33
int x = 0;

clang/test/SemaSYCL/esimd-private-global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -fsycl-explicit-simd -fsyntax-only -verify -pedantic %s
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify -pedantic %s
22

33
// This test checks specifics of semantic analysis of ESIMD private globals
44

clang/test/SemaSYCL/sycl-esimd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -fsycl-explicit-simd -fsyntax-only -Wno-sycl-2017-compat -verify %s
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s
22

33
// This test checks specifics of semantic analysis of ESIMD kernels.
44

sycl/include/CL/sycl/detail/cg.hpp

Lines changed: 134 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,119 @@ namespace sycl {
3636

3737
// Forward declarations
3838
class queue;
39-
namespace detail {
40-
class queue_impl;
41-
} // namespace detail
4239

4340
namespace detail {
4441

42+
// Periodically there is a need to extend handler and CG classes to hold more
43+
// data(members) than it has now. But any modification of the layout of those
44+
// classes is an ABI break. To have an ability to have more data the following
45+
// approach is implemented:
46+
//
47+
// Those classes have a member - MSharedPtrStorage which is an std::vector of
48+
// std::shared_ptr's and is supposed to hold reference counters of user
49+
// provided shared_ptr's.
50+
//
51+
// The first element of this vector is reused to store a vector of additional
52+
// members handler and CG need to have.
53+
//
54+
// These additional arguments are represented using "ExtendedMemberT" structure
55+
// which has a pointer to an arbitrary value and an integer which is used to
56+
// understand how the value the pointer points to should be interpreted.
57+
//
58+
// ======== ======== ========
59+
// | | | | ... | | std::vector<std::shared_ptr<void>>
60+
// ======== ======== ========
61+
// || || ||
62+
// || \/ \/
63+
// || user user
64+
// || data data
65+
// \/
66+
// ======== ======== ========
67+
// | Type | | Type | ... | Type | std::vector<ExtendedMemberT>
68+
// | | | | | |
69+
// | Ptr | | Ptr | ... | Ptr |
70+
// ======== ======== ========
71+
//
72+
// Prior to this change this vector was supposed to have user's values only, so
73+
// it is not legal to expect that the first argument is a special one.
74+
// Versioning is implemented to overcome this problem - if the first element of
75+
// the MSharedPtrStorage is a pointer to the special vector then CGType value
76+
// has version "1" encoded.
77+
//
78+
// The version of CG type is encoded in the highest byte of the value:
79+
//
80+
// 0x00000001 - CG type KERNEL version 0
81+
// 0x01000001 - CG type KERNEL version 1
82+
// /\
83+
// ||
84+
// The byte specifies the version
85+
//
86+
// A user of this vector should not expect that a specific data is stored at a
87+
// specific position, but iterate over all looking for an ExtendedMemberT value
88+
// with the desired type.
89+
// This allows changing/extending the contents of this vector without changing
90+
// the version.
91+
//
92+
93+
// Used to represent a type of an extended member
94+
enum class ExtendedMembersType : unsigned int {
95+
HANDLER_KERNEL_BUNDLE = 0,
96+
};
97+
98+
// Holds a pointer to an object of an arbitrary type and an ID value which
99+
// should be used to understand what type pointer points to.
100+
// Used as to extend handler class without introducing new class members which
101+
// would change handler layout.
102+
struct ExtendedMemberT {
103+
ExtendedMembersType MType;
104+
std::shared_ptr<void> MData;
105+
};
106+
107+
static std::shared_ptr<std::vector<ExtendedMemberT>>
108+
convertToExtendedMembers(const std::shared_ptr<const void> &SPtr) {
109+
return std::const_pointer_cast<std::vector<ExtendedMemberT>>(
110+
std::static_pointer_cast<const std::vector<ExtendedMemberT>>(SPtr));
111+
}
112+
45113
class stream_impl;
114+
class queue_impl;
115+
class kernel_bundle_impl;
116+
117+
// The constant is used to left shift a CG type value to access it's version
118+
constexpr unsigned int ShiftBitsForVersion = 24;
119+
120+
// Constructs versioned type
121+
constexpr unsigned int getVersionedCGType(unsigned int Type,
122+
unsigned char Version) {
123+
return Type | (static_cast<unsigned int>(Version) << ShiftBitsForVersion);
124+
}
125+
126+
// Returns the type without version encoded
127+
constexpr unsigned char getUnversionedCGType(unsigned int Type) {
128+
unsigned int Mask = -1;
129+
Mask >>= (sizeof(Mask) * 8 - ShiftBitsForVersion);
130+
return Type & Mask;
131+
}
132+
133+
// Returns the version encoded to the type
134+
constexpr unsigned char getCGTypeVersion(unsigned int Type) {
135+
return Type >> ShiftBitsForVersion;
136+
}
137+
46138
/// Base class for all types of command groups.
47139
class CG {
48140
public:
141+
// Used to version CG and handler classes. Using unsigned char as the version
142+
// is encoded in the highest byte of CGType value. So it is not possible to
143+
// encode a value > 255 anyway which should be big enough room for version
144+
// bumping.
145+
enum class CG_VERSION : unsigned char {
146+
V0 = 0,
147+
V1 = 1,
148+
};
149+
49150
/// Type of the command group.
50-
enum CGTYPE {
151+
enum CGTYPE : unsigned int {
51152
NONE = 0,
52153
KERNEL = 1,
53154
COPY_ACC_TO_PTR = 2,
@@ -62,7 +163,9 @@ class CG {
62163
FILL_USM = 11,
63164
PREFETCH_USM = 12,
64165
CODEPLAY_INTEROP_TASK = 13,
65-
CODEPLAY_HOST_TASK = 14
166+
CODEPLAY_HOST_TASK = 14,
167+
KERNEL_V1 =
168+
getVersionedCGType(KERNEL, static_cast<unsigned int>(CG_VERSION::V1)),
66169
};
67170

68171
CG(CGTYPE Type, vector_class<vector_class<char>> ArgsStorage,
@@ -87,7 +190,17 @@ class CG {
87190

88191
CG(CG &&CommandGroup) = default;
89192

90-
CGTYPE getType() { return MType; }
193+
CGTYPE getType() { return static_cast<CGTYPE>(getUnversionedCGType(MType)); }
194+
195+
std::shared_ptr<std::vector<ExtendedMemberT>> getExtendedMembers() {
196+
if (getCGTypeVersion(MType) == static_cast<unsigned int>(CG_VERSION::V0) ||
197+
MSharedPtrStorage.empty())
198+
return nullptr;
199+
200+
// The first value in shared_ptr storage is supposed to store a vector of
201+
// extended members.
202+
return convertToExtendedMembers(MSharedPtrStorage[0]);
203+
}
91204

92205
virtual ~CG() = default;
93206

@@ -146,7 +259,8 @@ class CGExecKernel : public CG {
146259
MSyclKernel(std::move(SyclKernel)), MArgs(std::move(Args)),
147260
MKernelName(std::move(KernelName)), MOSModuleHandle(OSModuleHandle),
148261
MStreams(std::move(Streams)) {
149-
assert((getType() == RUN_ON_HOST_INTEL || getType() == KERNEL) &&
262+
assert((getType() == RUN_ON_HOST_INTEL || getType() == KERNEL ||
263+
getType() == KERNEL_V1) &&
150264
"Wrong type of exec kernel CG.");
151265
}
152266

@@ -155,6 +269,19 @@ class CGExecKernel : public CG {
155269
vector_class<shared_ptr_class<detail::stream_impl>> getStreams() const {
156270
return MStreams;
157271
}
272+
273+
std::shared_ptr<detail::kernel_bundle_impl> getKernelBundle() {
274+
const std::shared_ptr<std::vector<ExtendedMemberT>> &ExtendedMembers =
275+
getExtendedMembers();
276+
if (!ExtendedMembers)
277+
return nullptr;
278+
for (const ExtendedMemberT &EMember : *ExtendedMembers)
279+
if (ExtendedMembersType::HANDLER_KERNEL_BUNDLE == EMember.MType)
280+
return std::static_pointer_cast<detail::kernel_bundle_impl>(
281+
EMember.MData);
282+
return nullptr;
283+
}
284+
158285
void clearStreams() { MStreams.clear(); }
159286
};
160287

0 commit comments

Comments
 (0)