Skip to content
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

DPL I/O API: Supporting spectator vector as return for InputRecord::get<std::vector<T>> #2697

Conversation

matthiasrichter
Copy link
Collaborator

I'm opening a new PR in order to discuss this topic even though it depends on the commit in #2617

When querying vectors, a spectator vactor is returned which is directly using
the raw memory without copy using polymorphic allocator and spectator memory
resource. A unique instance of the spectator memory resource is kept in the
InputRecord and valid for the lifetime of teh record.

This changes the return type to vector<T const, o2::pmr::SpectatorAllocator<T const>>
and thus breaks compilation in code where the vector with standard allocator is used.

This is not problematic in cases where the returned instance is only used in the
function itself and not passed onto workers (unless in a templatized function call).

Ways out of this problem:
change access to the read-only input data objects in the worker classes

  1. where possible one could use a templatized function call, and within this reader
    function use iterators
  2. introduce specific vector class like o2::spectator::vector (naming to be discussed)
  3. Use spans over the readonly input arrays

Pros and cons:
option 1) (+) can implement flexible code
(-) many of the classes use member variables to hold the
data which are set in advance, implementation must be in the header
this is more an option for small algorithms
option 2) (+) we introduce a data object which can be used system wide
(-) while suitable for the workflow implementations and everything which
is related to messaging in DPL, the worker classes should be kept more
general in order to be used standalone with little overhead
option 3) (+) generic solution
(-) no cons

@matthiasrichter matthiasrichter requested a review from a team as a code owner December 12, 2019 09:40
@matthiasrichter
Copy link
Collaborator Author

Once the worker code is changed to use spans, there is of course also an option to use InputRecord::get<span<T>> for messageable types.

@@ -516,6 +523,7 @@ class InputRecord
private:
std::vector<InputRoute> const& mInputsSchema;
InputSpan mSpan;
std::vector<std::unique_ptr<boost::container::pmr::memory_resource>> mSpectatorResources;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should ask that FairMQMessage becomes a "spectator resource" itself, so that we do not need to have separate accounting of those. @rbx @mkrzewic what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind the FairMQ message does not know the type...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been playing with some ideas at FairMQLevel (see e.g. FairRootGroup/FairMQ#110). btw, the resource does not need to know the type, it is meant to allocate bytes only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean not only, but bytes is enough :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed resourcebuffer was just "char".

@ktf
Copy link
Member

ktf commented Dec 12, 2019

For the record, this PR is fine for me, but I really think we should use spans and string_view when accessing data.

@ktf
Copy link
Member

ktf commented Dec 12, 2019

or even the ranges_v3 api...

@matthiasrichter matthiasrichter force-pushed the framework-io-spectator-vector branch from 86a3732 to ae5e312 Compare February 20, 2020 23:13
@matthiasrichter matthiasrichter changed the title DPL I/O API: Prototyping spectator vector as return for InputRecord::get<std::vector<T>> [WIP] DPL I/O API: Prototyping spectator vector as return for InputRecord::get<std::vector<T>> Feb 27, 2020
@matthiasrichter matthiasrichter force-pushed the framework-io-spectator-vector branch from ae5e312 to a17fe64 Compare March 3, 2020 12:09
@matthiasrichter matthiasrichter force-pushed the framework-io-spectator-vector branch 3 times, most recently from 4885c38 to 5612d23 Compare March 19, 2020 14:59
@matthiasrichter matthiasrichter requested a review from a team as a code owner March 19, 2020 14:59
@matthiasrichter
Copy link
Collaborator Author

A quick update: meanwhile many of the workflows have been adjusted to use spans for the read-only arrays of messageable objects. The span is either retrieved directly from the InputRecord, or a vector of the object is requested in the user code. This PR will in the latter case return vector with SpectatorAllocator and by that avoid a copy. The user code then passes the vector as span to workers, thanks to the constructor provided by gsl::span this is completely transparent.

The second approach can handle both unserialized data and serialized data, while retrieving span directly from InputRecord allows only unserialized data (and will throw otherwise).

The only remaining code to adjust is the TPC CA Tracker now. There the buffering functionality needs to be adjusted.

@ktf
Copy link
Member

ktf commented Mar 21, 2020

Is this still needed?

@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2020

This PR did not have any update in the last 30 days. Is it still needed? Unless further action in will be closed in 5 days.

@github-actions github-actions bot added the stale label May 8, 2020
@github-actions github-actions bot closed this May 13, 2020
@ktf ktf removed the stale label May 14, 2020
@matthiasrichter matthiasrichter force-pushed the framework-io-spectator-vector branch from 5612d23 to f6f0937 Compare June 5, 2020 10:45
@matthiasrichter matthiasrichter changed the title [WIP] DPL I/O API: Prototyping spectator vector as return for InputRecord::get<std::vector<T>> [WIP] DPL I/O API: Supporting spectator vector as return for InputRecord::get<std::vector<T>> Jun 5, 2020
@matthiasrichter
Copy link
Collaborator Author

Going to be ready for merging soon, needs #3704 and #3710, and some upcoming changes.

@matthiasrichter matthiasrichter changed the title [WIP] DPL I/O API: Supporting spectator vector as return for InputRecord::get<std::vector<T>> DPL I/O API: Supporting spectator vector as return for InputRecord::get<std::vector<T>> Jun 16, 2020
@matthiasrichter matthiasrichter force-pushed the framework-io-spectator-vector branch from f6f0937 to 7346e28 Compare June 16, 2020 08:08
@matthiasrichter
Copy link
Collaborator Author

finally only requiring #3819 to be merged

Changing API for InputRecord::get<std::vector<T>>
Return type changed to vector<T const, o2::pmr::SpectatorAllocator<T const>>

A spectator vector for unserialized messages of messageable type is created
using the raw input memory without copy.
Depending on the serialization method of the incoming message, the spectator
vector is created with raw memory of the message or the deserialized object
as underlying resource

A unique instance of the spectator memory resource is kept in the
InputRecord and valid for the lifetime of the record.
@matthiasrichter matthiasrichter force-pushed the framework-io-spectator-vector branch from 7346e28 to 8a56867 Compare June 16, 2020 15:07
@matthiasrichter matthiasrichter merged commit 64d00d9 into AliceO2Group:dev Jun 19, 2020
@matthiasrichter matthiasrichter deleted the framework-io-spectator-vector branch June 19, 2020 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants