Skip to content

[SYCL][ESIMD] Fix logic and arithmetic operators for simd_view with scalar #4680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ namespace __SEIEE {
class = std::enable_if_t< \
__SEIEED::is_any_simd_view_type_v<SimdViewT2> && COND>> \
inline auto operator BINOP(T1 LHS, const SimdViewT2 &RHS) { \
using SimdT = typename SimdViewT2::value_type; \
return SimdT(LHS) BINOP RHS.read(); \
return LHS BINOP RHS.read(); \
} \
\
/* simd_view BINOP SCALAR */ \
Expand All @@ -301,8 +300,7 @@ namespace __SEIEE {
class = std::enable_if_t< \
__SEIEED::is_any_simd_view_type_v<SimdViewT1> && COND>> \
inline auto operator BINOP(const SimdViewT1 &LHS, T2 RHS) { \
using SimdT = typename SimdViewT1::value_type; \
return LHS.read() BINOP SimdT(RHS); \
return LHS.read() BINOP RHS; \
}

#define __ESIMD_BITWISE_OP_FILTER \
Expand Down
22 changes: 22 additions & 0 deletions sycl/test/esimd/simd_view_bin_op.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %clangxx -fsycl -fsycl-device-only -S -emit-llvm -x c++ %s -o - | FileCheck %s

// This test checks that arithmetic opration on simd_view and scalar does not
// truncate scalar to the view's element type.

#include <sycl/ext/intel/experimental/esimd.hpp>

using namespace sycl::ext::intel::experimental::esimd;

simd<short, 4> test1(int X, simd<short, 16> Y) __attribute__((sycl_device)) {
// CHECK-LABEL: test1
// CHECK-SAME: i32 [[X:%.+]],
// CHECK-NOT: trunc i32 [[X]] to i16
return X * Y.select<4, 1>(0);
}

simd<short, 4> test2(int X, simd<short, 16> Y) __attribute__((sycl_device)) {
// CHECK-LABEL: test2
// CHECK-SAME: i32 [[X:%.+]],
// CHECK-NOT: trunc i32 [[X]] to i16
return Y.select<4, 1>(0) * X;
}