Skip to content

Commit e74334e

Browse files
authored
[SYCL-MLIR]: Runtime workaround for paralllel_for (#7303)
The following test case (using a SYCL parallel_for) fails to run correctly due to a SYCL RT function (dim_loop_impl) which uses a complex templated implementation which "confuses" cgeist. As a workaround we can use the older SYCL RT implementation which used a regular for loop. Test case: ``` void host_parallel_for(std::array<int, N> &A) { auto q = queue{}; device d = q.get_device(); std::cout << "Using " << d.get_info<info::device::name>() << "\n"; auto range = sycl::range<1>{N}; { auto buf = buffer<int, 1>{A.data(), range}; q.submit([&](handler &cgh) { auto A = buf.get_access<access::mode::write>(cgh); cgh.parallel_for<class kernel_parallel_for>( range, [=](sycl::id<1> id) { A[3] = 33; }); }); } } Signed-off-by: Tiotto, Ettore <[email protected]>
1 parent a6e5413 commit e74334e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,9 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
10141014
template <int Dims = Dimensions> size_t getLinearIndex(id<Dims> Id) const {
10151015

10161016
size_t Result = 0;
1017-
detail::dim_loop<Dims>([&, this](size_t I) {
1017+
1018+
#pragma unroll
1019+
for (int I = 0; I < Dims; ++I) {
10181020
Result = Result * getMemoryRange()[I] + Id[I];
10191021
// We've already adjusted for the accessor's offset in the __init, so
10201022
// don't include it here in case of device.
@@ -1028,7 +1030,7 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
10281030
Result += getOffset()[I];
10291031
#endif
10301032
#endif // __SYCL_DEVICE_ONLY__
1031-
});
1033+
}
10321034

10331035
return Result;
10341036
}
@@ -1084,7 +1086,9 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
10841086
void __init(ConcreteASPtrType Ptr, range<AdjustedDim> AccessRange,
10851087
range<AdjustedDim> MemRange, id<AdjustedDim> Offset) {
10861088
MData = Ptr;
1087-
detail::dim_loop<AdjustedDim>([&, this](size_t I) {
1089+
1090+
#pragma unroll
1091+
for (int I = 0; I < AdjustedDim; ++I) {
10881092
#if __cplusplus >= 201703L
10891093
if constexpr (!(PropertyListT::template has_property<
10901094
sycl::ext::oneapi::property::no_offset>())) {
@@ -1095,7 +1099,7 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
10951099
#endif
10961100
getAccessRange()[I] = AccessRange[I];
10971101
getMemoryRange()[I] = MemRange[I];
1098-
});
1102+
}
10991103

11001104
// Adjust for offsets as that part is invariant for all invocations of
11011105
// operator[]. Will have to re-adjust in get_pointer.
@@ -2148,7 +2152,9 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21482152
#ifdef __SYCL_DEVICE_ONLY__
21492153
size_t getTotalOffset() const {
21502154
size_t TotalOffset = 0;
2151-
detail::dim_loop<Dimensions>([&, this](size_t I) {
2155+
2156+
#pragma unroll
2157+
for (int I = 0; I < Dimensions; ++I) {
21522158
TotalOffset = TotalOffset * impl.MemRange[I];
21532159
#if __cplusplus >= 201703L
21542160
if constexpr (!(PropertyListT::template has_property<
@@ -2158,7 +2164,7 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21582164
#else
21592165
TotalOffset += impl.Offset[I];
21602166
#endif
2161-
});
2167+
}
21622168

21632169
return TotalOffset;
21642170
}
@@ -2414,8 +2420,10 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
24142420
void __init(ConcreteASPtrType Ptr, range<AdjustedDim> AccessRange,
24152421
range<AdjustedDim>, id<AdjustedDim>) {
24162422
MData = Ptr;
2417-
detail::dim_loop<AdjustedDim>(
2418-
[&, this](size_t I) { getSize()[I] = AccessRange[I]; });
2423+
2424+
#pragma unroll
2425+
for (int I = 0; I < AdjustedDim; ++I)
2426+
getSize()[I] = AccessRange[I];
24192427
}
24202428

24212429
public:

0 commit comments

Comments
 (0)