Skip to content

Commit 3de0989

Browse files
[SYCL] Fix sycl::atomic regression (#19015)
This is a follow-up for #18839 which broke host compilation of `sycl::atomic`. The actual fix is just an addition of `#include <sycl/__spirv/spirv_ops.hpp>` to `sycl/atomic.hpp`. However, I didn't want `spirv_ops.hpp` to appear again in `sycl/detail/core.hpp` and therefore I went further to make sure that `sycl/atomic.hpp` isn't used by `sycl/accessor.hpp` which prompted other changes in this PR.
1 parent adf3592 commit 3de0989

File tree

13 files changed

+133
-45
lines changed

13 files changed

+133
-45
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include <sycl/access/access.hpp> // for target, mode
12-
#include <sycl/atomic.hpp> // for atomic
1312
#include <sycl/buffer.hpp> // for range
1413
#include <sycl/detail/accessor_iterator.hpp> // for accessor_iterator
1514
#include <sycl/detail/common.hpp> // for code_location
@@ -215,6 +214,8 @@
215214
namespace sycl {
216215
inline namespace _V1 {
217216
class stream;
217+
template <typename T, access::address_space addressSpace> class atomic;
218+
218219
namespace ext::intel::esimd::detail {
219220
// Forward declare a "back-door" access class to support ESIMD.
220221
class AccessorPrivateProxy;
@@ -1755,14 +1756,14 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
17551756
}
17561757

17571758
template <int Dims = Dimensions>
1758-
operator typename std::enable_if_t<Dims == 0 &&
1759-
AccessMode == access::mode::atomic,
1759+
operator typename std::enable_if_t<
1760+
Dims == 0 && AccessMode == access::mode::atomic,
17601761
#ifdef __ENABLE_USM_ADDR_SPACE__
1761-
atomic<DataT>
1762+
atomic<DataT, access::address_space::global_space>
17621763
#else
1763-
atomic<DataT, AS>
1764+
atomic<DataT, AS>
17641765
#endif
1765-
>() const {
1766+
>() const {
17661767
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
17671768
return atomic<DataT, AS>(multi_ptr<DataT, AS, access::decorated::yes>(
17681769
getQualifiedPtr() + LinearIndex));

sycl/include/sycl/atomic.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <sycl/__spirv/spirv_ops.hpp>
1112
#include <sycl/__spirv/spirv_types.hpp> // for Scope, MemorySemanticsMask
1213
#include <sycl/access/access.hpp> // for address_space, decorated
1314
#include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED

sycl/test-e2e/Basic/accessor/accessor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//===----------------------------------------------------------------------===//
1616
#include <cassert>
1717
#include <iostream>
18+
19+
#include <sycl/atomic.hpp>
1820
#include <sycl/detail/core.hpp>
1921

2022
struct IdxID1 {

sycl/test-e2e/Basic/compare_exchange_strong.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{build} -o %t.out
22
// RUN: %{run} %t.out
33

4+
#include <sycl/atomic.hpp>
45
#include <sycl/detail/core.hpp>
56
using namespace sycl;
67

sycl/test-e2e/Basic/parallel_for_disable_range_roundup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// RUN: %{build} -sycl-std=2020 -o %t2.out
77
// RUN: env SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE=1 %{run} %t2.out | FileCheck %s --check-prefix CHECK-ENABLED
88

9-
#include <iostream>
9+
#include <sycl/atomic.hpp>
1010
#include <sycl/detail/core.hpp>
11+
12+
#include <iostream>
1113
using namespace sycl;
1214

1315
range<1> Range1 = {0};

sycl/test-e2e/Basic/parallel_for_range_roundup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
// UNSUPPORTED: hip
2626
// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/17077
2727
//
28-
#include <iostream>
28+
#include <sycl/atomic.hpp>
2929
#include <sycl/detail/core.hpp>
3030
#include <sycl/vector.hpp>
3131

32+
#include <iostream>
33+
3234
using namespace sycl;
3335

3436
constexpr size_t MagicY = 33, MagicZ = 64;

sycl/test-e2e/DeviceLib/exp/exp-std-complex-edge-cases.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// This test checks edge cases handling for std::exp(std::complex<T>) used
22
// in SYCL kernels.
33

4+
// This include should happen before <sycl/detail/core.hpp> or otherwise NAN
5+
// may not be constexpr on some Windows configurations. See intel/llvm#19114
6+
#include <cmath>
7+
48
#include <sycl/detail/core.hpp>
59

6-
#include <cmath>
710
#include <complex>
811
#include <type_traits>
912

sycl/test-e2e/Regression/atomic_load.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %{build} -o %t.out
22
// RUN: %{run} %t.out
3+
#include <sycl/atomic.hpp>
34
#include <sycl/detail/core.hpp>
5+
46
using namespace sycl;
57

68
template <typename T> class foo;

sycl/test-e2e/Regression/implicit_atomic_conversion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %{build} -Wno-error=deprecated-declarations -o %t.out
22
// RUN: %{run} %t.out
33

4+
#include <sycl/atomic.hpp>
45
#include <sycl/detail/core.hpp>
56

67
using namespace sycl;

sycl/test-e2e/XPTI/buffer/accessors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#else
1111

12+
#include <sycl/atomic.hpp>
1213
#include <sycl/detail/core.hpp>
1314

1415
using namespace sycl::access;

sycl/test/include_deps/sycl_accessor.hpp.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,21 @@
77
// CHECK-NEXT: accessor.hpp
88
// CHECK-NEXT: access/access.hpp
99
// CHECK-NEXT: detail/defines_elementary.hpp
10-
// CHECK-NEXT: atomic.hpp
11-
// CHECK-NEXT: __spirv/spirv_types.hpp
12-
// CHECK-NEXT: detail/defines.hpp
13-
// CHECK-NEXT: detail/helpers.hpp
14-
// CHECK-NEXT: detail/export.hpp
15-
// CHECK-NEXT: memory_enums.hpp
16-
// CHECK-NEXT: __spirv/spirv_vars.hpp
17-
// CHECK-NEXT: multi_ptr.hpp
18-
// CHECK-NEXT: aliases.hpp
19-
// CHECK-NEXT: detail/address_space_cast.hpp
20-
// CHECK-NEXT: detail/type_traits.hpp
21-
// CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp
22-
// CHECK-NEXT: half_type.hpp
23-
// CHECK-NEXT: bit_cast.hpp
24-
// CHECK-NEXT: detail/iostream_proxy.hpp
25-
// CHECK-NEXT: aspects.hpp
26-
// CHECK-NEXT: info/aspects.def
27-
// CHECK-NEXT: info/aspects_deprecated.def
2810
// CHECK-NEXT: buffer.hpp
2911
// CHECK-NEXT: backend_types.hpp
3012
// CHECK-NEXT: detail/array.hpp
3113
// CHECK-NEXT: exception.hpp
14+
// CHECK-NEXT: detail/export.hpp
3215
// CHECK-NEXT: detail/string.hpp
3316
// CHECK-NEXT: detail/common.hpp
3417
// CHECK-NEXT: stl_wrappers/cassert
3518
// CHECK-NEXT: stl_wrappers/assert.h
19+
// CHECK-NEXT: __spirv/spirv_vars.hpp
20+
// CHECK-NEXT: __spirv/spirv_types.hpp
21+
// CHECK-NEXT: detail/defines.hpp
22+
// CHECK-NEXT: detail/helpers.hpp
23+
// CHECK-NEXT: memory_enums.hpp
24+
// CHECK-NEXT: detail/iostream_proxy.hpp
3625
// CHECK-NEXT: detail/is_device_copyable.hpp
3726
// CHECK-NEXT: detail/owner_less_base.hpp
3827
// CHECK-NEXT: detail/impl_utils.hpp
@@ -51,6 +40,16 @@
5140
// CHECK-NEXT: ur_api.h
5241
// CHECK-NEXT: detail/accessor_iterator.hpp
5342
// CHECK-NEXT: detail/generic_type_traits.hpp
43+
// CHECK-NEXT: aliases.hpp
44+
// CHECK-NEXT: detail/type_traits.hpp
45+
// CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp
46+
// CHECK-NEXT: half_type.hpp
47+
// CHECK-NEXT: bit_cast.hpp
48+
// CHECK-NEXT: aspects.hpp
49+
// CHECK-NEXT: info/aspects.def
50+
// CHECK-NEXT: info/aspects_deprecated.def
51+
// CHECK-NEXT: multi_ptr.hpp
52+
// CHECK-NEXT: detail/address_space_cast.hpp
5453
// CHECK-NEXT: ext/oneapi/bfloat16.hpp
5554
// CHECK-NEXT: detail/handler_proxy.hpp
5655
// CHECK-NEXT: pointers.hpp

sycl/test/include_deps/sycl_detail_core.hpp.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,21 @@
88
// CHECK-NEXT: accessor.hpp
99
// CHECK-NEXT: access/access.hpp
1010
// CHECK-NEXT: detail/defines_elementary.hpp
11-
// CHECK-NEXT: atomic.hpp
12-
// CHECK-NEXT: __spirv/spirv_types.hpp
13-
// CHECK-NEXT: detail/defines.hpp
14-
// CHECK-NEXT: detail/helpers.hpp
15-
// CHECK-NEXT: detail/export.hpp
16-
// CHECK-NEXT: memory_enums.hpp
17-
// CHECK-NEXT: __spirv/spirv_vars.hpp
18-
// CHECK-NEXT: multi_ptr.hpp
19-
// CHECK-NEXT: aliases.hpp
20-
// CHECK-NEXT: detail/address_space_cast.hpp
21-
// CHECK-NEXT: detail/type_traits.hpp
22-
// CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp
23-
// CHECK-NEXT: half_type.hpp
24-
// CHECK-NEXT: bit_cast.hpp
25-
// CHECK-NEXT: detail/iostream_proxy.hpp
26-
// CHECK-NEXT: aspects.hpp
27-
// CHECK-NEXT: info/aspects.def
28-
// CHECK-NEXT: info/aspects_deprecated.def
2911
// CHECK-NEXT: buffer.hpp
3012
// CHECK-NEXT: backend_types.hpp
3113
// CHECK-NEXT: detail/array.hpp
3214
// CHECK-NEXT: exception.hpp
15+
// CHECK-NEXT: detail/export.hpp
3316
// CHECK-NEXT: detail/string.hpp
3417
// CHECK-NEXT: detail/common.hpp
3518
// CHECK-NEXT: stl_wrappers/cassert
3619
// CHECK-NEXT: stl_wrappers/assert.h
20+
// CHECK-NEXT: __spirv/spirv_vars.hpp
21+
// CHECK-NEXT: __spirv/spirv_types.hpp
22+
// CHECK-NEXT: detail/defines.hpp
23+
// CHECK-NEXT: detail/helpers.hpp
24+
// CHECK-NEXT: memory_enums.hpp
25+
// CHECK-NEXT: detail/iostream_proxy.hpp
3726
// CHECK-NEXT: detail/is_device_copyable.hpp
3827
// CHECK-NEXT: detail/owner_less_base.hpp
3928
// CHECK-NEXT: detail/impl_utils.hpp
@@ -52,6 +41,16 @@
5241
// CHECK-NEXT: ur_api.h
5342
// CHECK-NEXT: detail/accessor_iterator.hpp
5443
// CHECK-NEXT: detail/generic_type_traits.hpp
44+
// CHECK-NEXT: aliases.hpp
45+
// CHECK-NEXT: detail/type_traits.hpp
46+
// CHECK-NEXT: detail/type_traits/vec_marray_traits.hpp
47+
// CHECK-NEXT: half_type.hpp
48+
// CHECK-NEXT: bit_cast.hpp
49+
// CHECK-NEXT: aspects.hpp
50+
// CHECK-NEXT: info/aspects.def
51+
// CHECK-NEXT: info/aspects_deprecated.def
52+
// CHECK-NEXT: multi_ptr.hpp
53+
// CHECK-NEXT: detail/address_space_cast.hpp
5554
// CHECK-NEXT: ext/oneapi/bfloat16.hpp
5655
// CHECK-NEXT: detail/handler_proxy.hpp
5756
// CHECK-NEXT: pointers.hpp

sycl/test/regression/atomic.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Wno-deprecated-declarations -Xclang -verify %s
2+
// expected-no-diagnostics
3+
4+
#include <sycl/atomic.hpp>
5+
#include <sycl/multi_ptr.hpp>
6+
7+
SYCL_EXTERNAL void
8+
store(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
9+
int value) {
10+
sycl::atomic<int> a(mptr);
11+
a.store(value);
12+
}
13+
14+
SYCL_EXTERNAL int
15+
load(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr) {
16+
sycl::atomic<int> a(mptr);
17+
return a.load();
18+
}
19+
20+
SYCL_EXTERNAL int
21+
exchange(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
22+
int value) {
23+
sycl::atomic<int> a(mptr);
24+
return a.exchange(value);
25+
}
26+
27+
SYCL_EXTERNAL int
28+
fetch_add(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
29+
int value) {
30+
sycl::atomic<int> a(mptr);
31+
return a.fetch_add(value);
32+
}
33+
34+
SYCL_EXTERNAL int
35+
fetch_sub(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
36+
int value) {
37+
sycl::atomic<int> a(mptr);
38+
return a.fetch_sub(value);
39+
}
40+
41+
SYCL_EXTERNAL int
42+
fetch_and(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
43+
int value) {
44+
sycl::atomic<int> a(mptr);
45+
return a.fetch_and(value);
46+
}
47+
48+
SYCL_EXTERNAL int
49+
fetch_or(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
50+
int value) {
51+
sycl::atomic<int> a(mptr);
52+
return a.fetch_or(value);
53+
}
54+
55+
SYCL_EXTERNAL int
56+
fetch_xor(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
57+
int value) {
58+
sycl::atomic<int> a(mptr);
59+
return a.fetch_xor(value);
60+
}
61+
62+
SYCL_EXTERNAL int
63+
fetch_min(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
64+
int value) {
65+
sycl::atomic<int> a(mptr);
66+
return a.fetch_min(value);
67+
}
68+
69+
SYCL_EXTERNAL int
70+
fetch_max(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr,
71+
int value) {
72+
sycl::atomic<int> a(mptr);
73+
return a.fetch_max(value);
74+
}

0 commit comments

Comments
 (0)