-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
2ac3537
to
a2c1b06
Compare
91bb734
to
487e668
Compare
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.
LGTM! Just one minor comment
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.
LGTM.
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.
Threading changes themselves look really good, have few other minor points
using WriteLock = std::unique_lock<std::shared_mutex>; | ||
|
||
/// Protects all the fields that can be changed by class' methods. | ||
mutable std::shared_mutex MMutex; |
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.
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?
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.
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.
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.
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.
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 added a comment.
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.
LGTM
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>
Adds some comments.
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
727d6ef
to
1597546
Compare
* [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>
* [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>
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