Skip to content

Commit 0e72f02

Browse files
authored
[ESIMD] Fix is_esimd_arithmetic_type internal problem. (#4826)
In some cases 'computation_type_t' meta-function call lead to call to this template <class Ty> struct is_esimd_arithmetic_type< Ty, __esimd_void_t<std::enable_if_t<std::is_arithmetic_v<Ty>>, decltype(std::declval<Ty>() + std::declval<Ty>()), ...>> meta-function with Ty being a simd type, which caused decltype(std::declval<Ty>() + std::declval<Ty>()) to fail (it is not supposed to be invoked with a simd type). Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent d48d8bc commit 0e72f02

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

sycl/include/sycl/ext/intel/experimental/esimd/detail/types.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ struct is_esimd_arithmetic_type : std::false_type {};
179179

180180
template <class Ty>
181181
struct is_esimd_arithmetic_type<
182-
Ty, __esimd_void_t<decltype(std::declval<Ty>() + std::declval<Ty>()),
182+
Ty, __esimd_void_t<std::enable_if_t<std::is_arithmetic_v<Ty>>,
183+
decltype(std::declval<Ty>() + std::declval<Ty>()),
183184
decltype(std::declval<Ty>() - std::declval<Ty>()),
184185
decltype(std::declval<Ty>() * std::declval<Ty>()),
185186
decltype(std::declval<Ty>() / std::declval<Ty>())>>
186-
: std::conditional_t<std::is_arithmetic_v<Ty>, std::true_type,
187-
std::false_type> {};
187+
: std::true_type {};
188188

189189
template <typename Ty>
190190
static inline constexpr bool is_esimd_arithmetic_type_v =
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s
2+
// expected-no-diagnostics
3+
4+
// Check that is_esimd_arithmetic_type works as expected on simd and simd_view
5+
// types.
6+
7+
#include <sycl/ext/intel/experimental/esimd.hpp>
8+
9+
using namespace sycl::ext::intel::experimental::esimd;
10+
11+
constexpr bool foo0() {
12+
return __SEIEED::is_esimd_arithmetic_type_v<simd<int, 8>>;
13+
}
14+
15+
constexpr bool foo1() {
16+
return __SEIEED::is_esimd_arithmetic_type_v<
17+
simd_view<simd<int, 8>, region1d_t<int, 8, 1>>>;
18+
}
19+
20+
SYCL_EXTERNAL void foo() SYCL_ESIMD_FUNCTION {
21+
static_assert(!foo0() && !foo1(), "");
22+
}
23+
24+
// This models original user code where compilation failure occurred.
25+
// Similar code exists in operators.cpp, but somehow presence of '^='
26+
// operation (commented out below) hid the problem and compiler did not fail.
27+
SYCL_EXTERNAL auto foo2(simd<char, 8> x, simd<char, 8> x1,
28+
simd<char, 8> y) SYCL_ESIMD_FUNCTION {
29+
//{ auto k = x1 ^= x1; }
30+
{ auto v = x ^ y; }
31+
}

0 commit comments

Comments
 (0)