Skip to content

[SYCL] Implementation of discard_events #5026

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 32 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
adf4079
[SYCL] Add avoid_event_creation property for queue
alexanderfle Oct 28, 2021
6905227
[SYCL] Add exceptions for a few cases.
alexanderfle Oct 29, 2021
aaa71c8
[SYCL] Add check for kernel case
alexanderfle Nov 1, 2021
04d798f
Merge branch 'sycl' into way1
alexanderfle Nov 1, 2021
1b340b0
Merge branch 'sycl' into way1
alexanderfle Nov 11, 2021
aa620d4
Merge branch 'sycl' into way1
alexanderfle Nov 11, 2021
f5730c6
[SYCL] Add new macro in Feature Test
alexanderfle Nov 11, 2021
2b1a221
[SYCL] Update queue_properties.hpp according to last merge logic
alexanderfle Nov 11, 2021
2f31823
[SYCL] Rename avoid_event_creation property to discard_events
alexanderfle Nov 11, 2021
b08c309
[SYCL] Change namespace on ext::oneapi::property::queue::discard_events
alexanderfle Nov 11, 2021
ebaa2a1
[SYCL] Add support for fallback assert
alexanderfle Nov 17, 2021
d325859
[SYCL] Align implementation with spec
alexanderfle Nov 23, 2021
7f5de5b
Merge branch 'sycl' into way1
alexanderfle Nov 23, 2021
107721c
Clean up unnecessary changes
alexanderfle Nov 23, 2021
16cf4c0
Clean up unnecessary changes2
alexanderfle Nov 23, 2021
3fd916e
[SYCL] Fix ABI issues
alexanderfle Nov 25, 2021
675a1a3
[SYCL] Update sycl_symbols for ABI test
alexanderfle Nov 25, 2021
b0b1e0d
[SYCL] Update sycl_symbols_windows.dump
alexanderfle Nov 25, 2021
23271fd
[SYCL] Reduce one call to move assignment operator of sycl::event
alexanderfle Nov 25, 2021
1a67f7d
[SYCL] Add mock for EventGetInfo
alexanderfle Nov 25, 2021
c996706
[SYCL] Fix not uniqueness of event_command_status enum
alexanderfle Nov 26, 2021
bf96adc
[SYCL] Update CommonRedefinitions in unittests
alexanderfle Nov 29, 2021
fa654d3
[SYCL] Revert changes for MemoryManager::copy and MemoryManager::fill
alexanderfle Dec 3, 2021
a85eec5
Merge branch 'sycl' into discard_events_implementation
alexanderfle Dec 6, 2021
6e4468b
[SYCL] Update symbols for linux and windows according to previous revert
alexanderfle Dec 6, 2021
65ef8fe
Merge branch 'sycl' into discard_events_implementation
alexanderfle Dec 7, 2021
4cd8233
[SYCL] Fix review comments
alexanderfle Dec 10, 2021
9ec63ad
[SYCL] Update sycl_symbols_linux.dump and Rename "invalid" event to "…
alexanderfle Dec 10, 2021
d55f3e5
[SYCL] Update comment to clarify "MHasDiscardEventsSupport"
alexanderfle Dec 10, 2021
f70f49d
[SYCL] Update value of ext_oneapi_unknown
alexanderfle Dec 13, 2021
fe6abbf
Merge branch 'sycl' into discard_events_implementation
alexanderfle Dec 14, 2021
6617fc7
[SYCL] Merge 'sycl' into discard_events_implementation
alexanderfle Dec 14, 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
26 changes: 26 additions & 0 deletions sycl/include/CL/sycl/detail/memory_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <CL/sycl/detail/cl.h>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
#include <CL/sycl/id.hpp>
#include <CL/sycl/property_list.hpp>
#include <CL/sycl/range.hpp>

Expand Down Expand Up @@ -140,18 +141,43 @@ class __SYCL_EXPORT MemoryManager {
void *MappedPtr, std::vector<RT::PiEvent> DepEvents,
RT::PiEvent &OutEvent);

static void copy_usm(const void *SrcMem, QueueImplPtr Queue, size_t Len,
void *DstMem, std::vector<RT::PiEvent> DepEvents,
RT::PiEvent *OutEvent);

__SYCL_DEPRECATED("copy_usm() accepting PiEvent& is deprecated, use "
"copy_usm() accepting PiEvent* instead")
static void copy_usm(const void *SrcMem, QueueImplPtr Queue, size_t Len,
void *DstMem, std::vector<RT::PiEvent> DepEvents,
RT::PiEvent &OutEvent);

static void fill_usm(void *DstMem, QueueImplPtr Queue, size_t Len,
int Pattern, std::vector<RT::PiEvent> DepEvents,
RT::PiEvent *OutEvent);

__SYCL_DEPRECATED("fill_usm() accepting PiEvent& is deprecated, use "
"fill_usm() accepting PiEvent* instead")
static void fill_usm(void *DstMem, QueueImplPtr Queue, size_t Len,
int Pattern, std::vector<RT::PiEvent> DepEvents,
RT::PiEvent &OutEvent);

