Skip to content

Commit

Permalink
[SYCL][Graph] Fixes multithread finalize unitest bug (#314)
Browse files Browse the repository at this point in the history
* [SYCL][Graph] Fixes multithread finalize unitest bug

std::map insertions are not thread-safe causing an issue in the multithread finalize test.
This commit adds a mutex to prevent races when inserting data in the map.

* Update sycl/unittests/Extensions/CommandGraph.cpp

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

---------

Co-authored-by: Ewan Crawford <ewan@codeplay.com>
  • Loading branch information
mfrancepillois and EwanC committed Aug 29, 2023
1 parent 6de9657 commit cfd54cb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sycl/unittests/Extensions/CommandGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,18 +1931,21 @@ TEST_F(MultiThreadGraphTest, RecordAddNodesInOrderQueue) {
TEST_F(MultiThreadGraphTest, Finalize) {
addKernels(Graph);

std::mutex MutexMap;

std::map<int,
experimental::command_graph<experimental::graph_state::executable>>
GraphsExecMap;
auto FinalizeGraph = [&](int ThreadNum) {
SyncPoint.wait();
auto GraphExec = Graph.finalize();
Queue.submit([&](sycl::handler &CGH) { CGH.ext_oneapi_graph(GraphExec); });

std::lock_guard<std::mutex> Guard(MutexMap);
GraphsExecMap.insert(
std::map<int, experimental::command_graph<
experimental::graph_state::executable>>::
value_type(ThreadNum, GraphExec));
Queue.submit([&](sycl::handler &CGH) { CGH.ext_oneapi_graph(GraphExec); });
};

for (unsigned i = 0; i < NumThreads; ++i) {
Expand Down

0 comments on commit cfd54cb

Please sign in to comment.