Skip to content

Commit b4efcdb

Browse files
[SYCL] Remove CG/handler extended members mechanism (#6759)
Now that the extended members have been promoted to proper fields of CG/handler classes, the extended member mechanism can be removed until it's needed again.
1 parent 7ecf4f3 commit b4efcdb

File tree

6 files changed

+7
-141
lines changed

6 files changed

+7
-141
lines changed

sycl/doc/developer/ABIPolicyGuide.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,3 @@ Whenever you need to change the existing ABI, please, follow these steps:
123123
part of version, as described above)
124124

125125
At the end of this window we will increment major version of the DPC++ library
126-
127-
## BKMs on avoiding changing ABI
128-
129-
1. If there is a need to add a new field in `sycl::handler` or/and
130-
`sycl::detail::CG` classes it can be done without breaking ABI using the
131-
approach described in the comment at the beggining of
132-
[cg.hpp](../../include/sycl/detail/cg.hpp)

sycl/include/sycl/detail/cg.hpp

Lines changed: 4 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -42,111 +42,16 @@ namespace detail {
4242
class event_impl;
4343
using EventImplPtr = std::shared_ptr<event_impl>;
4444

45-
// Periodically there is a need to extend handler and CG classes to hold more
46-
// data(members) than it has now. But any modification of the layout of those
47-
// classes is an ABI break. To have an ability to have more data the following
48-
// approach is implemented:
49-
//
50-
// Those classes have a member - MSharedPtrStorage which is an std::vector of
51-
// std::shared_ptr's and is supposed to hold reference counters of user
52-
// provided shared_ptr's.
53-
//
54-
// The first element of this vector is reused to store a vector of additional
55-
// members handler and CG need to have.
56-
//
57-
// These additional arguments are represented using "ExtendedMemberT" structure
58-
// which has a pointer to an arbitrary value and an integer which is used to
59-
// understand how the value the pointer points to should be interpreted.
60-
//
61-
// ======== ======== ========
62-
// | | | | ... | | std::vector<std::shared_ptr<void>>
63-
// ======== ======== ========
64-
// || || ||
65-
// || \/ \/
66-
// || user user
67-
// || data data
68-
// \/
69-
// ======== ======== ========
70-
// | Type | | Type | ... | Type | std::vector<ExtendedMemberT>
71-
// | | | | | |
72-
// | Ptr | | Ptr | ... | Ptr |
73-
// ======== ======== ========
74-
//
75-
// Prior to this change this vector was supposed to have user's values only, so
76-
// it is not legal to expect that the first argument is a special one.
77-
// Versioning is implemented to overcome this problem - if the first element of
78-
// the MSharedPtrStorage is a pointer to the special vector then CGType value
79-
// has version "1" encoded.
80-
//
81-
// The version of CG type is encoded in the highest byte of the value:
82-
//
83-
// 0x00000001 - CG type KERNEL version 0
84-
// 0x01000001 - CG type KERNEL version 1
85-
// ^
86-
// |
87-
// The byte specifies the version
88-
//
89-
// A user of this vector should not expect that a specific data is stored at a
90-
// specific position, but iterate over all looking for an ExtendedMemberT value
91-
// with the desired type.
92-
// This allows changing/extending the contents of this vector without changing
93-
// the version.
94-
95-
// Used to represent a type of an extended member
96-
enum class ExtendedMembersType : unsigned int { PLACEHOLDER_TYPE };
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-
11345
class stream_impl;
11446
class queue_impl;
11547
class kernel_bundle_impl;
11648

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-
49+
// If there's a need to add new members to CG classes without breaking ABI
50+
// compatibility, we can bring back the extended members mechanism. See
51+
// https://github.com/intel/llvm/pull/6759
13852
/// Base class for all types of command groups.
13953
class CG {
14054
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-
15055
/// Type of the command group.
15156
enum CGTYPE : unsigned int {
15257
None = 0,
@@ -189,21 +94,7 @@ class CG {
18994

19095
CG(CG &&CommandGroup) = default;
19196

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

20899
virtual ~CG() = default;
209100

sycl/include/sycl/handler.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,9 @@ class __SYCL_EXPORT handler {
380380
return Storage;
381381
}
382382

383-
void setType(detail::CG::CGTYPE Type) {
384-
constexpr detail::CG::CG_VERSION Version = detail::CG::CG_VERSION::V1;
385-
MCGType = static_cast<detail::CG::CGTYPE>(
386-
getVersionedCGType(Type, static_cast<int>(Version)));
387-
}
383+
void setType(detail::CG::CGTYPE Type) { MCGType = Type; }
388384

389-
detail::CG::CGTYPE getType() {
390-
return static_cast<detail::CG::CGTYPE>(getUnversionedCGType(MCGType));
391-
}
385+
detail::CG::CGTYPE getType() { return MCGType; }
392386

393387
void throwIfActionIsCreated() {
394388
if (detail::CG::None != getType())

sycl/source/detail/global_handler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ XPTIRegistry &GlobalHandler::getXPTIRegistry() {
8787
return getOrCreate(MXPTIRegistry);
8888
}
8989

90-
std::mutex &GlobalHandler::getHandlerExtendedMembersMutex() {
91-
return getOrCreate(MHandlerExtendedMembersMutex);
92-
}
93-
9490
ThreadPool &GlobalHandler::getHostTaskThreadPool() {
9591
int Size = SYCLConfig<SYCL_QUEUE_THREAD_POOL_SIZE>::get();
9692
ThreadPool &TP = getOrCreate(MHostTaskThreadPool, Size);

sycl/source/detail/global_handler.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class GlobalHandler {
6767
std::vector<plugin> &getPlugins();
6868
device_filter_list &getDeviceFilterList(const std::string &InitValue);
6969
XPTIRegistry &getXPTIRegistry();
70-
std::mutex &getHandlerExtendedMembersMutex();
7170
ThreadPool &getHostTaskThreadPool();
7271

7372
static void registerDefaultContextReleaseHandler();
@@ -101,8 +100,6 @@ class GlobalHandler {
101100
InstWithLock<std::vector<plugin>> MPlugins;
102101
InstWithLock<device_filter_list> MDeviceFilterList;
103102
InstWithLock<XPTIRegistry> MXPTIRegistry;
104-
// The mutex for synchronizing accesses to handlers extended members
105-
InstWithLock<std::mutex> MHandlerExtendedMembersMutex;
106103
// Thread pool for host task and event callbacks execution
107104
InstWithLock<ThreadPool> MHostTaskThreadPool;
108105
};

sycl/source/handler.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ handler::handler(std::shared_ptr<detail::queue_impl> Queue,
3737
bool IsHost)
3838
: MImpl(std::make_shared<detail::handler_impl>(std::move(PrimaryQueue),
3939
std::move(SecondaryQueue))),
40-
MQueue(std::move(Queue)), MIsHost(IsHost) {
41-
// Create extended members
42-
auto ExtendedMembers =
43-
std::make_shared<std::vector<detail::ExtendedMemberT>>();
44-
MSharedPtrStorage.push_back(std::move(ExtendedMembers));
45-
}
40+
MQueue(std::move(Queue)), MIsHost(IsHost) {}
4641

4742
// Sets the submission state to indicate that an explicit kernel bundle has been
4843
// set. Throws a sycl::exception with errc::invalid if the current state

0 commit comments

Comments
 (0)