3#ifndef poplar_StreamCallback_hpp
4#define poplar_StreamCallback_hpp
6#include <poplar/CallbackTraits.hpp>
7#include <poplar/Quarter.hpp>
8#include <poplar/SSOPointer.hpp>
9#include <poplar/exceptions.hpp>
16class StreamCallbackBase {
18 enum class Result { Success, NotAvailable };
20 virtual ~StreamCallbackBase() =
default;
26 virtual void complete(){};
31 virtual void invalidatePrefetched(){};
139 SSOPointer<ConditionVar> conditionVar;
150 return Result::NotAvailable;
169 template <
class CallbackImpl,
170 typename =
typename std::enable_if<
171 std::is_base_of<StreamCallback, CallbackImpl>::value ||
173 CallbackImpl>::value>::type>
175 : callback(std::move(f)) {
187 template <
class F,
typename =
typename std::enable_if<
188 traits::is_callback<F>::value>::type>
202 operator std::unique_ptr<StreamCallbackBase>() && {
203 return std::move(callback);
212 operator std::unique_ptr<StreamCallback>() &&;
220 operator std::unique_ptr<StreamCallbackWithMetadata>() &&;
224 static std::unique_ptr<StreamCallback> makeCallback(F &&f) {
226 using Function =
typename traits::remove_cvref<F>::type;
228 NonPrefetchable(F &&f) : function(std::forward<F>(f)) {}
229 void fetch(
void *p)
override { function(p); }
232 return std::unique_ptr<NonPrefetchable>(
233 new NonPrefetchable(std::forward<F>(f)));
236 std::unique_ptr<StreamCallbackBase> callback;
A reference to a function stored within a graph.
Definition: GraphElements.hpp:148
Convenience StreamCallback specialization for implementations that do not support prefetch/complete o...
Definition: StreamCallback.hpp:146
virtual void invalidatePrefetched() final override
Not available in legacy streams.
Definition: StreamCallback.hpp:153
virtual void complete() final override
Not available in legacy streams.
Definition: StreamCallback.hpp:155
virtual Result prefetch(void *) final override
Not available in legacy streams.
Definition: StreamCallback.hpp:149
Expands StreamCallback API with functions that prevent further progress.
Definition: StreamCallback.hpp:117
bool isAwaiting() const
Returns whether the callback task is waiting to be notified.
void notify()
Schedules the callback task back to execution.
void wait()
Calling this function will suspend the execution of the current callback.
Wrapper for StreamCallback instances.
Definition: StreamCallback.hpp:161
StreamCallbackHandle(std::unique_ptr< CallbackImpl > f)
Constructs a handle from an instance of a stream callback implementation.
Definition: StreamCallback.hpp:174
StreamCallbackHandle(F &&f)
Constructs a handle from a callable instance.
Definition: StreamCallback.hpp:189
Interface used during stream copies to produce/consume the data being exchanged between the host and ...
Definition: StreamCallback.hpp:43
virtual Result prefetch(void *p)=0
Callback function to fill the host buffer (host-to-device streams only).
virtual void fetch(void *)=0
Callback function to fill the host buffer.
Poplar classes and functions.
Definition: ArrayRef.hpp:14
Base class for Poplar exceptions.
Definition: exceptions.hpp:16