-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Document a way to flow graph can be attached to arbitrary task_arena #785
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ab56ed
Document a way to flow graph can be attached to arbitrary task_arena
69b4ed2
Updating with comments during code review.
ea72ed2
Update doc/main/tbb_userguide/attach_flow_graph_to_arena.rst
e44112e
Update doc/main/tbb_userguide/attach_flow_graph_to_arena.rst
286d1d8
Updating with comments during code review.
2ed8684
Update doc/main/tbb_userguide/attach_flow_graph_to_arena.rst
28063bd
Update doc/main/tbb_userguide/snippets/flow_graph_examples.cpp
6e848e2
Update doc/main/tbb_userguide/attach_flow_graph_to_arena.rst
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| .. _attach_flow_graph_to_arena: | ||
|
|
||
| Attach Flow Graph to an Arbitrary Task Arena | ||
| ====================== | ||
|
|
||
|
|
||
| |short_name| ``task_arena`` interface provides mechanisms to guide tasks execution | ||
| within the arena by setting the preferred computation units or restricting part of | ||
| computation units. In some cases, you may want to use mechanisms within a flow graph. | ||
|
|
||
| During its construction, a ``graph`` object attaches to the arena, in which the constructing | ||
| thread occupies a slot. | ||
|
|
||
| This example shows how to set the most performant core type as the preferred one | ||
| for a graph execution: | ||
|
|
||
|
|
||
| .. literalinclude:: ./snippets/flow_graph_examples.cpp | ||
| :language: c++ | ||
| :start-after: /*begin_attach_to_arena_1*/ | ||
| :end-before: /*end_attach_to_arena_1*/ | ||
|
|
||
|
|
||
| A ``graph`` object can be reattached to a different ``task_arena`` by calling | ||
| the ``graph::reset()`` function. It reinitializes and reattaches the ``graph`` to | ||
| the task arena instance, inside which the ``graph::reset()`` method is executed. | ||
|
|
||
| This example shows how to reattach existing graph to an arena with the most performant | ||
| core type as the preferred one for a work execution. Whenever a task is spawned on behalf | ||
| of the graph, it is spawned in the arena of a graph it is attached to, disregarding | ||
| the arena of the thread that the task is spawned from: | ||
|
|
||
|
|
||
| .. literalinclude:: ./snippets/flow_graph_examples.cpp | ||
| :language: c++ | ||
| :start-after: /*begin_attach_to_arena_2*/ | ||
| :end-before: /*end_attach_to_arena_2*/ | ||
|
|
||
| See the following topics to learn more: | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 4 | ||
|
|
||
| ../tbb_userguide/Guiding_Task_Scheduler_Execution | ||
| ../tbb_userguide/work_isolation | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| Copyright (c) 2005-2022 Intel Corporation | ||
vlserov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| /* Flow Graph Code Example for the Userguide. | ||
| */ | ||
|
|
||
| //! Enable extended task_arena constraints feature for supporting Intel Hybrid Technology | ||
| //! and Intel Hyper-Threading Technology. | ||
| #define TBB_PREVIEW_TASK_ARENA_CONSTRAINTS_EXTENSION 1 | ||
|
|
||
| #include <oneapi/tbb/flow_graph.h> | ||
| #include <vector> | ||
|
|
||
| using namespace tbb::flow; | ||
|
|
||
| //! Example shows how to set the most performant core type as the preferred one | ||
| //! for a graph execution. | ||
| static void flow_graph_attach_to_arena_1() { | ||
| /*begin_attach_to_arena_1*/ | ||
| std::vector<tbb::core_type_id> core_types = tbb::info::core_types(); | ||
| tbb::task_arena arena( | ||
| tbb::task_arena::constraints{}.set_core_type(core_types.back()) | ||
| ); | ||
|
|
||
| arena.execute( [&]() { | ||
| graph g; | ||
| function_node< int > f( g, unlimited, []( int ) { | ||
| /*the most performant core type is defined as preferred.*/ | ||
| } ); | ||
| f.try_put(1); | ||
| g.wait_for_all(); | ||
| } ); | ||
| /*end_attach_to_arena_1*/ | ||
| } | ||
|
|
||
| //! Reattach existing graph to an arena with the most performant core type as | ||
| //! the preferred one for a work execution. | ||
| static void flow_graph_attach_to_arena_2() { | ||
| /*begin_attach_to_arena_2*/ | ||
| graph g; | ||
| function_node< int > f( g, unlimited, []( int ) { | ||
| /*the most performant core type is defined as preferred.*/ | ||
| } ); | ||
|
|
||
| std::vector<tbb::core_type_id> core_types = tbb::info::core_types(); | ||
| tbb::task_arena arena( | ||
| tbb::task_arena::constraints{}.set_core_type(core_types.back()) | ||
| ); | ||
|
|
||
| arena.execute( [&]() { | ||
| g.reset(); | ||
| } ); | ||
| f.try_put(1); | ||
| g.wait_for_all(); | ||
| /*end_attach_to_arena_2*/ | ||
| } | ||
|
|
||
| int main() { | ||
| flow_graph_attach_to_arena_1(); | ||
| flow_graph_attach_to_arena_2(); | ||
|
|
||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.