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

Document a way to flow graph can be attached to arbitrary task_arena #785

Merged
merged 8 commits into from
Mar 9, 2022

Conversation

vlserov
Copy link

@vlserov vlserov commented Feb 22, 2022

Description

Adding documentation to describes a way to flow::graph can be attached to arbitrary task_arena

Fixes # - issue number(s) if exists

  • - git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details)

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

  • bug fix - change that fixes an issue
  • new feature - change that adds functionality
  • tests - change in tests
  • infrastructure - change in infrastructure and CI
  • documentation - documentation update

Tests

  • added - required for new features and some bug fixes
  • not needed

Documentation

  • updated in # - add PR number
  • needs to be updated
  • not needed

Breaks backward compatibility

  • Yes
  • No
  • Unknown

Notify the following users

@aleksei-fedotov @alexandraepan

Other information

Signed-off-by: Serov, Vladimir <vladimir.serov@intel.com>
@@ -0,0 +1,62 @@
.. _attach_flow_graph_to_arena:

Attach Flow Graph to arbitrary Task Arena
Copy link
Contributor

@aepanchi aepanchi Feb 22, 2022

Choose a reason for hiding this comment

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

Suggested change
Attach Flow Graph to arbitrary Task Arena
Attach Flow Graph to an Arbitrary Task Arena

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is worth adding in which cases a user may need to attach flow graph to task arena

Copy link
Author

Choose a reason for hiding this comment

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

Changes has been applied.

======================


During construction a ``graph`` object captures a reference to the arena of the thread that
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
During construction a ``graph`` object captures a reference to the arena of the thread that
During construction, a ``graph`` object captures a reference to the arena of the thread that



During construction a ``graph`` object captures a reference to the arena of the thread that
constructed the object. Whenever a task is spawned to execute work in the graph, the tasks
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
constructed the object. Whenever a task is spawned to execute work in the graph, the tasks
constructed the object. When a task is spawned to execute work in a graph, the tasks


During construction a ``graph`` object captures a reference to the arena of the thread that
constructed the object. Whenever a task is spawned to execute work in the graph, the tasks
are spawned in this arena, not in the arena of the that caused the task to be spawned.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
are spawned in this arena, not in the arena of the that caused the task to be spawned.
are spawned in that arena, not in the arena that caused the task to be spawned.

During construction a ``graph`` object captures a reference to the arena of the thread that
constructed the object. Whenever a task is spawned to execute work in the graph, the tasks
are spawned in this arena, not in the arena of the that caused the task to be spawned.
All tasks are spawned into a single arena, the arena of the thread that constructed the graph
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
All tasks are spawned into a single arena, the arena of the thread that constructed the graph
All tasks are spawned into a single arena that constructed a graph

} );


Since the main thread constructs the ``graph`` object, the ``graph`` will use the default arena,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Since the main thread constructs the ``graph`` object, the ``graph`` will use the default arena,
Since the main thread constructs the ``graph`` object, the ``graph`` uses the default arena.



Since the main thread constructs the ``graph`` object, the ``graph`` will use the default arena,
which we initialize with eight slots. After calling ``reset`` function to reinitialize
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
which we initialize with eight slots. After calling ``reset`` function to reinitialize
Such an arena is initialized with eight slots. After calling the ``reset`` function to reinitialize


Since the main thread constructs the ``graph`` object, the ``graph`` will use the default arena,
which we initialize with eight slots. After calling ``reset`` function to reinitialize
the graph and nodes executes in arena ``arena``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not clear what is this sentence for.

Copy link
Author

Choose a reason for hiding this comment

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

Removed as not necessary.

the graph and nodes executes in arena ``arena``.


So performance tuning optimizations which is described in sections below can be applied for
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
So performance tuning optimizations which is described in sections below can be applied for
A performance tuning optimization can be applied for



So performance tuning optimizations which is described in sections below can be applied for
flow graphs as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
flow graphs as well.
flow graphs as well. See the following topics to learn more.

Copy link
Author

Choose a reason for hiding this comment

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

Applied

Copy link
Contributor

@aleksei-fedotov aleksei-fedotov left a comment

Choose a reason for hiding this comment

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

Please see my comments below.

Also, let's move source code into separate files so that they are automatically tested when the automation task for testing of samples from the docs is ready.

Signed-off-by: Serov, Vladimir <vladimir.serov@intel.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Alexandra Epanchinzeva <alexandra.epanchinzeva@intel.com>
Comment on lines 12 to 14
thread occupies a slot. Whenever a task is spawned on behalf of the graph, it is spawned
in the arena of the graph it is attached to, disregarding the arena of the thread
which is caused a task to be spawned.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the second sentence in this paragraph better be moved closer to the second example as the example now shows this explicitly and so may raise questions of readers.

Perhaps, the best place for it is right after the example introduction words, i.e. line #41.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree here

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.

Comment on lines 47 to 59
graph g;
function_node< int > f( g, unlimited, []( int i ) {
/*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();
Copy link
Contributor

Choose a reason for hiding this comment

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

I also asked a question about moving the code into separate source file for further simpler testing.
I found this approach that can work for us. Can we use it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@aleksei-fedotov We definitely can make it work :)

Copy link
Author

Choose a reason for hiding this comment

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

Moved to separate source file

During its construction a ``graph`` object attaches to the arena, in which the constructing
thread occupies a slot. Whenever a task is spawned on behalf of the graph, it is spawned
in the arena of the graph it is attached to, disregarding the arena of the thread
which is caused a task to be spawned.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
which is caused a task to be spawned.
that the task is spawned from.

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.

Comment on lines 12 to 14
thread occupies a slot. Whenever a task is spawned on behalf of the graph, it is spawned
in the arena of the graph it is attached to, disregarding the arena of the thread
which is caused a task to be spawned.
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree here

in the arena of the graph it is attached to, disregarding the arena of the thread
which is caused a task to be spawned.

The example shows how to set the most performant core type as preferable for graph execution:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The example shows how to set the most performant core type as preferable for graph execution:
This example shows how to set the most performant core type as the preferred one for a graph execution:

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.


A ``graph`` object can be reattached to a different ``task_arena`` by calling
the ``graph::reset()`` function. This reinitializes the ``graph`` and reattaches
it to the task arena instance, inside which the ``graph::reset()`` method is executed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it to the task arena instance, inside which the ``graph::reset()`` method is executed.
the ``graph`` to the task arena instance, inside which the ``graph::reset()`` method is executed.

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.

the ``graph::reset()`` function. This reinitializes the ``graph`` and reattaches
it to the task arena instance, inside which the ``graph::reset()`` method is executed.

The example shows how reattach existing graph to an arena with the most performant core type
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The example shows how reattach existing graph to an arena with the most performant core type
This example shows how to reattach existing graph to an arena with the most performant core type

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.

it to the task arena instance, inside which the ``graph::reset()`` method is executed.

The example shows how reattach existing graph to an arena with the most performant core type
as preferable for work execution:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
as preferable for work execution:
as the preferred one for a work execution:

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.

Comment on lines 47 to 59
graph g;
function_node< int > f( g, unlimited, []( int i ) {
/*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();
Copy link
Contributor

Choose a reason for hiding this comment

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

@aleksei-fedotov We definitely can make it work :)

f.try_put(1);
g.wait_for_all();

See the following topics to learn more.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
See the following topics to learn more.
See the following topics to learn more:

Copy link
Author

Choose a reason for hiding this comment

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

Updated with suggested changes.

Vladimir Serov and others added 3 commits March 5, 2022 12:58
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
Moving examples to separate source file.

Signed-off-by: Serov, Vladimir <vladimir.serov@intel.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Alexandra Epanchinzeva <alexandra.epanchinzeva@intel.com>
Copy link
Contributor

@aepanchi aepanchi left a comment

Choose a reason for hiding this comment

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

the rest looks good!

Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
Copy link
Contributor

@aleksei-fedotov aleksei-fedotov left a comment

Choose a reason for hiding this comment

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

Now looks much better to me! There is a couple of questions left, though.

Vladimir Serov and others added 2 commits March 9, 2022 12:45
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
@vlserov vlserov requested a review from aleksei-fedotov March 9, 2022 09:47
Copy link
Contributor

@aleksei-fedotov aleksei-fedotov left a comment

Choose a reason for hiding this comment

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

Thanks Vladimir!

Hope readers won't be nit-picking regarding the other details necessary to make the example fully compilable.

@vlserov vlserov requested a review from aepanchi March 9, 2022 11:52
@vlserov vlserov merged commit a938322 into master Mar 9, 2022
@vlserov vlserov deleted the dev/vserov/flow_graph_arena branch March 9, 2022 12:04
ValentinaKats pushed a commit to ValentinaKats/oneTBB that referenced this pull request May 20, 2022
…xlfoundation#785)

* Document a way to flow graph can be attached to arbitrary task_arena

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.

Signed-off-by: Serov, Vladimir <vladimir.serov@intel.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Alexandra Epanchinzeva <alexandra.epanchinzeva@intel.com>
(cherry picked from commit a938322)
timmiesmith pushed a commit that referenced this pull request Aug 9, 2022
* Update pull_request_template.md (#751)

Signed-off-by: Alexandra Epanchinzeva alexandra.epanchinzeva@intel.com
(cherry picked from commit 4eda0f9)

* Update CONTRIBUTING.md (#765)

(cherry picked from commit e274a9e)

* Documentation update for unpreview `task_handle` and related stuff (#755)

* Unpreview task_handle and related stuff

Signed-off-by: Anton Potapov <anton.potapov@intel.com>
Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
(cherry picked from commit fd76f45)

* Update conf.py (#774)

(cherry picked from commit 6666292)

* Actualize documentation about proportional splitting constructor in Range (#728)

Actualize documentation about proportional splitting

Signed-off-by: Fedotov, Aleksei <aleksei.fedotov@intel.com>
(cherry picked from commit e5cbe50)

* Update doc structure and add new files (#791)

(cherry picked from commit ce0d258)

* Instruction for building the docs locally  (#778)

(cherry picked from commit e386960)

* Document a way to flow graph can be attached to arbitrary task_arena (#785)

* Document a way to flow graph can be attached to arbitrary task_arena

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.

Signed-off-by: Serov, Vladimir <vladimir.serov@intel.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Alexandra Epanchinzeva <alexandra.epanchinzeva@intel.com>
(cherry picked from commit a938322)

* Add topic about "Lazy Initiliazation" pattern to Design patterns (#790)

New topic about Lazy initialization pattern and how it can be implemented using oneapi::tbb::collaborative_call_once has been added.

Signed-off-by: Ilya Isaev <ilya.isaev@intel.com>
(cherry picked from commit 1da8f0d)

* Update Get Started Guide (#803)

(cherry picked from commit 0502372)

* Update intro_gsg.rst (#808)

(cherry picked from commit 2c4f282)

* Update conf.py (#810)

(cherry picked from commit 0a0a592)

* TBB DOC : Dev Guide: Task Scheduler Bypass and How Does Task Scheduler Works (#521)

* TBB DOC : Dev Guide: Task Scheduler Bypass and How Task Scheduler
Works

Signed-off-by: Anton Potapov <anton.potapov@intel.com>
Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>

(cherry picked from commit ed9d4b5)

* Update intro_gsg.rst (#811)

(cherry picked from commit efea993)

* Update conf.py (#812)

(cherry picked from commit 3859d11)

* Update examples.rst (#816)

(cherry picked from commit 4aa0b0b)

* Update layout.html (#815)

(cherry picked from commit 3e352b4)

* Update RELEASE_NOTES.md for oneTBB 2021.6 (#835)

(cherry picked from commit faaf43c)

Co-authored-by: Alexandra <alexandra.epanchinzeva@intel.com>
Co-authored-by: Anton Potapov <potapov.slash.co@gmail.com>
Co-authored-by: Aleksei Fedotov <aleksei.fedotov@intel.com>
Co-authored-by: Vladimir Serov <vladimir.serov@intel.com>
Co-authored-by: Ilya Isaev <ilya.isaev@intel.com>
Co-authored-by: Anton Potapov <anton.potapov@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants