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

[SYCL][Graph] Makes command graph functions thread-safe #265

Merged
merged 9 commits into from
Aug 4, 2023

Conversation

mfrancepillois
Copy link
Collaborator

Adds mutual exclusions to make graph functions thread-safe.
Adds debugging functions to help check equivalence of two graphs
Improves threading tests to ensure implementation thread-safe property.

Addresses Issue: #85

@mfrancepillois mfrancepillois added the Graph Implementation Related to DPC++ implementation and testing label Jul 14, 2023
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.hpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.hpp Outdated Show resolved Hide resolved
sycl/test-e2e/Graph/Threading/begin_end_recording.cpp Outdated Show resolved Hide resolved
Base automatically changed from maxime/graph_debug_functions_print_check_sim to sycl-graph-develop July 18, 2023 07:51
sycl/source/handler.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.hpp Outdated Show resolved Hide resolved
@mfrancepillois mfrancepillois force-pushed the maxime/thread-safe branch 6 times, most recently from 91bb734 to 487e668 Compare July 24, 2023 11:45
Copy link
Collaborator

@Bensuo Bensuo left a comment

Choose a reason for hiding this comment

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

LGTM! Just one minor comment

sycl/source/detail/graph_impl.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@julianmi julianmi left a comment

Choose a reason for hiding this comment

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

LGTM.

sycl/unittests/Extensions/CommandGraph.cpp Show resolved Hide resolved
sycl/unittests/Extensions/CommandGraph.cpp Show resolved Hide resolved
Copy link
Collaborator

@EwanC EwanC left a comment

Choose a reason for hiding this comment

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

Threading changes themselves look really good, have few other minor points

sycl/source/detail/graph_impl.hpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.hpp Outdated Show resolved Hide resolved
sycl/source/detail/graph_impl.hpp Outdated Show resolved Hide resolved
sycl/unittests/Extensions/CommandGraph.cpp Outdated Show resolved Hide resolved
sycl/test-e2e/Graph/Threading/submit.cpp Outdated Show resolved Hide resolved
sycl/test-e2e/Graph/Threading/finalize.cpp Show resolved Hide resolved
using WriteLock = std::unique_lock<std::shared_mutex>;

/// Protects all the fields that can be changed by class' methods.
mutable std::shared_mutex MMutex;
Copy link
Owner

Choose a reason for hiding this comment

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

Since each executable and modifiable graph has its own mutex, and there is a 1:n mapping of modifiable to executable graphs I see the potential for a deadlock. Because the order how we lock the graph becomes important. Do we have a test in place that would catch this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I understand your comment correctly, you are asking if there is a potential risk for deadlock due to cross mutex locking due to multiple graph_exec referencing the same graph_impl, right?
Thread1: Thread2:
A.lock() B.lock()
B.lock() A.lock()
If so, given that graph_impl does not reference graph_exec, the only case where it could append is:
Thread1: Thread2:
graph_impl.begin_recording(queue)
graph_impl.add(ext_oneapi_graph(graph_exec)) queue.submit(ext_oneapi_graph(graph_exec))

However, since graph_exec is only locked with read permission (handle.cpp l.1054), this cannot create a deadlock.
Also, it is not allowed to use Explicit API and Record&Replay API at the same time for the same graph.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes your understanding is correct. It might help to document somewhere that we'll have to take the locks always in the same order, e.g. modifiable first then executable. This could help reducing the risk of introducing a deadlock in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a comment.

sycl/source/handler.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@reble reble left a comment

Choose a reason for hiding this comment

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

LGTM

mfrancepillois and others added 4 commits August 4, 2023 11:23
Addresses comments made on the first PR commit.
Mutexes are now added to Graph implementation entry points
instead of end points as was the case in the previous commit.
Adds "build_pthread_inc" lit test macro to facilitate the
compilation of the threading tests.
Removes std::barrier (std-20) dependency in threading tests.

Addresses Issue: #85
Moves threading tests that do not require a device to run to unitests
Co-authored-by: Ben Tracy <ben.tracy@codeplay.com>
mfrancepillois and others added 5 commits August 4, 2023 11:25
Co-authored-by: Pablo Reble <pablo.reble@intel.com>
Co-authored-by: Ewan Crawford <ewan@codeplay.com>
Adds dedidacted sub-class to unitests for multi-threading unitests
@mfrancepillois mfrancepillois merged commit 0d6bf2a into sycl-graph-develop Aug 4, 2023
mfrancepillois added a commit that referenced this pull request Aug 4, 2023
* [SYCL][Graph] Makes command graph functions thread-safe

Addresses comments made on the first PR commit.
Mutexes are now added to Graph implementation entry points
instead of end points as was the case in the previous commit.
Adds "build_pthread_inc" lit test macro to facilitate the
compilation of the threading tests.
Removes std::barrier (std-20) dependency in threading tests.

Addresses Issue: #85

* [SYCL][Graph] Makes command graph functions thread-safe

Moves threading tests that do not require a device to run to unitests

* Update sycl/source/detail/graph_impl.cpp

Co-authored-by: Ben Tracy <ben.tracy@codeplay.com>

* [SYCL][Graph] Makes command graph functions thread-safe

Adds some comments.

* Update sycl/source/handler.cpp

Co-authored-by: Pablo Reble <pablo.reble@intel.com>

* Update sycl/source/detail/graph_impl.hpp

Co-authored-by: Ewan Crawford <ewan@codeplay.com>

* [SYCL][Graph] Makes command graph functions thread-safe

Adds dedidacted sub-class to unitests for multi-threading unitests

* [SYCL][Graph] Makes command graph functions thread-safe

Adds comments

* [SYCL][Graph] thread-safe: bug fix after rebase

---------

Co-authored-by: Ben Tracy <ben.tracy@codeplay.com>
Co-authored-by: Pablo Reble <pablo.reble@intel.com>
Co-authored-by: Ewan Crawford <ewan@codeplay.com>
EwanC added a commit that referenced this pull request Aug 10, 2023
* [SYCL][Graph] Makes command graph functions thread-safe

Addresses comments made on the first PR commit.
Mutexes are now added to Graph implementation entry points
instead of end points as was the case in the previous commit.
Adds "build_pthread_inc" lit test macro to facilitate the
compilation of the threading tests.
Removes std::barrier (std-20) dependency in threading tests.

Addresses Issue: #85

* [SYCL][Graph] Makes command graph functions thread-safe

Moves threading tests that do not require a device to run to unitests

* Update sycl/source/detail/graph_impl.cpp

Co-authored-by: Ben Tracy <ben.tracy@codeplay.com>

* [SYCL][Graph] Makes command graph functions thread-safe

Adds some comments.

* Update sycl/source/handler.cpp

Co-authored-by: Pablo Reble <pablo.reble@intel.com>

* Update sycl/source/detail/graph_impl.hpp

Co-authored-by: Ewan Crawford <ewan@codeplay.com>

* [SYCL][Graph] Makes command graph functions thread-safe

Adds dedidacted sub-class to unitests for multi-threading unitests

* [SYCL][Graph] Makes command graph functions thread-safe

Adds comments

* [SYCL][Graph] thread-safe: bug fix after rebase

---------

Co-authored-by: Ben Tracy <ben.tracy@codeplay.com>
Co-authored-by: Pablo Reble <pablo.reble@intel.com>
Co-authored-by: Ewan Crawford <ewan@codeplay.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick Graph Implementation Related to DPC++ implementation and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants