Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sycl/doc/UsersManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ and not recommended to use in production environment.

**`-f[no-]sycl-id-queries-fit-in-int`**

Assume/Do not assume that SYCL ID queries fit within MAX_INT. It assumes
that these values fit within MAX_INT:
Assume/Do not assume that SYCL ID queries fit within MAX_UINT. It assumes
that these values fit within MAX_UINT:
* id class get() member function and operator[]
* item class get_id() member function and operator[]
* nd_item class get_global_id()/get_global_linear_id() member functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ implementations that may support this extension.

If a translation unit is compiled with the `-fsycl-id-queries-fit-in-int`
option, all kernels and `SYCL_EXTERNAL` functions without an explicitly
specified `range_type` property are compiled as-if `range_type<int>` was
specified as a property of that kernel or function.
specified `range_type` property are compiled as-if `range_type<unsigned int>`
was specified as a property of that kernel or function.


== Implementation notes
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#if __SYCL_ID_QUERIES_FIT_IN_INT__ && __has_builtin(__builtin_assume)
#include <climits>
#define __SYCL_ASSUME_INT(x) __builtin_assume((x) <= INT_MAX)
#define __SYCL_ASSUME_INT(x) __builtin_assume((x) <= UINT_MAX)
#else
#define __SYCL_ASSUME_INT(x)
#if __SYCL_ID_QUERIES_FIT_IN_INT__ && !__has_builtin(__builtin_assume)
Expand Down
10 changes: 5 additions & 5 deletions sycl/include/sycl/detail/id_queries_fit_in_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// Our SYCL implementation has a special mode (introduced for performance
// reasons) in which it assume that all result of all id queries (i.e. global
// sizes, work-group sizes, local id, global id, etc.) fit within MAX_INT.
// sizes, work-group sizes, local id, global id, etc.) fit within UINT_MAX.
//
// This header contains corresponding helper functions related to this mode.
//
Expand All @@ -35,22 +35,22 @@ namespace detail {

#if __SYCL_ID_QUERIES_FIT_IN_INT__
constexpr static const char *Msg =
"Provided range and/or offset does not fit in int. Pass "
"Provided range and/or offset does not fit in unsigned int. Pass "
"`-fno-sycl-id-queries-fit-in-int' to remove this limit.";

template <typename ValT>
typename std::enable_if_t<std::is_same<ValT, size_t>::value ||
std::is_same<ValT, unsigned long long>::value>
checkValueRangeImpl(ValT V) {
static constexpr size_t Limit =
static_cast<size_t>((std::numeric_limits<int>::max)());
static_cast<size_t>((std::numeric_limits<unsigned int>::max)());
if (V > Limit)
throw sycl::exception(make_error_code(errc::nd_range), Msg);
}

inline void checkMulOverflow(size_t a, size_t b) {
#ifndef _MSC_VER
int Product;
unsigned int Product;
if (__builtin_mul_overflow(a, b, &Product)) {
throw sycl::exception(make_error_code(errc::nd_range), Msg);
}
Expand All @@ -64,7 +64,7 @@ inline void checkMulOverflow(size_t a, size_t b) {

inline void checkMulOverflow(size_t a, size_t b, size_t c) {
#ifndef _MSC_VER
int Product;
unsigned int Product;
if (__builtin_mul_overflow(a, b, &Product) ||
__builtin_mul_overflow(Product, c, &Product)) {
throw sycl::exception(make_error_code(errc::nd_range), Msg);
Expand Down
11 changes: 7 additions & 4 deletions sycl/test-e2e/Basic/range_offset_fit_in_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace S = sycl;

constexpr char Msg[] = "Provided range and/or offset does not fit in int. "
"Pass `-fno-sycl-id-queries-fit-in-int' to "
"remove this limit.";
constexpr char Msg[] =
"Provided range and/or offset does not fit in unsigned int. Pass "
"`-fno-sycl-id-queries-fit-in-int' to remove this limit.";

void checkRangeException(S::exception &E) {
std::cerr << E.what() << std::endl;
Expand All @@ -33,7 +33,10 @@ void test() {

S::queue Queue(EH);

static constexpr size_t OutOfLimitsSize = static_cast<size_t>(INT_MAX) + 1;
// Test is valid only if size_t is larger than unsigned int, we don't run the
// testing on platforms where this condition is not met.
static_assert(sizeof(size_t) > sizeof(unsigned int));
static constexpr size_t OutOfLimitsSize = static_cast<size_t>(UINT_MAX) + 1;

S::range<2> RangeOutOfLimits{OutOfLimitsSize, 1};
S::range<2> RangeInLimits{1, 1};
Expand Down
Loading