Poplar and PopLibs
poplar::StreamCallback Class Referenceabstract

Interface used during stream copies to produce/consume the data being exchanged between the host and the device. More...

#include <StreamCallback.hpp>

Inheritance diagram for poplar::StreamCallback:
poplar::LegacyStreamCallback poplar::ResumableStreamCallback poplar::StreamCallbackWithMetadata

Public Member Functions

virtual Result prefetch (void *p)=0
 Callback function to fill the host buffer (host-to-device streams only). More...
 
virtual void fetch (void *)=0
 Callback function to fill the host buffer. More...
 

Detailed Description

Interface used during stream copies to produce/consume the data being exchanged between the host and the device.

The type of the data must not require metadata.

In regular stream copies, fetch() and complete() are called as a result of the device requesting the data transfer. In host-to-device streams, prefetch() may be called after the completion of the last transfer of the same stream.

Member Function Documentation

◆ fetch()

virtual void poplar::StreamCallback::fetch ( void *  )
pure virtual

Callback function to fill the host buffer.

This function is called as a result of a stream copy, unless the last prefetch() invocation was successful.

It must always fill the buffer with more data and it is followed by a call to complete().

◆ prefetch()

virtual Result poplar::StreamCallback::prefetch ( void *  p)
pure virtual

Callback function to fill the host buffer (host-to-device streams only).

This function is called speculatively, this means it might still be called even if no additional copies for this stream exist for the remaining execution of the program.

The following situations are possible during the invocation:

  • There is more data available for consumption (A)
  • Data is temporarily not available during the time this function is called (B)
  • The stream reached the end and so no more data is available (C)

The return value indicates if the invocation resulted in the buffer being successfully filled. In the first case (A), the function shall return Result::Success. A call to complete() will follow if the program ends up transferring the data. Otherwise (scenarios B and C), it must return Result::NotAvailable. Calls to fetch() and then complete() will follow if the transfer takes place.

Note that when using a buffered data stream (see Graph::addHostToDeviceFIFO(), bufferingDepth option) there can be multiple calls to prefetch() before a corresponding complete() is called. In some circumstances prefetched data is invalidated and not read, and therefore will have no corresponding complete(), this is notified with invalidatePrefetched().

Parameters
pLocation of the buffer. It will only be valid for the duration of the function.
Returns
Result::Success if the function was able to fill the buffer with data, or Result::NotAvailable otherwise.

Implemented in poplar::LegacyStreamCallback.


The documentation for this class was generated from the following file: