-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Guard access to MCreateShadowCopy (#15273)
Fixes a flaky failure when getting write access to a buffer from multiple threads. --------- Co-authored-by: Artur Gainullin <artur.gainullin@intel.com>
- Loading branch information
1 parent
fe9aa1e
commit 3d07790
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
#include <sycl/detail/core.hpp> | ||
|
||
#include <cassert> | ||
#include <thread> | ||
#include <vector> | ||
|
||
constexpr int NThreads = 8; | ||
|
||
class KernelA; | ||
|
||
void threadFunction(sycl::buffer<int, 1> &Buf) { | ||
sycl::queue Q; | ||
Q.submit([&](sycl::handler &Cgh) { | ||
auto Acc = Buf.get_access<sycl::access::mode::read_write>(Cgh); | ||
Cgh.single_task<class KernelA>([=]() { Acc[0] += 1; }); | ||
}); | ||
} | ||
int main() { | ||
std::vector<std::thread> Threads; | ||
Threads.reserve(NThreads); | ||
|
||
int Val = 0; | ||
{ | ||
sycl::buffer<int, 1> Buf(&Val, sycl::range<1>(1)); | ||
sycl::queue Q; | ||
|
||
for (int I = 0; I < NThreads; ++I) | ||
Threads.emplace_back(threadFunction, std::ref(Buf)); | ||
for (auto &t : Threads) | ||
t.join(); | ||
} | ||
assert(Val == NThreads); | ||
} |