Skip to content

Commit 57616c3

Browse files
[SYCL] Don't use std::optional for the sake of gcc 7.5.0 support (intel#12224)
There is a mismatch between gcc 7.5.0 and newer versions of gcc in terms of std::optional implementation which causes programs to crash if program is partially compiled on the system with gcc 7.5.0 and partially compiled on the system with newer gcc. Co-authored-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent 9a1b908 commit 57616c3

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,12 @@ class __SYCL_EXPORT handler {
11201120
};
11211121

11221122
std::optional<std::array<size_t, 3>> getMaxWorkGroups();
1123+
// We need to use this version to support gcc 7.5.0. Remove when minimal
1124+
// supported gcc version is bumped.
1125+
std::tuple<std::array<size_t, 3>, bool> getMaxWorkGroups_v2();
11231126

11241127
template <int Dims>
1125-
std::optional<range<Dims>> getRoundedRange(range<Dims> UserRange) {
1128+
std::tuple<range<Dims>, bool> getRoundedRange(range<Dims> UserRange) {
11261129
range<Dims> RoundedRange = UserRange;
11271130
// Disable the rounding-up optimizations under these conditions:
11281131
// 1. The env var SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING is set.
@@ -1142,7 +1145,7 @@ class __SYCL_EXPORT handler {
11421145

11431146
// Perform range rounding if rounding-up is enabled.
11441147
if (this->DisableRangeRounding())
1145-
return {};
1148+
return {range<Dims>{}, false};
11461149

11471150
// Range should be a multiple of this for reasonable performance.
11481151
size_t MinFactorX = 16;
@@ -1166,8 +1169,8 @@ class __SYCL_EXPORT handler {
11661169
// kernel in a 32-bit global range.
11671170
auto Dev = detail::getSyclObjImpl(detail::getDeviceFromHandler(*this));
11681171
id<Dims> MaxNWGs = [&] {
1169-
auto PiResult = getMaxWorkGroups();
1170-
if (!PiResult.has_value()) {
1172+
auto [MaxWGs, HasMaxWGs] = getMaxWorkGroups_v2();
1173+
if (!HasMaxWGs) {
11711174
id<Dims> Default;
11721175
for (int i = 0; i < Dims; ++i)
11731176
Default[i] = (std::numeric_limits<int32_t>::max)();
@@ -1177,7 +1180,7 @@ class __SYCL_EXPORT handler {
11771180
id<Dims> IdResult;
11781181
size_t Limit = (std::numeric_limits<int>::max)();
11791182
for (int i = 0; i < Dims; ++i)
1180-
IdResult[i] = (std::min)(Limit, (*PiResult)[Dims - i - 1]);
1183+
IdResult[i] = (std::min)(Limit, MaxWGs[Dims - i - 1]);
11811184
return IdResult;
11821185
}();
11831186
auto M = (std::numeric_limits<uint32_t>::max)();
@@ -1213,8 +1216,8 @@ class __SYCL_EXPORT handler {
12131216
Adjust(i, MaxRange[i]);
12141217

12151218
if (!DidAdjust)
1216-
return {};
1217-
return RoundedRange;
1219+
return {range<Dims>{}, false};
1220+
return {RoundedRange, true};
12181221
}
12191222

12201223
/// Defines and invokes a SYCL kernel function for the specified range.
@@ -1282,7 +1285,8 @@ class __SYCL_EXPORT handler {
12821285
#if !defined(__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__) && \
12831286
!defined(DPCPP_HOST_DEVICE_OPENMP) && \
12841287
!defined(DPCPP_HOST_DEVICE_PERF_NATIVE) && SYCL_LANGUAGE_VERSION >= 202001
1285-
if (auto RoundedRange = getRoundedRange(UserRange)) {
1288+
auto [RoundedRange, HasRoundedRange] = getRoundedRange(UserRange);
1289+
if (HasRoundedRange) {
12861290
using NameWT = typename detail::get_kernel_wrapper_name_t<NameT>::name;
12871291
auto Wrapper =
12881292
getRangeRoundedKernelLambda<NameWT, TransformedArgType, Dims>(
@@ -1300,7 +1304,7 @@ class __SYCL_EXPORT handler {
13001304
// __SYCL_ASSUME_INT can still be violated. So check the bounds
13011305
// of the user range, instead of the rounded range.
13021306
detail::checkValueRange<Dims>(UserRange);
1303-
MNDRDesc.set(*RoundedRange);
1307+
MNDRDesc.set(RoundedRange);
13041308
StoreLambda<KName, decltype(Wrapper), Dims, TransformedArgType>(
13051309
std::move(Wrapper));
13061310
setType(detail::CG::Kernel);

sycl/source/handler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,5 +1457,12 @@ std::optional<std::array<size_t, 3>> handler::getMaxWorkGroups() {
14571457
return {};
14581458
}
14591459

1460+
std::tuple<std::array<size_t, 3>, bool> handler::getMaxWorkGroups_v2() {
1461+
auto ImmRess = getMaxWorkGroups();
1462+
if (ImmRess)
1463+
return {*ImmRess, true};
1464+
return {std::array<size_t, 3>{0, 0, 0}, false};
1465+
}
1466+
14601467
} // namespace _V1
14611468
} // namespace sycl

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4114,6 +4114,7 @@ _ZN4sycl3_V17handler17use_kernel_bundleERKNS0_13kernel_bundleILNS0_12bundle_stat
41144114
_ZN4sycl3_V17handler18RangeRoundingTraceEv
41154115
_ZN4sycl3_V17handler18ext_oneapi_barrierERKSt6vectorINS0_5eventESaIS3_EE
41164116
_ZN4sycl3_V17handler18extractArgsAndReqsEv
4117+
_ZN4sycl3_V17handler19getMaxWorkGroups_v2Ev
41174118
_ZN4sycl3_V17handler19supportsUSMMemcpy2DEv
41184119
_ZN4sycl3_V17handler19supportsUSMMemset2DEv
41194120
_ZN4sycl3_V17handler20DisableRangeRoundingEv

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@
11421142
?getInteropContext@SYCLMemObjT@detail@_V1@sycl@@UEBA?AV?$shared_ptr@Vcontext_impl@detail@_V1@sycl@@@std@@XZ
11431143
?getKernelName@handler@_V1@sycl@@AEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
11441144
?getMaxWorkGroups@handler@_V1@sycl@@AEAA?AV?$optional@V?$array@_K$02@std@@@std@@XZ
1145+
?getMaxWorkGroups_v2@handler@_V1@sycl@@AEAA?AV?$tuple@V?$array@_K$02@std@@_N@std@@XZ
11451146
?getMemoryObject@AccessorBaseHost@detail@_V1@sycl@@QEBAPEAXXZ
11461147
?getMemoryObject@SampledImageAccessorBaseHost@detail@_V1@sycl@@QEBAPEAXXZ
11471148
?getMemoryObject@UnsampledImageAccessorBaseHost@detail@_V1@sycl@@QEBAPEAXXZ

0 commit comments

Comments
 (0)