Skip to content

Commit ce7725d

Browse files
[SYCL] Fix zero dimension accessors on FPGA in AOT mode (#4458)
Zero dimension accessors aren't working on FPGA with atomic data. When aot compiling for FPGA we use address space global_device_space instead of just global_space. This seems to be confusing the specialization for the zero dimension accessor. Not overspecifying the address space fixes the problem with no other change in functionality. Signed-off-by: Chris Perkins <[email protected]>
1 parent bcbaa50 commit ce7725d

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

sycl/include/CL/sycl/accessor.hpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -1560,12 +1560,17 @@ class accessor :
15601560
}
15611561

15621562
template <int Dims = Dimensions>
1563-
operator typename detail::enable_if_t<
1564-
Dims == 0 && AccessMode == access::mode::atomic, atomic<DataT, AS>>()
1565-
const {
1566-
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
1567-
return atomic<DataT, AS>(
1568-
multi_ptr<DataT, AS>(getQualifiedPtr() + LinearIndex));
1563+
operator typename detail::enable_if_t<Dims == 0 &&
1564+
#ifdef __ENABLE_USM_ADDR_SPACE__
1565+
AccessMode == access::mode::atomic,
1566+
atomic<DataT>>() const {
1567+
#else
1568+
AccessMode == access::mode::atomic,
1569+
atomic<DataT, AS>>() const {
1570+
#endif
1571+
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
1572+
return atomic<DataT, AS>(
1573+
multi_ptr<DataT, AS>(getQualifiedPtr() + LinearIndex));
15691574
}
15701575

15711576
template <int Dims = Dimensions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only %s -o %t.out
2+
// RUN: %clangxx -fsycl -fsyntax-only -fsycl-targets=spir64_fpga %s -o %t.out
3+
4+
// When using zero dimension accessors with atomic access we
5+
// want to make sure they are compiling correctly on all devices,
6+
// especially FPGA which changes some of the template specializations
7+
// with the __ENABLE_USM_ADDR_SPACE__ macro.
8+
9+
#include <CL/sycl.hpp>
10+
11+
using namespace sycl;
12+
13+
using atomic_t = sycl::atomic<int>;
14+
15+
// store() is defined for both int and atomic
16+
void store(int &foo, int value) { foo = value; }
17+
18+
void store(atomic_t foo, int value) { foo.store(value); }
19+
20+
int main(int argc, char *argv[]) {
21+
22+
queue q(default_selector{});
23+
24+
// Accessor with dimensionality 0.
25+
{
26+
try {
27+
int data = -1;
28+
int atomic_data = -1;
29+
{
30+
sycl::buffer<int, 1> b(&data, sycl::range<1>(1));
31+
sycl::buffer<int, 1> atomic_b(&atomic_data, sycl::range<1>(1));
32+
sycl::queue queue;
33+
queue.submit([&](sycl::handler &cgh) {
34+
sycl::accessor<int, 0, sycl::access::mode::read_write,
35+
sycl::access::target::global_buffer>
36+
NormalA(b, cgh);
37+
sycl::accessor<int, 0, sycl::access::mode::atomic,
38+
sycl::access::target::global_buffer>
39+
AtomicA(atomic_b, cgh);
40+
cgh.single_task<class acc_with_zero_dim>([=]() {
41+
// 'normal int'
42+
store(NormalA, 399);
43+
44+
// 'atomic int'
45+
store(AtomicA, 499);
46+
// This error is the one we do NOT want to see when compiling on
47+
// FPGA
48+
// clang-format off
49+
// error: no matching function for call to 'store'
50+
// note: candidate function not viable: no known conversion from 'const sycl::accessor<int, 0, sycl::access::mode::atomic, sycl::access::target::global_buffer>' to 'int &' for 1st argument
51+
// note: candidate function not viable: no known conversion from 'const sycl::accessor<int, 0, sycl::access::mode::atomic, sycl::access::target::global_buffer>' to 'atomic_t' (aka 'atomic<int>') for 1st argument
52+
// clang-format on
53+
});
54+
});
55+
}
56+
assert(data == 399);
57+
assert(atomic_data == 499);
58+
} catch (sycl::exception e) {
59+
std::cout << "SYCL exception caught: " << e.what();
60+
return 1;
61+
}
62+
}
63+
std::cout << std::endl;
64+
65+
return 0;
66+
}

0 commit comments

Comments
 (0)