Skip to content

[SYCL] Add implementation of kernel_bundle. Part 3 #3375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
80f3f10
[SYCL] Add implementation of kernel_bundle. Part 2
romanovvlad Mar 2, 2021
0a7ae8a
applying comments
romanovvlad Mar 4, 2021
6b1ddfb
fix export location
romanovvlad Mar 4, 2021
bfd9bad
revert
romanovvlad Mar 8, 2021
b389960
changes
romanovvlad Mar 11, 2021
f609ae9
changes
romanovvlad Mar 11, 2021
2781b4e
changes
romanovvlad Mar 12, 2021
649859c
fix warnings
romanovvlad Mar 15, 2021
4517547
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad Mar 15, 2021
09a3eeb
dummy compile, link, build work
romanovvlad Mar 15, 2021
ff4258a
add kernel_bundle to CG
romanovvlad Mar 15, 2021
3290edf
add kernel_bundle to CG ref
romanovvlad Mar 15, 2021
cca0a2f
merging with cache
romanovvlad Mar 15, 2021
20cdff9
modifying program_manager
romanovvlad Mar 16, 2021
7f49edb
impl of handler methods
romanovvlad Mar 17, 2021
bbf1af3
impl of handler methods
romanovvlad Mar 17, 2021
5b8c430
it works?
romanovvlad Mar 18, 2021
dc0a826
remove spec consts API
romanovvlad Mar 18, 2021
e47fa4a
clean up
romanovvlad Mar 18, 2021
53ab585
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad Mar 22, 2021
a7f8c59
Update symbols
romanovvlad Mar 22, 2021
a6b25dd
More comments, renaming.
romanovvlad Mar 22, 2021
d382787
Add OSModule handle
romanovvlad Mar 22, 2021
3a05631
applying comments
romanovvlad Mar 22, 2021
ef728f7
update assert
romanovvlad Mar 24, 2021
f3daaf5
Add more info about extended members
romanovvlad Mar 24, 2021
90fbe3c
remove OS module usage and add more comment for extended members
romanovvlad Mar 24, 2021
e99f775
apply comments
romanovvlad Mar 24, 2021
77619f7
remove some changes in program_manager
romanovvlad Mar 24, 2021
f9ac19c
updated reference counting.
romanovvlad Mar 24, 2021
f53dfeb
improve test checks
romanovvlad Mar 24, 2021
b816281
apply comments
romanovvlad Mar 24, 2021
4c79ac0
address clang-format concerns.
romanovvlad Mar 24, 2021
6d0dd1e
Add ()
romanovvlad Mar 25, 2021
cd42188
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad Mar 25, 2021
d2f22dd
[SYCL] Fix assert statements
romanovvlad Mar 25, 2021
a8856e8
apply comments
romanovvlad Mar 25, 2021
3ca7c93
more comments
romanovvlad Mar 25, 2021
7a7495f
update test
romanovvlad Mar 25, 2021
0f60a77
Changed getType to return unversioned type
romanovvlad Mar 25, 2021
b9fe1c5
Add support for bringing device images to the desired state.
romanovvlad Mar 27, 2021
87b98ea
address comments
romanovvlad Mar 27, 2021
b7d8c62
Improved test
romanovvlad Mar 27, 2021
dd2de8a
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad Mar 27, 2021
700cd7d
Clang-formatting and fix-spelling
romanovvlad Mar 27, 2021
eb3ee1d
Nth attempt to fix test on windows
romanovvlad Mar 28, 2021
3c5a192
(N+1)th attempt to fix the test on windows
romanovvlad Mar 29, 2021
0ed62b1
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad Mar 29, 2021
a836515
apply comments
romanovvlad Mar 30, 2021
5db24c5
apply comments
romanovvlad Mar 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 134 additions & 7 deletions sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,119 @@ namespace sycl {

// Forward declarations
class queue;
namespace detail {
class queue_impl;
} // namespace detail

namespace detail {

// Periodically there is a need to extend handler and CG classes to hold more
// data(members) than it has now. But any modification of the layout of those
// classes is an ABI break. To have an ability to have more data the following
// approach is implemented:
//
// Those classes have a member - MSharedPtrStorage which is an std::vector of
// std::shared_ptr's and is supposed to hold reference counters of user
// provided shared_ptr's.
//
// The first element of this vector is reused to store a vector of additional
// members handler and CG need to have.
//
// These additional arguments are represented using "ExtendedMemberT" structure
// which has a pointer to an arbitrary value and an integer which is used to
// understand how the value the pointer points to should be interpreted.
//
// ======== ======== ========
// | | | | ... | | std::vector<std::shared_ptr<void>>
// ======== ======== ========
// || || ||
// || \/ \/
// || user user
// || data data
// \/
// ======== ======== ========
// | Type | | Type | ... | Type | std::vector<ExtendedMemberT>
// | | | | | |
// | Ptr | | Ptr | ... | Ptr |
// ======== ======== ========
//
// Prior to this change this vector was supposed to have user's values only, so
// it is not legal to expect that the first argument is a special one.
// Versioning is implemented to overcome this problem - if the first element of
// the MSharedPtrStorage is a pointer to the special vector then CGType value
// has version "1" encoded.
//
// The version of CG type is encoded in the highest byte of the value:
//
// 0x00000001 - CG type KERNEL version 0
// 0x01000001 - CG type KERNEL version 1
// /\
// ||
// The byte specifies the version
//
// A user of this vector should not expect that a specific data is stored at a
// specific position, but iterate over all looking for an ExtendedMemberT value
// with the desired type.
// This allows changing/extending the contents of this vector without changing
// the version.
//
Comment on lines +42 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should update ABI policy guide after this patch is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will add in a separate PR.


// Used to represent a type of an extended member
enum class ExtendedMembersType : unsigned int {
HANDLER_KERNEL_BUNDLE = 0,
};

// Holds a pointer to an object of an arbitrary type and an ID value which
// should be used to understand what type pointer points to.
// Used as to extend handler class without introducing new class members which
// would change handler layout.
struct ExtendedMemberT {
ExtendedMembersType MType;
std::shared_ptr<void> MData;
};

static std::shared_ptr<std::vector<ExtendedMemberT>>
convertToExtendedMembers(const std::shared_ptr<const void> &SPtr) {
return std::const_pointer_cast<std::vector<ExtendedMemberT>>(
std::static_pointer_cast<const std::vector<ExtendedMemberT>>(SPtr));
}

class stream_impl;
class queue_impl;
class kernel_bundle_impl;

// The constant is used to left shift a CG type value to access it's version
constexpr unsigned int ShiftBitsForVersion = 24;

// Constructs versioned type
constexpr unsigned int getVersionedCGType(unsigned int Type,
unsigned char Version) {
return Type | (static_cast<unsigned int>(Version) << ShiftBitsForVersion);
}

// Returns the type without version encoded
constexpr unsigned char getUnversionedCGType(unsigned int Type) {
unsigned int Mask = -1;
Mask >>= (sizeof(Mask) * 8 - ShiftBitsForVersion);
return Type & Mask;
}

// Returns the version encoded to the type
constexpr unsigned char getCGTypeVersion(unsigned int Type) {
return Type >> ShiftBitsForVersion;
}

/// Base class for all types of command groups.
class CG {
public:
// Used to version CG and handler classes. Using unsigned char as the version
// is encoded in the highest byte of CGType value. So it is not possible to
// encode a value > 255 anyway which should be big enough room for version
// bumping.
enum class CG_VERSION : unsigned char {
V0 = 0,
V1 = 1,
};

/// Type of the command group.
enum CGTYPE {
enum CGTYPE : unsigned int {
NONE = 0,
KERNEL = 1,
COPY_ACC_TO_PTR = 2,
Expand All @@ -62,7 +163,9 @@ class CG {
FILL_USM = 11,
PREFETCH_USM = 12,
CODEPLAY_INTEROP_TASK = 13,
CODEPLAY_HOST_TASK = 14
CODEPLAY_HOST_TASK = 14,
KERNEL_V1 =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably it makes more sense to not have distinct enum value and hide manipulations with version in setType, getType, setVersion, getVersion methods.

getVersionedCGType(KERNEL, static_cast<unsigned int>(CG_VERSION::V1)),
};

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

CG(CG &&CommandGroup) = default;

CGTYPE getType() { return MType; }
CGTYPE getType() { return static_cast<CGTYPE>(getUnversionedCGType(MType)); }

std::shared_ptr<std::vector<ExtendedMemberT>> getExtendedMembers() {
if (getCGTypeVersion(MType) == static_cast<unsigned int>(CG_VERSION::V0) ||
MSharedPtrStorage.empty())
return nullptr;

// The first value in shared_ptr storage is supposed to store a vector of
// extended members.
return convertToExtendedMembers(MSharedPtrStorage[0]);
}

virtual ~CG() = default;

Expand Down Expand Up @@ -146,7 +259,8 @@ class CGExecKernel : public CG {
MSyclKernel(std::move(SyclKernel)), MArgs(std::move(Args)),
MKernelName(std::move(KernelName)), MOSModuleHandle(OSModuleHandle),
MStreams(std::move(Streams)) {
assert((getType() == RUN_ON_HOST_INTEL || getType() == KERNEL) &&
assert((getType() == RUN_ON_HOST_INTEL || getType() == KERNEL ||
getType() == KERNEL_V1) &&
"Wrong type of exec kernel CG.");
}

Expand All @@ -155,6 +269,19 @@ class CGExecKernel : public CG {
vector_class<shared_ptr_class<detail::stream_impl>> getStreams() const {
return MStreams;
}

std::shared_ptr<detail::kernel_bundle_impl> getKernelBundle() {
const std::shared_ptr<std::vector<ExtendedMemberT>> &ExtendedMembers =
getExtendedMembers();
if (!ExtendedMembers)
return nullptr;
for (const ExtendedMemberT &EMember : *ExtendedMembers)
if (ExtendedMembersType::HANDLER_KERNEL_BUNDLE == EMember.MType)
return std::static_pointer_cast<detail::kernel_bundle_impl>(
EMember.MData);
return nullptr;
}

void clearStreams() { MStreams.clear(); }
};

Expand Down
Loading