Skip to content

Commit 73cf85d

Browse files
OuadiElfaroukiAlcpzjoeatoddYihan Wang
authored
[SYCL][COMPAT] Add math extend_vcompare[2/4] to SYCLCompat (#14079)
This PR adds math `extend_vcompare[2/4] `operators (4 in total) along with unit-tests for signed and unsigned int32 cases. Also, Unit-tests from previous `extend_v*4` #14078 and `extend_v*2` #13953 are moved to two different files. --------- Co-authored-by: Alberto Cabrera Pérez <[email protected]> Co-authored-by: Joe Todd <[email protected]> Co-authored-by: Yihan Wang <[email protected]>
1 parent f9fd95e commit 73cf85d

File tree

4 files changed

+678
-335
lines changed

4 files changed

+678
-335
lines changed

sycl/doc/syclcompat/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,73 @@ template <typename RetT, typename AT, typename BT>
24162416
inline constexpr RetT extend_vavrg4_sat(AT a, BT b, RetT c);
24172417
```
24182418

2419+
Vectorized comparison APIs also provided in the math header behave similarly
2420+
and support a `std` comparison operator parameter which can be `greater`,
2421+
`less`, `greater_equal`, `less_equal`, `equal_to` or `not_equal_to`. These APIs
2422+
cover both the 2-elements *(16-bits each)* and 4-elements *(8-bits each)*
2423+
variants, as well as an additional `_add` variant that computes the sum of the
2424+
2/4 output elements.
2425+
2426+
```cpp
2427+
/// Extend \p a and \p b to 33 bit and vectorized compare input values using
2428+
/// specified comparison \p cmp .
2429+
///
2430+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
2431+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
2432+
/// \tparam [in] BinaryOperation The type of the compare operation
2433+
/// \param [in] a The first value
2434+
/// \param [in] b The second value
2435+
/// \param [in] cmp The comparsion operator
2436+
/// \returns The comparison result of the two extended values.
2437+
template <typename AT, typename BT, typename BinaryOperation>
2438+
inline constexpr unsigned extend_vcompare2(AT a, BT b, BinaryOperation cmp);
2439+
2440+
/// Extend Inputs to 33 bit, and vectorized compare input values using specified
2441+
/// comparison \p cmp , then add the result with \p c .
2442+
///
2443+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
2444+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
2445+
/// \tparam [in] BinaryOperation The type of the compare operation
2446+
/// \param [in] a The first value
2447+
/// \param [in] b The second value
2448+
/// \param [in] c The third value
2449+
/// \param [in] cmp The comparsion operator
2450+
/// \returns The comparison result of the two extended values, and add the
2451+
/// result with \p c .
2452+
template <typename AT, typename BT, typename BinaryOperation>
2453+
inline constexpr unsigned extend_vcompare2_add(AT a, BT b, unsigned c,
2454+
BinaryOperation cmp);
2455+
2456+
/// Extend \p a and \p b to 33 bit and vectorized compare input values using
2457+
/// specified comparison \p cmp .
2458+
///
2459+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
2460+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
2461+
/// \tparam [in] BinaryOperation The type of the compare operation
2462+
/// \param [in] a The first value
2463+
/// \param [in] b The second value
2464+
/// \param [in] cmp The comparsion operator
2465+
/// \returns The comparison result of the two extended values.
2466+
template <typename AT, typename BT, typename BinaryOperation>
2467+
inline constexpr unsigned extend_vcompare4(AT a, BT b, BinaryOperation cmp);
2468+
2469+
/// Extend Inputs to 33 bit, and vectorized compare input values using specified
2470+
/// comparison \p cmp , then add the result with \p c .
2471+
///
2472+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
2473+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
2474+
/// \tparam [in] BinaryOperation The type of the compare operation
2475+
/// \param [in] a The first value
2476+
/// \param [in] b The second value
2477+
/// \param [in] c The third value
2478+
/// \param [in] cmp The comparsion operator
2479+
/// \returns The comparison result of the two extended values, and add the
2480+
/// result with \p c .
2481+
template <typename AT, typename BT, typename BinaryOperation>
2482+
inline constexpr unsigned extend_vcompare4_add(AT a, BT b, unsigned c,
2483+
BinaryOperation cmp);
2484+
```
2485+
24192486
The math header file provides APIs for bit-field insertion (`bfi_safe`) and
24202487
bit-field extraction (`bfe_safe`). These are bounds-checked variants of
24212488
underlying `detail` APIs (`detail::bfi`, `detail::bfe`) which, in future

sycl/include/syclcompat/math.hpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,39 @@ inline constexpr RetT extend_vavrg2_sat(AT a, BT b, RetT c) {
18561856
return detail::extend_vbinary2<RetT, true, false>(a, b, c, detail::average());
18571857
}
18581858

1859+
/// Extend \p a and \p b to 33 bit and vectorized compare input values using
1860+
/// specified comparison \p cmp .
1861+
///
1862+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
1863+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
1864+
/// \tparam [in] BinaryOperation The type of the compare operation
1865+
/// \param [in] a The first value
1866+
/// \param [in] b The second value
1867+
/// \param [in] cmp The comparsion operator
1868+
/// \returns The comparison result of the two extended values.
1869+
template <typename AT, typename BT, typename BinaryOperation>
1870+
inline constexpr unsigned extend_vcompare2(AT a, BT b, BinaryOperation cmp) {
1871+
return detail::extend_vbinary2<unsigned, false, false>(a, b, 0, cmp);
1872+
}
1873+
1874+
/// Extend Inputs to 33 bit, and vectorized compare input values using specified
1875+
/// comparison \p cmp , then add the result with \p c .
1876+
///
1877+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
1878+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
1879+
/// \tparam [in] BinaryOperation The type of the compare operation
1880+
/// \param [in] a The first value
1881+
/// \param [in] b The second value
1882+
/// \param [in] c The third value
1883+
/// \param [in] cmp The comparsion operator
1884+
/// \returns The comparison result of the two extended values, and add the
1885+
/// result with \p c .
1886+
template <typename AT, typename BT, typename BinaryOperation>
1887+
inline constexpr unsigned extend_vcompare2_add(AT a, BT b, unsigned c,
1888+
BinaryOperation cmp) {
1889+
return detail::extend_vbinary2<unsigned, false, true>(a, b, c, cmp);
1890+
}
1891+
18591892
/// Compute vectorized addition of \p a and \p b, with each value treated as a
18601893
/// 4 elements vector type and extend each element to 9 bit.
18611894
/// \tparam [in] RetT The type of the return value, can only be 32 bit integer
@@ -2121,4 +2154,37 @@ inline constexpr RetT extend_vavrg4_sat(AT a, BT b, RetT c) {
21212154
return detail::extend_vbinary4<RetT, true, false>(a, b, c, detail::average());
21222155
}
21232156

2157+
/// Extend \p a and \p b to 33 bit and vectorized compare input values using
2158+
/// specified comparison \p cmp .
2159+
///
2160+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
2161+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
2162+
/// \tparam [in] BinaryOperation The type of the compare operation
2163+
/// \param [in] a The first value
2164+
/// \param [in] b The second value
2165+
/// \param [in] cmp The comparsion operator
2166+
/// \returns The comparison result of the two extended values.
2167+
template <typename AT, typename BT, typename BinaryOperation>
2168+
inline constexpr unsigned extend_vcompare4(AT a, BT b, BinaryOperation cmp) {
2169+
return detail::extend_vbinary4<unsigned, false, false>(a, b, 0, cmp);
2170+
}
2171+
2172+
/// Extend Inputs to 33 bit, and vectorized compare input values using specified
2173+
/// comparison \p cmp , then add the result with \p c .
2174+
///
2175+
/// \tparam [in] AT The type of the first value, can only be 32 bit integer
2176+
/// \tparam [in] BT The type of the second value, can only be 32 bit integer
2177+
/// \tparam [in] BinaryOperation The type of the compare operation
2178+
/// \param [in] a The first value
2179+
/// \param [in] b The second value
2180+
/// \param [in] c The third value
2181+
/// \param [in] cmp The comparsion operator
2182+
/// \returns The comparison result of the two extended values, and add the
2183+
/// result with \p c .
2184+
template <typename AT, typename BT, typename BinaryOperation>
2185+
inline constexpr unsigned extend_vcompare4_add(AT a, BT b, unsigned c,
2186+
BinaryOperation cmp) {
2187+
return detail::extend_vbinary4<unsigned, false, true>(a, b, c, cmp);
2188+
}
2189+
21242190
} // namespace syclcompat

0 commit comments

Comments
 (0)