-
Notifications
You must be signed in to change notification settings - Fork 768
[SYCL][Fusion] Add kernel fusion extension API #7416
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
steffenlarsen
merged 3 commits into
intel:sycl
from
sommerlukas:kernel-fusion/first-patch
Nov 24, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
108 changes: 108 additions & 0 deletions
108
sycl/include/sycl/ext/codeplay/experimental/fusion_properties.hpp
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
//==----------- fusion_properties.hpp --- SYCL fusion properties -----------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <sycl/access/access.hpp> | ||
#include <sycl/detail/property_helper.hpp> | ||
#include <sycl/properties/property_traits.hpp> | ||
|
||
namespace sycl { | ||
__SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
namespace ext { | ||
namespace codeplay { | ||
namespace experimental { | ||
namespace property { | ||
|
||
class promote_private | ||
: public detail::DataLessProperty<detail::FusionPromotePrivate> {}; | ||
|
||
class promote_local | ||
: public detail::DataLessProperty<detail::FusionPromoteLocal> {}; | ||
|
||
class no_barriers : public detail::DataLessProperty<detail::FusionNoBarrier> {}; | ||
|
||
class force_fusion : public detail::DataLessProperty<detail::FusionForce> {}; | ||
|
||
namespace queue { | ||
class enable_fusion : public detail::DataLessProperty<detail::FusionEnable> {}; | ||
} // namespace queue | ||
|
||
} // namespace property | ||
} // namespace experimental | ||
} // namespace codeplay | ||
} // namespace ext | ||
|
||
// Forward declarations | ||
template <typename T, int Dimensions, typename AllocatorT, typename Enable> | ||
class buffer; | ||
|
||
template <typename DataT, int Dimensions, access::mode AccessMode, | ||
access::target AccessTarget, access::placeholder IsPlaceholder, | ||
typename PropertyListT> | ||
class accessor; | ||
|
||
class queue; | ||
|
||
// Property trait specializations. | ||
template <> | ||
struct is_property<ext::codeplay::experimental::property::promote_private> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property<ext::codeplay::experimental::property::promote_local> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property<ext::codeplay::experimental::property::no_barriers> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property<ext::codeplay::experimental::property::force_fusion> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property<ext::codeplay::experimental::property::queue::enable_fusion> | ||
: std::true_type {}; | ||
|
||
// Buffer property trait specializations | ||
template <typename T, int Dimensions, typename AllocatorT> | ||
struct is_property_of<ext::codeplay::experimental::property::promote_private, | ||
buffer<T, Dimensions, AllocatorT, void>> | ||
: std::true_type {}; | ||
|
||
template <typename T, int Dimensions, typename AllocatorT> | ||
struct is_property_of<ext::codeplay::experimental::property::promote_local, | ||
buffer<T, Dimensions, AllocatorT, void>> | ||
: std::true_type {}; | ||
|
||
// Accessor property trait specializations | ||
template <typename DataT, int Dimensions, access::mode AccessMode, | ||
access::target AccessTarget, access::placeholder IsPlaceholder, | ||
typename PropertyListT> | ||
struct is_property_of<ext::codeplay::experimental::property::promote_private, | ||
accessor<DataT, Dimensions, AccessMode, AccessTarget, | ||
IsPlaceholder, PropertyListT>> : std::true_type { | ||
}; | ||
|
||
template <typename DataT, int Dimensions, access::mode AccessMode, | ||
access::target AccessTarget, access::placeholder IsPlaceholder, | ||
typename PropertyListT> | ||
struct is_property_of<ext::codeplay::experimental::property::promote_local, | ||
accessor<DataT, Dimensions, AccessMode, AccessTarget, | ||
IsPlaceholder, PropertyListT>> : std::true_type { | ||
}; | ||
|
||
// Queue property trait specializations | ||
template <> | ||
struct is_property_of< | ||
ext::codeplay::experimental::property::queue::enable_fusion, queue> | ||
: std::true_type {}; | ||
|
||
} // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
} // namespace sycl |
98 changes: 98 additions & 0 deletions
98
sycl/include/sycl/ext/codeplay/experimental/fusion_wrapper.hpp
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//==---- fusion_wrapper.hpp --- SYCL wrapper for queue for kernel fusion ---==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <sycl/queue.hpp> | ||
|
||
namespace sycl { | ||
__SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
|
||
namespace detail { | ||
class fusion_wrapper_impl; | ||
} | ||
|
||
namespace ext { | ||
namespace codeplay { | ||
namespace experimental { | ||
|
||
/// | ||
/// A wrapper wrapping a sycl::queue to provide access to the kernel fusion API, | ||
/// allowing to manage kernel fusion on the wrapped queue. | ||
class __SYCL_EXPORT fusion_wrapper { | ||
|
||
public: | ||
/// | ||
/// Wrap a queue to get access to the kernel fusion API. | ||
/// | ||
/// @throw sycl::exception with errc::invalid if trying to construct a wrapper | ||
/// on a queue which doesn't support fusion. | ||
explicit fusion_wrapper(queue &q); | ||
|
||
/// | ||
/// Access the queue wrapped by this fusion wrapper. | ||
queue get_queue() const; | ||
|
||
/// | ||
/// @brief Check whether the wrapped queue is in fusion mode or not. | ||
bool is_in_fusion_mode() const; | ||
|
||
/// | ||
/// @brief Set the wrapped queue into "fusion mode". This means that the | ||
/// kernels that are submitted in subsequent calls to queue::submit() are not | ||
/// submitted for execution right away, but rather added to a list of kernels | ||
/// that should be fused. | ||
/// | ||
/// @throw sycl::exception with errc::invalid if this operation is called on a | ||
/// queue which is already in fusion mode. | ||
void start_fusion(); | ||
|
||
/// | ||
/// @brief Cancel the fusion and submit all kernels submitted since the last | ||
/// start_fusion() for immediate execution without fusion. The kernels are | ||
/// executed in the same order as they were initially submitted to the wrapped | ||
/// queue. | ||
/// | ||
/// This operation is asynchronous, i.e., it may return after the previously | ||
/// submitted kernels have been passed to the scheduler, but before any of the | ||
/// previously submitted kernel starts or completes execution. The events | ||
/// returned by submit() since the last call to start_fusion remain valid and | ||
/// can be used for synchronization. | ||
/// | ||
/// The queue is not in "fusion mode" anymore after this calls returns, until | ||
/// the next start_fusion(). | ||
void cancel_fusion(); | ||
|
||
/// | ||
/// @brief Complete the fusion: JIT-compile a fused kernel from all kernels | ||
/// submitted to the wrapped queue since the last start_fusion and submit the | ||
/// fused kernel for execution. Inside the fused kernel, the per-work-item | ||
/// effects are executed in the same order as the kernels were initially | ||
/// submitted. | ||
/// | ||
/// This operation is asynchronous, i.e., it may return after the JIT | ||
/// compilation is executed and the fused kernel is passed to the scheduler, | ||
/// but before the fused kernel starts or completes execution. The returned | ||
/// event allows to synchronize with the execution of the fused kernel. All | ||
/// events returned by queue::submit since the last call to start_fusion | ||
/// remain valid. | ||
/// | ||
/// The wrapped queue is not in "fusion mode" anymore after this calls | ||
/// returns, until the next start_fusion(). | ||
/// | ||
/// @param properties Properties to take into account when performing fusion. | ||
event complete_fusion(const property_list &propList = {}); | ||
|
||
private: | ||
std::shared_ptr<detail::fusion_wrapper_impl> MImpl; | ||
}; | ||
} // namespace experimental | ||
} // namespace codeplay | ||
} // namespace ext | ||
} // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
} // namespace sycl |
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//==------------ fusion_wrapper.cpp ----------------------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <sycl/ext/codeplay/experimental/fusion_wrapper.hpp> | ||
|
||
#include <detail/fusion/fusion_wrapper_impl.hpp> | ||
#include <detail/queue_impl.hpp> | ||
|
||
namespace sycl { | ||
__SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
namespace ext { | ||
namespace codeplay { | ||
namespace experimental { | ||
|
||
fusion_wrapper::fusion_wrapper(queue &Queue) { | ||
if (!Queue.ext_codeplay_supports_fusion()) { | ||
throw sycl::exception( | ||
sycl::errc::invalid, | ||
"Cannot wrap a queue for fusion which doesn't support fusion"); | ||
} | ||
MImpl = std::make_shared<detail::fusion_wrapper_impl>( | ||
sycl::detail::getSyclObjImpl(Queue)); | ||
} | ||
|
||
queue fusion_wrapper::get_queue() const { | ||
return sycl::detail::createSyclObjFromImpl<sycl::queue>(MImpl->get_queue()); | ||
} | ||
|
||
bool fusion_wrapper::is_in_fusion_mode() const { | ||
return MImpl->is_in_fusion_mode(); | ||
} | ||
|
||
void fusion_wrapper::start_fusion() { MImpl->start_fusion(); } | ||
|
||
void fusion_wrapper::cancel_fusion() { MImpl->cancel_fusion(); } | ||
|
||
event fusion_wrapper::complete_fusion(const property_list &PropList) { | ||
return MImpl->complete_fusion(PropList); | ||
} | ||
|
||
} // namespace experimental | ||
} // namespace codeplay | ||
} // namespace ext | ||
} // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
} // namespace sycl |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//==------------ fusion_wrapper.cpp ----------------------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <detail/fusion/fusion_wrapper_impl.hpp> | ||
|
||
namespace sycl { | ||
__SYCL_INLINE_VER_NAMESPACE(_V1) { | ||
namespace detail { | ||
|
||
fusion_wrapper_impl::fusion_wrapper_impl( | ||
std::shared_ptr<detail::queue_impl> Queue) | ||
: MQueue{std::move(Queue)} {} | ||
|
||
std::shared_ptr<detail::queue_impl> fusion_wrapper_impl::get_queue() const { | ||
return MQueue; | ||
} | ||
|
||
bool fusion_wrapper_impl::is_in_fusion_mode() const { return false; } | ||
|
||
void fusion_wrapper_impl::start_fusion() { | ||
throw sycl::exception(sycl::errc::feature_not_supported, | ||
"Fusion not yet implemented"); | ||
} | ||
|
||
void fusion_wrapper_impl::cancel_fusion() { | ||
throw sycl::exception(sycl::errc::feature_not_supported, | ||
"Fusion not yet implemented"); | ||
} | ||
|
||
event fusion_wrapper_impl::complete_fusion(const property_list &PropList) { | ||
(void)PropList; | ||
throw sycl::exception(sycl::errc::feature_not_supported, | ||
"Fusion not yet implemented"); | ||
} | ||
|
||
} // namespace detail | ||
} // __SYCL_INLINE_VER_NAMESPACE(_V1) | ||
} // namespace sycl |
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.
@pvchupin - Do we have a good place to document this?
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.
A future PR will add support for fusion in
buildbot/configure.py
, which would then set the value for this option.Users using
buildbot/configure.py
would therefore not need to set this option manually.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.
I guess it can be documented at https://github.com/intel/llvm/blob/sycl/sycl/doc/GetStartedGuide.md#build-dpc-toolchain
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.
In that case, I am okay with waiting with documentation for it until it has an option in
buildbot/configure.py
. I'll let @pvchupin have the last say in that though.