From cfd54cb021443495d7c4060f0245b5b846cc970b Mon Sep 17 00:00:00 2001 From: Maxime France-Pillois Date: Tue, 29 Aug 2023 17:10:35 +0100 Subject: [PATCH] [SYCL][Graph] Fixes multithread finalize unitest bug (#314) * [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 --------- Co-authored-by: Ewan Crawford --- sycl/unittests/Extensions/CommandGraph.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sycl/unittests/Extensions/CommandGraph.cpp b/sycl/unittests/Extensions/CommandGraph.cpp index b4746e1e745b8..bac29f791436d 100644 --- a/sycl/unittests/Extensions/CommandGraph.cpp +++ b/sycl/unittests/Extensions/CommandGraph.cpp @@ -1931,18 +1931,21 @@ TEST_F(MultiThreadGraphTest, RecordAddNodesInOrderQueue) { TEST_F(MultiThreadGraphTest, Finalize) { addKernels(Graph); + std::mutex MutexMap; + std::map> GraphsExecMap; auto FinalizeGraph = [&](int ThreadNum) { SyncPoint.wait(); auto GraphExec = Graph.finalize(); + Queue.submit([&](sycl::handler &CGH) { CGH.ext_oneapi_graph(GraphExec); }); + std::lock_guard Guard(MutexMap); GraphsExecMap.insert( std::map>:: value_type(ThreadNum, GraphExec)); - Queue.submit([&](sycl::handler &CGH) { CGH.ext_oneapi_graph(GraphExec); }); }; for (unsigned i = 0; i < NumThreads; ++i) {