Skip to content

Commit a8dcc96

Browse files
author
Sergey Kanaev
committed
[SYCL] Address comments.
Signed-off-by: Sergey Kanaev <[email protected]>
1 parent 8fbd039 commit a8dcc96

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

sycl/include/CL/sycl/handler.hpp

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <algorithm>
2727
#include <functional>
28+
#include <limits>
2829
#include <memory>
2930
#include <type_traits>
3031

@@ -133,23 +134,24 @@ template <typename T> struct NotIntMsg;
133134

134135
template <int Dims> struct NotIntMsg<range<Dims>> {
135136
constexpr static char *Msg = "Provided range is out of integer limits. "
136-
"Suggest disabling `id-queries-fit-in-int32' "
137-
"optimizations flag.";
137+
"Suggest disabling `fsycl-id-queries-fit-in-int'"
138+
" optimizations flag.";
138139
};
139140

140141
template <int Dims> struct NotIntMsg<id<Dims>> {
141142
constexpr static char *Msg = "Provided offset is out of integer limits. "
142-
"Suggest disabling `id-queries-fit-in-int32' "
143-
"optimizations flag.";
143+
"Suggest disabling `fsycl-id-queries-fit-in-int'"
144+
" optimizations flag.";
144145
};
145146
#endif
146147

