-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Flow Graph - remove C++03 legacy #945
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
base: master
Are you sure you want to change the base?
Conversation
|
What is the status of this PR? |
|
Thank you for expressing your interest into this PR. |
|
@kboyarinov, thanks for reaching out. I have been using oneTBB flow for a while, and have greatly enjoyed it. One of the use cases I have is that some algorithms/nodes invoke library code that is not thread-safe. It is not sufficient to simply specify a concurrency level of 1 for that node, because there are other nodes that might also call the same library at the same time. Instead, for nodes that have to call the same thread-unsafe resource, I use a join node where one of the input ports receives a serialization token--only one token exists in the full graph for a given thread-unsafe library, and the node will not execute until it receives the token. And sometimes more than one token is required if there are more than one thread-unsafe libraries that must be invoked by the node. I also use join nodes, though, with tag-matching to ensure that all of the arguments required by a particular algorithm are available before the algorithm is executed. If the algorithm requires Does that help explain the situation? I can also produce a diagram if that would be helpful. |
| template <std::size_t N> | ||
| struct edge_maker { | ||
| template <typename Sender, typename NodeType> | ||
| static void make(Sender& sender, NodeType& node) { | ||
| oneapi::tbb::flow::make_edge(sender, oneapi::tbb::flow::input_port<N - 1>(node)); | ||
| edge_maker<N - 1>::make(sender, node); | ||
| } | ||
|
|
||
| template <typename Sender, typename NodeType> | ||
| static void make(std::vector<Sender>& senders, NodeType& node) { | ||
| oneapi::tbb::flow::make_edge(senders[N - 1], oneapi::tbb::flow::input_port<N - 1>(node)); | ||
| edge_maker<N - 1>::make(senders, node); | ||
| } | ||
| }; | ||
|
|
||
| template <> | ||
| struct edge_maker<0> { | ||
| template <typename Sender, typename NodeType> | ||
| static void make(Sender&, NodeType&) {} | ||
| }; |
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.
Maybe move graph-related helpers into common "graph-helpers" header?
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.
Moved to common/graph_utils.h
| for (auto& buffer : buffers) { | ||
| make_edge(submitter, buffer); | ||
| } |
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.
Add a helper in edge_maker for this as well?
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 would prefer to keep it as-is since it can be implemented as a runtime loop and edge_maker is intended to implement a compile-time loop since input_port<N> should be used. I don't think it makes sense to overcomplicate it by implementing using a compile-time logic.
|
|
||
| std::size_t body_counter = 0; | ||
| function_node<output_tuple> function(g, serial, [&](const output_tuple& tuple) { | ||
| tuple_assert<N>(tuple, message); |
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.
Rename to something more readable? For example,
| tuple_assert<N>(tuple, message); | |
| assert_all_items_equal_to<N>(tuple, message); |
Similarly to edge_maker, this can also be extended to support other containers.
By the way, std::get already supports other collections: std::array, std::pair, std::variant, etc. So, such helper will automatically support them.
Therefore, consider renaming (since tuple could already be not necessarily a tuple) and moving this useful helper to some common place.
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.
Renamed tuple_assert, moved to common header and renamed first argument to be tuple-like.
I would not add tuple-like support to edge_maker now since it will require adding constraint that std::get is valid to disambiguate with the existing overload of edge_maker::make. It is not used in the existing tests, so I would it as-is for now.
| unfolded_join_node(graph &g) | ||
| : base_type(g, | ||
| func_initializer_type(new type_to_key_function_body_leaf<Types, K, | ||
| key_from_message_body<K, Types>>(key_from_message_body<K, Types>())...)) | ||
| {} |
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.
Can we also replace type_to_key_function_body[_leaf] types with std::function?
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 think it is a good idea, but I would consider it as part of the separate PR.
Otherwise, this one would be overcomplicated
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Co-authored-by: Aleksei Fedotov <[email protected]>
Description
Rewrite Flow Graph join_node and indexer_node to use variadic templates.
Follow up for #437
Fixes # - issue number(s) if exists
Type of change
Choose one or multiple, leave empty if none of the other choices apply
Add a respective label(s) to PR if you have permissions
Tests
Documentation
Breaks backward compatibility
Notify the following users
List users with
@to send notificationsOther information