-
Notifications
You must be signed in to change notification settings - Fork 770
[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
romanovvlad
merged 50 commits into
intel:sycl
from
romanovvlad:private/vromanov/KernelBundlesImpl6
Mar 31, 2021
Merged
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 0a7ae8a
applying comments
romanovvlad 6b1ddfb
fix export location
romanovvlad bfd9bad
revert
romanovvlad b389960
changes
romanovvlad f609ae9
changes
romanovvlad 2781b4e
changes
romanovvlad 649859c
fix warnings
romanovvlad 4517547
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad 09a3eeb
dummy compile, link, build work
romanovvlad ff4258a
add kernel_bundle to CG
romanovvlad 3290edf
add kernel_bundle to CG ref
romanovvlad cca0a2f
merging with cache
romanovvlad 20cdff9
modifying program_manager
romanovvlad 7f49edb
impl of handler methods
romanovvlad bbf1af3
impl of handler methods
romanovvlad 5b8c430
it works?
romanovvlad dc0a826
remove spec consts API
romanovvlad e47fa4a
clean up
romanovvlad 53ab585
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad a7f8c59
Update symbols
romanovvlad a6b25dd
More comments, renaming.
romanovvlad d382787
Add OSModule handle
romanovvlad 3a05631
applying comments
romanovvlad ef728f7
update assert
romanovvlad f3daaf5
Add more info about extended members
romanovvlad 90fbe3c
remove OS module usage and add more comment for extended members
romanovvlad e99f775
apply comments
romanovvlad 77619f7
remove some changes in program_manager
romanovvlad f9ac19c
updated reference counting.
romanovvlad f53dfeb
improve test checks
romanovvlad b816281
apply comments
romanovvlad 4c79ac0
address clang-format concerns.
romanovvlad 6d0dd1e
Add ()
romanovvlad cd42188
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad d2f22dd
[SYCL] Fix assert statements
romanovvlad a8856e8
apply comments
romanovvlad 3ca7c93
more comments
romanovvlad 7a7495f
update test
romanovvlad 0f60a77
Changed getType to return unversioned type
romanovvlad b9fe1c5
Add support for bringing device images to the desired state.
romanovvlad 87b98ea
address comments
romanovvlad b7d8c62
Improved test
romanovvlad dd2de8a
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad 700cd7d
Clang-formatting and fix-spelling
romanovvlad eb3ee1d
Nth attempt to fix test on windows
romanovvlad 3c5a192
(N+1)th attempt to fix the test on windows
romanovvlad 0ed62b1
Merge remote-tracking branch 'public/sycl' into private/vromanov/Kern…
romanovvlad a836515
apply comments
romanovvlad 5db24c5
apply comments
romanovvlad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
// | ||
|
||
// 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 { | ||
kbobrovs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ExtendedMembersType MType; | ||
std::shared_ptr<void> MData; | ||
}; | ||
|
||
static std::shared_ptr<std::vector<ExtendedMemberT>> | ||
kbobrovs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
alexbatashev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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, | ||
|
@@ -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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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]); | ||
kbobrovs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
virtual ~CG() = default; | ||
|
||
|
@@ -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."); | ||
} | ||
|
||
|
@@ -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(); } | ||
}; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.