147148
template <int Dims, typename T>
148149
typename std::enable_if<std::is_same<T, range<Dims>>::value ||
149150
std::is_same<T, id<Dims>>::value>::type
150-
throwIfNotInt(const T &V) {
151+
checkValueRange(const T &V) {
151152
#if defined(__SYCL_ID_QUERIES_FIT_IN_INT__)
152-
static constexpr size_t Limit = static_cast<size_t>(INT_MAX);
153+
static constexpr size_t Limit = static_cast<size_t>(
154+
std::numeric_limits<int>::max());
153155
for (size_t Dim = 0; Dim < Dims; ++Dim)
154156
if (V[Dim] > Limit)
155157
throw runtime_error(NotIntMsg<T>::Msg, PI_INVALID_VALUE);
@@ -824,7 +826,7 @@ class __SYCL_EXPORT handler {
824826
(void)NumWorkItems;
825827
kernel_parallel_for<NameT, KernelType, Dims>(KernelFunc);
826828
#else
827-
detail::throwIfNotInt<Dims>(NumWorkItems);
829+
detail::checkValueRange<Dims>(NumWorkItems);
828830
MNDRDesc.set(std::move(NumWorkItems));
829831
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));
830832
MCGType = detail::CG::KERNEL;
@@ -885,8 +887,8 @@ class __SYCL_EXPORT handler {
885887
(void)WorkItemOffset;
886888
kernel_parallel_for<NameT, KernelType, Dims>(KernelFunc);
887889
#else
888-
detail::throwIfNotInt<Dims>(NumWorkItems);
889-
detail::throwIfNotInt<Dims>(WorkItemOffset);
890+
detail::checkValueRange<Dims>(NumWorkItems);
891+
detail::checkValueRange<Dims>(WorkItemOffset);
890892
MNDRDesc.set(std::move(NumWorkItems), std::move(WorkItemOffset));
891893
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));
892894
MCGType = detail::CG::KERNEL;
@@ -915,9 +917,9 @@ class __SYCL_EXPORT handler {
915917
(void)ExecutionRange;
916918
kernel_parallel_for_nd_range<NameT, KernelType, Dims>(KernelFunc);
917919
#else
918-
detail::throwIfNotInt<Dims>(ExecutionRange.get_global_range());
919-
detail::throwIfNotInt<Dims>(ExecutionRange.get_local_range());
920-
detail::throwIfNotInt<Dims>(ExecutionRange.get_offset());
920+
detail::checkValueRange<Dims>(ExecutionRange.get_global_range());
921+
detail::checkValueRange<Dims>(ExecutionRange.get_local_range());
922+
detail::checkValueRange<Dims>(ExecutionRange.get_offset());
921923
MNDRDesc.set(std::move(ExecutionRange));
922924
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));
923925
MCGType = detail::CG::KERNEL;
@@ -1087,7 +1089,7 @@ class __SYCL_EXPORT handler {
10871089
(void)NumWorkGroups;
10881090
kernel_parallel_for_work_group<NameT, KernelType, Dims>(KernelFunc);
10891091
#else
1090-
detail::throwIfNotInt<Dims>(NumWorkGroups);
1092+
detail::checkValueRange<Dims>(NumWorkGroups);
10911093
MNDRDesc.setNumWorkGroups(NumWorkGroups);
10921094
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));
10931095
MCGType = detail::CG::KERNEL;
@@ -1121,9 +1123,9 @@ class __SYCL_EXPORT handler {
11211123
#else
11221124
nd_range<Dims> ExecRange =
11231125
nd_range<Dims>(NumWorkGroups * WorkGroupSize, WorkGroupSize);
1124-
detail::throwIfNotInt<Dims>(ExecRange.get_global_range());
1125-
detail::throwIfNotInt<Dims>(ExecRange.get_local_range());
1126-
detail::throwIfNotInt<Dims>(ExecRange.get_offset());
1126+
detail::checkValueRange<Dims>(ExecRange.get_global_range());
1127+
detail::checkValueRange<Dims>(ExecRange.get_local_range());
1128+
detail::checkValueRange<Dims>(ExecRange.get_offset());
11271129
MNDRDesc.set(std::move(ExecRange));
11281130
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));
11291131
MCGType = detail::CG::KERNEL;
@@ -1159,7 +1161,7 @@ class __SYCL_EXPORT handler {
11591161
throwIfActionIsCreated();
11601162
verifyKernelInvoc(Kenrel);
11611163
MKernel = detail::getSyclObjImpl(std::move(Kenrel));
1162-
detail::throwIfNotInt<Dims>(NumWorkItems);
1164+
detail::checkValueRange<Dims>(NumWorkItems);
11631165
MNDRDesc.set(std::move(NumWorkItems));
11641166
MCGType = detail::CG::KERNEL;
11651167
extractArgsAndReqs();
@@ -1179,8 +1181,8 @@ class __SYCL_EXPORT handler {
11791181
throwIfActionIsCreated();
11801182
verifyKernelInvoc(Kernel);
11811183
MKernel = detail::getSyclObjImpl(std::move(Kernel));
1182-
detail::throwIfNotInt<Dims>(NumWorkItems);
1183-
detail::throwIfNotInt<Dims>(WorkItemOffset);
1184+
detail::checkValueRange<Dims>(NumWorkItems);
1185+
detail::checkValueRange<Dims>(WorkItemOffset);
11841186
MNDRDesc.set(std::move(NumWorkItems), std::move(WorkItemOffset));
11851187
MCGType = detail::CG::KERNEL;
11861188
extractArgsAndReqs();
@@ -1198,9 +1200,9 @@ class __SYCL_EXPORT handler {
11981200
throwIfActionIsCreated();
11991201
verifyKernelInvoc(Kernel);
12001202
MKernel = detail::getSyclObjImpl(std::move(Kernel));
1201-
detail::throwIfNotInt<Dims>(NDRange.get_global_range());
1202-
detail::throwIfNotInt<Dims>(NDRange.get_local_range());
1203-
detail::throwIfNotInt<Dims>(NDRange.get_offset());
1203+
detail::checkValueRange<Dims>(NDRange.get_global_range());
1204+
detail::checkValueRange<Dims>(NDRange.get_local_range());
1205+
detail::checkValueRange<Dims>(NDRange.get_offset());
12041206
MNDRDesc.set(std::move(NDRange));
12051207
MCGType = detail::CG::KERNEL;
12061208
extractArgsAndReqs();
@@ -1261,7 +1263,7 @@ class __SYCL_EXPORT handler {
12611263
(void)NumWorkItems;
12621264
kernel_parallel_for<NameT, KernelType, Dims>(KernelFunc);
12631265
#else
1264-
detail::throwIfNotInt<Dims>(NumWorkItems);
1266+
detail::checkValueRange<Dims>(NumWorkItems);
12651267
MNDRDesc.set(std::move(NumWorkItems));
12661268
MKernel = detail::getSyclObjImpl(std::move(Kernel));
12671269
MCGType = detail::CG::KERNEL;
@@ -1294,8 +1296,8 @@ class __SYCL_EXPORT handler {
12941296
(void)WorkItemOffset;
12951297
kernel_parallel_for<NameT, KernelType, Dims>(KernelFunc);
12961298
#else
1297-
detail::throwIfNotInt<Dims>(NumWorkItems);
1298-
detail::throwIfNotInt<Dims>(WorkItemOffset);
1299+
detail::checkValueRange<Dims>(NumWorkItems);
1300+
detail::checkValueRange<Dims>(WorkItemOffset);
12991301
MNDRDesc.set(std::move(NumWorkItems), std::move(WorkItemOffset));
13001302
MKernel = detail::getSyclObjImpl(std::move(Kernel));
13011303
MCGType = detail::CG::KERNEL;
@@ -1327,9 +1329,9 @@ class __SYCL_EXPORT handler {
13271329
(void)NDRange;
13281330
kernel_parallel_for_nd_range<NameT, KernelType, Dims>(KernelFunc);
13291331
#else
1330-
detail::throwIfNotInt<Dims>(NDRange.get_global_range());
1331-
detail::throwIfNotInt<Dims>(NDRange.get_local_range());
1332-
detail::throwIfNotInt<Dims>(NDRange.get_offset());
1332+
detail::checkValueRange<Dims>(NDRange.get_global_range());
1333+
detail::checkValueRange<Dims>(NDRange.get_local_range());
1334+
detail::checkValueRange<Dims>(NDRange.get_offset());
13331335
MNDRDesc.set(std::move(NDRange));
13341336
MKernel = detail::getSyclObjImpl(std::move(Kernel));
13351337
MCGType = detail::CG::KERNEL;
@@ -1365,7 +1367,7 @@ class __SYCL_EXPORT handler {
13651367
(void)NumWorkGroups;
13661368
kernel_parallel_for_work_group<NameT, KernelType, Dims>(KernelFunc);
13671369
#else
1368-
detail::throwIfNotInt<Dims>(NumWorkGroups);
1370+
detail::checkValueRange<Dims>(NumWorkGroups);
13691371
MNDRDesc.setNumWorkGroups(NumWorkGroups);
13701372
MKernel = detail::getSyclObjImpl(std::move(Kernel));
13711373
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));
@@ -1404,9 +1406,9 @@ class __SYCL_EXPORT handler {
14041406
#else
14051407
nd_range<Dims> ExecRange =
14061408
nd_range<Dims>(NumWorkGroups * WorkGroupSize, WorkGroupSize);
1407-
detail::throwIfNotInt<Dims>(ExecRange.get_global_range());
1408-
detail::throwIfNotInt<Dims>(ExecRange.get_local_range());
1409-
detail::throwIfNotInt<Dims>(ExecRange.get_offset());
1409+
detail::checkValueRange<Dims>(ExecRange.get_global_range());
1410+
detail::checkValueRange<Dims>(ExecRange.get_local_range());
1411+
detail::checkValueRange<Dims>(ExecRange.get_offset());
14101412
MNDRDesc.set(std::move(ExecRange));
14111413
MKernel = detail::getSyclObjImpl(std::move(Kernel));
14121414
StoreLambda<NameT, KernelType, Dims>(std::move(KernelFunc));

sycl/test/basic_tests/range_offset_fit_in_int.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace S = cl::sycl;
88

99
void checkRangeException(S::runtime_error &E) {
1010
constexpr char Msg[] = "Provided range is out of integer limits. Suggest "
11-
"disabling `id-queries-fit-in-int32' optimizations "
12-
"flag.";
11+
"disabling `fsycl-id-queries-fit-in-int' optimizations"
12+
" flag.";
1313

1414
std::cerr << E.what() << std::endl;
1515

@@ -18,8 +18,8 @@ void checkRangeException(S::runtime_error &E) {
1818

1919
void checkOffsetException(S::runtime_error &E) {
2020
constexpr char Msg[] = "Provided offset is out of integer limits. Suggest "
21-
"disabling `id-queries-fit-in-int32' optimizations "
22-
"flag.";
21+
"disabling `fsycl-id-queries-fit-in-int' optimizations"
22+
" flag.";
2323

2424
std::cerr << E.what() << std::endl;
2525

0 commit comments

Comments
 (0)