Relational functions#
Relational functions are defined in the sycl namespace
and are available on both host and device. These functions
perform various relational comparisons on sycl::vec,
sycl::marray, and scalar types.
The comparisons performed by sycl::isequal, sycl::isgreater,
sycl::isgreaterequal, sycl::isless, sycl::islessequal,
and sycl::islessgreater are false when one or both operands
are NaN. The comparison performed by sycl::isnotequal is true
when one or both operands are NaN.
The function descriptions in this section use two terms that refer to a specific list of types. The term generic scalar type represents the following types:
charsigned charshortintlonglong longunsigned charunsigned shortunsigned intunsigned longunsigned long longfloatdoublehalf
The term vector element type represents these types:
int8_tint16_tint32_tint64_tuint8_tuint16_tuint32_tuint64_tfloatdoublehalf
See also
SYCL Specification Section 4.17.10
sycl::isequal#
Overloads 1-3
bool isequal(float x, float y);
bool isequal(double x, double y);
bool isequal(half x, half y);
Returns the value (x == y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value (x[i] == y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
((x[i] == y[i]) ? -1 : 0) for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isnotequal#
Overloads 1-3
bool isnotequal(float x, float y);
bool isnotequal(double x, double y);
bool isnotequal(half x, half y);
Returns the value (x != y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isnotequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value (x[i] != y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
((x[i] != y[i]) ? -1 : 0) for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isgreater#
Overloads 1-3
bool isgreater(float x, float y);
bool isgreater(double x, double y);
bool isgreater(half x, half y);
Returns the value (x > y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isgreater(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value (x[i] > y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
((x[i] > y[i]) ? -1 : 0) for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isgreaterequal#
Overloads 1-3
bool isgreaterequal(float x, float y);
bool isgreaterequal(double x, double y);
bool isgreaterequal(half x, half y);
Returns the value (x >= y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isgreaterequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value (x[i] >= y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
((x[i] >= y[i]) ? -1 : 0) for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isless#
Overloads 1-3
bool isless(float x, float y);
bool isless(double x, double y);
bool isless(half x, half y);
Returns the value (x < y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isless(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value (x[i] < y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
((x[i] < y[i]) ? -1 : 0) for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::islessequal#
Overloads 1-3
bool islessequal(float x, float y);
bool islessequal(double x, double y);
bool islessequal(half x, half y);
Returns the value (x <= y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ islessequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value (x[i] <= y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
((x[i] <= y[i]) ? -1 : 0) for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::islessgreater#
Overloads 1-3
bool islessgreater(float x, float y);
bool islessgreater(double x, double y);
bool islessgreater(half x, half y);
Returns the value (x < y) || (x > y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ islessgreater(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
If NonScalar1 is sycl::marray, the value
(x[i] < y[i]) || (x[i] > y[i])
for each element of x and y. If NonScalar1 is
sycl::vec or the __swizzled_vec__ type, returns the value
(((x[i] < y[i]) || (x[i] > y[i])) ? -1 : 0) for each element
of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isfinite#
Overloads 1-3
bool isfinite(float x);
bool isfinite(double x);
bool isfinite(half x);
Returns the value true only if x has finite value.
Overload 4
template<typename NonScalar>
/*return-type*/ isfinite(NonScalar x);
Available only if all of the following conditions are met:
NonScalarissycl::marray,sycl::vec, or the__swizzled_vec__type;The element type is
float,double, orhalf.
If NonScalar is sycl::marray, returns true for
each element of x only if x[i] is a finite value. If
NonScalar is sycl::vec or the __swizzled_vec__ type,
returns -1 for each element of x if x[i] is a finite
value and returns 0 otherwise.
The return type depends on NonScalar:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isinf#
Overloads 1-3
bool isinf(float x);
bool isinf(double x);
bool isinf(half x);
Returns the value true only if x has an
infinity value (either positive or negative).
Overload 4
template<typename NonScalar>
/*return-type*/ isinf(NonScalar x);
Available only if all of the following conditions are met:
NonScalarissycl::marray,sycl::vec, or the__swizzled_vec__type;The element type is
float,double, orhalf.
If NonScalar is sycl::marray, returns true for
each element of x only if x[i] has an infinity value.
If NonScalar is sycl::vec or the __swizzled_vec__
type, returns -1 for each element of x if x[i] has an
infinity value and returns 0 otherwise.
The return type depends on NonScalar:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isnan#
Overloads 1-3
bool isnan(float x);
bool isnan(double x);
bool isnan(half x);
Returns the value true only if x has a NaN value.
Overload 4
template<typename NonScalar>
/*return-type*/ isnan(NonScalar x);
Available only if all of the following conditions are met:
NonScalarissycl::marray,sycl::vec, or the__swizzled_vec__type;The element type is
float,double, orhalf.
If NonScalar is sycl::marray, returns true for each
element of x only if x[i] has a NaN value. If
NonScalar is sycl::vec or the __swizzled_vec__
type, returns -1 for each element of x if x[i] has
a NaN value and returns 0 otherwise.
The return type depends on NonScalar:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isnormal#
Overloads 1-3
bool isnormal(float x);
bool isnormal(double x);
bool isnormal(half x);
Returns the value true only if x has a normal value.
Overload 4
template<typename NonScalar>
/*return-type*/ isnormal(NonScalar x);
Available only if all of the following conditions are met:
NonScalarissycl::marray,sycl::vec, or the__swizzled_vec__type;The element type is
float,double, orhalf.
If NonScalar is sycl::marray, returns true for
each element of x only if x[i] has a normal value.
If NonScalar is sycl::vec or the __swizzled_vec__
type, returns -1 for each element of x if x[i] has a
normal value and returns 0 otherwise.
The return type depends on NonScalar:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isordered#
Overloads 1-3
bool isordered(float x, float y);
bool isordered(double x, double y);
bool isordered(half x, half y);
Returns the value sycl::isequal(x, x) && sycl::isequal(y, y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isordered(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
Tests if each element of x and y are ordered.
If NonScalar1 is marray, the value
sycl::isequal(x[i], x[i]) && sycl::isequal(y[i], y[i]) for
each element of x and y. If NonScalar1 is sycl::vec
or the __swizzled_vec__ type, returns the value
((sycl::isequal(x[i], x[i]) && sycl::isequal(y[i], y[i])) ? -1 : 0)
for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::isunordered#
Overloads 1-3
bool isunordered(float x, float y);
bool isunordered(double x, double y);
bool isunordered(half x, half y);
Returns the value sycl::isnan(x) || sycl::isnan(y).
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isunordered(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1andNonScalar2:Both
NonScalar1andNonScalar2aresycl::marray;NonScalar1andNonScalar2are any combination ofsycl::vecand the__swizzled_vec__type;
NonScalar1andNonScalar2have the same number of elements and the same element type;The element type is
float,double, orhalf.
Tests if each element of x and y are unordered.
If NonScalar1 is marray, the value
sycl::isnan(x[i]) || sycl::isnan(y[i]) for
each element of x and y. If NonScalar1 is sycl::vec
or the __swizzled_vec__ type, returns the value
((sycl::isnan(x[i]) || sycl::isnan(y[i])) ? -1 : 0)
for each element of x and y.
The return type depends on NonScalar1:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::signbit#
Overloads 1-3
bool signbit(float x);
bool signbit(double x);
bool signbit(half x);
Returns the value true only if the sign bit of x is set.
Overload 4
template<typename NonScalar>
/*return-type*/ signbit(NonScalar x);
Available only if all of the following conditions are met:
NonScalarissycl::marray,sycl::vec, or the__swizzled_vec__type;The element type is
float,double, orhalf.
If NonScalar is sycl::marray, returns true for
each element of x only if the sign bit of x[i] is set.
If NonScalar is sycl::vec or the __swizzled_vec__
type, returns -1 for each element of x if the sign bit of
x[i] is set and returns 0 otherwise.
The return type depends on NonScalar:
|
Return Type |
|---|---|
|
|
|
|
|
|
|
|
sycl::any#
Overload 1
template<typename GenInt>
/*return-type*/ any(GenInt x);
Available only if GenInt is one of the following types:
sycl::marray<bool, N>sycl::vec<int8_t, N>sycl::vec<int16_t, N>sycl::vec<int32_t, N>sycl::vec<int64_t, N>__swizzled_vec__that is convertible tosycl::vec<int8_t, N>__swizzled_vec__that is convertible tosycl::vec<int16_t, N>__swizzled_vec__that is convertible tosycl::vec<int32_t, N>__swizzled_vec__that is convertible tosycl::vec<int64_t, N>
When x is sycl::marray, returns a Boolean
telling whether any element of x is true.
When x is sycl::vec or the __swizzled_vec__
type, returns the value 1 if any element in x has
its most significant bit set, otherwise returns the value 0.
The return type is bool if GenInt is sycl::marray.
Otherwise, the return type is int.
Overload 2
template<typename GenInt>
bool any(GenInt x);
Warning
This overload is deprecated in SYCL 2020.
Available only if GenInt is one of the following types:
signed charshortintlonglong longsycl::marray<signed char, N>sycl::marray<short, N>sycl::marray<int, N>sycl::marray<long, N>sycl::marray<long long, N>
When x is a scalar, returns a Boolean telling whether
the most significant bit of x is set. When x is
sycl::marray, returns a Boolean telling whether the
most significant bit of any element in x is set.
sycl::all#
Overload 1
template<typename GenInt>
/*return-type*/ all(GenInt x);
Available only if GenInt is one of the following types:
sycl::marray<bool, N>sycl::vec<int8_t, N>sycl::vec<int16_t, N>sycl::vec<int32_t, N>sycl::vec<int64_t, N>__swizzled_vec__that is convertible tosycl::vec<int8_t, N>__swizzled_vec__that is convertible tosycl::vec<int16_t, N>__swizzled_vec__that is convertible tosycl::vec<int32_t, N>__swizzled_vec__that is convertible tosycl::vec<int64_t, N>
When x is sycl::marray, returns a Boolean
telling whether all elements of x are true.
When x is sycl::vec or the __swizzled_vec__
type, returns the value 1 if all elements in x have
their most significant bit set, otherwise returns the value 0.
The return type is bool if GenInt is sycl::marray.
Otherwise, the return type is int.
Overload 2
template<typename GenInt>
bool all(GenInt x);
Warning
This overload is deprecated in SYCL 2020.
Available only if GenInt is one of the following types:
signed charshortintlonglong longsycl::marray<signed char, N>sycl::marray<short, N>sycl::marray<int, N>sycl::marray<long, N>sycl::marray<long long, N>
When x is a scalar, returns a Boolean telling whether
the most significant bit of x is set. When x is
sycl::marray, returns a Boolean telling whether the
most significant bit of all elements in x are set.
sycl::bitselect#
template<typename GenType1, typename GenType2, typename GenType3>
/*return-type*/ bitselect(GenType1 a, GenType2 b, GenType3 c);
Available only if all of the following conditions are met:
GenType1is one of the following types:One of the generic scalar types as defined above;
sycl::marray<T, N>, whereTis one of the generic scalar types;sycl::vec<T, N>, whereTis one of the vector element types as defined above;__swizzled_vec__that is convertible tosycl::vec<T, N>, whereTis one of the vector element types;
If
GenType1is notsycl::vecor the__swizzled_vec__type, thenGenType2andGenType3must be the same asGenType1;If
GenType1issycl::vecor the__swizzled_vec__type, thenGenType2andGenType3must also besycl::vecor the__swizzled_vec__type, and all three must have the same element type and the same number of elements.
When the input parameters are scalars, returns a result where each
bit of the result is the corresponding bit of a if the
corresponding bit of c is 0. Otherwise it is the corresponding
bit of b.
When the input parameters are not scalars, returns a result for
each element where each bit of the result for element i is
the corresponding bit of a[i] if the corresponding bit of
c[i] is 0. Otherwise it is the corresponding bit of b[i].
The return type is GenType1 unless GenType1 is the
__swizzled_vec__ type, in which case the return type is
the corresponding sycl::vec.
sycl::select#
Overload 1
template<typename Scalar>
Scalar select(Scalar a, Scalar b, bool c);
Available only if Scalar is one of the generic scalar types as defined above.
Returns the value (c ? b : a).
Overload 2
template<typename NonScalar1, typename NonScalar2, typename NonScalar3>
/*return-type*/ select(NonScalar1 a, NonScalar2 b, NonScalar3 c);
Available only if all of the following conditions are met:
NonScalar1is one of the following types:sycl::marray<T, N>, whereTis one of the generic scalar types as defined above;sycl::vec<T, N>, whereTis one of the vector element types as defined above;__swizzled_vec__that is convertible tosycl::vec<T, N>, whereTis one of the vector element types;
If
NonScalar1issycl::marray, then:NonScalar2must be the same asNonScalar1;NonScalar3must besycl::marraywith element type bool and the same number of elements asNonScalar1;
If
NonScalar1issycl::vecor the__swizzled_vec__type, then:NonScalar2must also besycl::vecor the__swizzled_vec__type, and both must have the same element type and the same number of elements; andNonScalar3must besycl::vecor the__swizzled_vec__type with the same number of elements asNonScalar1. The element type ofNonScalar3must be a signed or unsigned integer with the same number of bits as the element type ofNonScalar1.
If NonScalar1 is sycl::marray, return the value (c[i] ? b[i] : a[i])
for each element of a, b, and c.
If NonScalar1 is sycl::vec or the __swizzled_vec__ type,
returns the value ((MSB of c[i] is set) ? b[i] : a[i]) for each
element of a, b, and c.
The return type is NonScalar1 unless NonScalar1 is the
__swizzled_vec__ type, in which case the return type is the
corresponding sycl::vec.