static void prefetch_usm(void *Ptr, QueueImplPtr Queue, size_t Len,
std::vector<RT::PiEvent> DepEvents,
RT::PiEvent *OutEvent);

__SYCL_DEPRECATED("prefetch_usm() accepting PiEvent& is deprecated, use "
"prefetch_usm() accepting PiEvent* instead")
static void prefetch_usm(void *Ptr, QueueImplPtr Queue, size_t Len,
std::vector<RT::PiEvent> DepEvents,
RT::PiEvent &OutEvent);

static void advise_usm(const void *Ptr, QueueImplPtr Queue, size_t Len,
pi_mem_advice Advice,
std::vector<RT::PiEvent> DepEvents,
RT::PiEvent *OutEvent);

__SYCL_DEPRECATED("advise_usm() accepting PiEvent& is deprecated, use "
"advise_usm() accepting PiEvent* instead")
static void advise_usm(const void *Ptr, QueueImplPtr Queue, size_t Len,
pi_mem_advice Advice,
std::vector<RT::PiEvent> DepEvents,
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/property_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ enum DataLessPropKind {
UsePrimaryContext = 6,
InitializeToIdentity = 7,
UseDefaultStream = 8,
DiscardEvents = 9,
// Indicates the last known dataless property.
LastKnownDataLessPropKind = 8,
LastKnownDataLessPropKind = 9,
// Exceeding 32 may cause ABI breaking change on some of OSes.
DataLessPropKindSize = 32
};
Expand Down
1 change: 1 addition & 0 deletions sycl/include/CL/sycl/feature_test.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace sycl {
#define SYCL_EXT_ONEAPI_MATRIX 2
#endif
#define SYCL_EXT_ONEAPI_ASSERT 1
#define SYCL_EXT_ONEAPI_DISCARD_QUEUE_EVENTS 1
#define SYCL_EXT_ONEAPI_ENQUEUE_BARRIER 1
#define SYCL_EXT_ONEAPI_FREE_FUNCTION_QUERIES 1
#define SYCL_EXT_ONEAPI_GROUP_ALGORITHMS 1
Expand Down
10 changes: 2 additions & 8 deletions sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1354,18 +1354,12 @@ class __SYCL_EXPORT handler {
/// Registers event dependencies on this command group.
///
/// \param Event is a valid SYCL event to wait on.
void depends_on(event Event) {
MEvents.push_back(detail::getSyclObjImpl(Event));
}
void depends_on(event Event);

/// Registers event dependencies on this command group.
///
/// \param Events is a vector of valid SYCL events to wait on.
void depends_on(const std::vector<event> &Events) {
for (const event &Event : Events) {
MEvents.push_back(detail::getSyclObjImpl(Event));
}
}
void depends_on(const std::vector<event> &Events);

template <typename T>
using remove_cv_ref_t =
Expand Down
5 changes: 4 additions & 1 deletion sycl/include/CL/sycl/info/info_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ enum class event : cl_event_info {
enum class event_command_status : cl_int {
submitted = CL_SUBMITTED,
running = CL_RUNNING,
complete = CL_COMPLETE
complete = CL_COMPLETE,
// Since all BE values are positive, it is safe to use a negative value If you
// add other ext_oneapi values
ext_oneapi_unknown = -1
};

enum class event_profiling : cl_profiling_info {
Expand Down
14 changes: 14 additions & 0 deletions sycl/include/CL/sycl/properties/queue_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class enable_profiling

namespace ext {
namespace oneapi {

namespace property {
namespace queue {
class discard_events : public ::cl::sycl::detail::DataLessProperty<
::cl::sycl::detail::DiscardEvents> {};
} // namespace queue
} // namespace property

namespace cuda {
namespace property {
namespace queue {
Expand Down Expand Up @@ -52,6 +60,9 @@ template <> struct is_property<property::queue::in_order> : std::true_type {};
template <>
struct is_property<property::queue::enable_profiling> : std::true_type {};
template <>
struct is_property<ext::oneapi::property::queue::discard_events>
: std::true_type {};
template <>
struct is_property<property::queue::cuda::use_default_stream> : std::true_type {
};
template <>
Expand All @@ -64,6 +75,9 @@ template <>
struct is_property_of<property::queue::enable_profiling, queue>
: std::true_type {};
template <>
struct is_property_of<ext::oneapi::property::queue::discard_events, queue>
: std::true_type {};
template <>
struct is_property_of<property::queue::cuda::use_default_stream, queue>
: std::true_type {};
template <>
Expand Down
26 changes: 13 additions & 13 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ class __SYCL_EXPORT queue {
template <typename T> event submit(T CGF _CODELOCPARAM(&CodeLoc)) {
_CODELOCARG(&CodeLoc);

event Event;

#if __SYCL_USE_FALLBACK_ASSERT
if (!is_host()) {
auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert,
Expand All @@ -268,14 +266,14 @@ class __SYCL_EXPORT queue {
}
};

Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess);
auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess);
return discard_or_return(Event);
} else
#endif // __SYCL_USE_FALLBACK_ASSERT
{
Event = submit_impl(CGF, CodeLoc);
auto Event = submit_impl(CGF, CodeLoc);
return discard_or_return(Event);
}

return Event;
}

/// Submits a command group function object to the queue, in order to be
Expand All @@ -293,8 +291,6 @@ class __SYCL_EXPORT queue {
event submit(T CGF, queue &SecondaryQueue _CODELOCPARAM(&CodeLoc)) {
_CODELOCARG(&CodeLoc);

event Event;

#if __SYCL_USE_FALLBACK_ASSERT
if (!is_host()) {
auto PostProcess = [this, &SecondaryQueue, &CodeLoc](
Expand All @@ -315,15 +311,15 @@ class __SYCL_EXPORT queue {
}
};

Event = submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc,
PostProcess);
auto Event = submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc,
PostProcess);
return discard_or_return(Event);
} else
#endif // __SYCL_USE_FALLBACK_ASSERT
{
Event = submit_impl(CGF, SecondaryQueue, CodeLoc);
auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc);
return discard_or_return(Event);
}

return Event;
}

/// Prevents any commands submitted afterward to this queue from executing
Expand Down Expand Up @@ -1089,6 +1085,10 @@ class __SYCL_EXPORT queue {
event submit_impl(std::function<void(handler &)> CGH, queue secondQueue,
const detail::code_location &CodeLoc);

/// Checks if the event needs to be discarded and if so, discards it and
/// returns a discarded event. Otherwise, it returns input event.
event discard_or_return(const event &Event);

// Function to postprocess submitted command
// Arguments:
// bool IsKernel - true if the submitted command was kernel, false otherwise
Expand Down
20 changes: 19 additions & 1 deletion sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ void event_impl::waitInternal() const {
return;
}

if (MState == HES_Discarded)
throw sycl::exception(
make_error_code(errc::invalid),
"waitInternal method cannot be used for a discarded event.");

while (MState != HES_Complete)
;
}
Expand Down Expand Up @@ -93,7 +98,8 @@ void event_impl::setContextImpl(const ContextImplPtr &Context) {
MState = HES_NotComplete;
}

event_impl::event_impl() : MIsFlushed(true), MState(HES_Complete) {}
event_impl::event_impl(HostEventState State)
: MIsFlushed(true), MState(State) {}

event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
: MEvent(Event), MContext(detail::getSyclObjImpl(SyclContext)),
Expand Down Expand Up @@ -188,6 +194,10 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,

void event_impl::wait(
std::shared_ptr<cl::sycl::detail::event_impl> Self) const {
if (MState == HES_Discarded)
throw sycl::exception(make_error_code(errc::invalid),
"wait method cannot be used for a discarded event.");

#ifdef XPTI_ENABLE_INSTRUMENTATION
void *TelemetryEvent = nullptr;
uint64_t IId;
Expand Down Expand Up @@ -304,6 +314,9 @@ template <> cl_uint event_impl::get_info<info::event::reference_count>() const {
template <>
info::event_command_status
event_impl::get_info<info::event::command_execution_status>() const {
if (MState == HES_Discarded)
return info::event_command_status::ext_oneapi_unknown;

if (!MHostEvent && MEvent) {
return get_event_info<info::event::command_execution_status>::get(
this->getHandleRef(), this->getPlugin());
Expand Down Expand Up @@ -333,6 +346,11 @@ pi_native_handle event_impl::getNative() const {
}

std::vector<EventImplPtr> event_impl::getWaitList() {
if (MState == HES_Discarded)
throw sycl::exception(
make_error_code(errc::invalid),
"get_wait_list() cannot be used for a discarded event.");

std::lock_guard<std::mutex> Lock(MMutex);

std::vector<EventImplPtr> Result;
Expand Down
15 changes: 12 additions & 3 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ using EventImplPtr = std::shared_ptr<cl::sycl::detail::event_impl>;

class event_impl {
public:
enum HostEventState : int {
HES_NotComplete = 0,
HES_Complete,
HES_Discarded
};

/// Constructs a ready SYCL event.
///
/// If the constructed SYCL event is waited on it will complete immediately.
event_impl();
event_impl(HostEventState State = HES_Complete);
/// Constructs an event instance from a plug-in event handle.
///
/// The SyclContext must match the plug-in context associated with the
Expand Down Expand Up @@ -190,6 +196,11 @@ class event_impl {
/// Cleans dependencies of this event_impl
void cleanupDependencyEvents();

/// Checks if this event is discarded by SYCL implementation.
///
/// \return true if this event is discarded.
bool isDiscarded() const { return MState == HES_Discarded; }

private:
// When instrumentation is enabled emits trace event for event wait begin and
// returns the telemetry event generated for the wait
Expand All @@ -215,8 +226,6 @@ class event_impl {
/// the queue to the device.
std::atomic<bool> MIsFlushed = false;

enum HostEventState : int { HES_NotComplete = 0, HES_Complete };

// State of host event. Employed only for host events and event with no
// backend's representation (e.g. alloca). Used values are listed in
// HostEventState enum.
Expand Down
Loading