diff --git a/sycl/include/sycl/ext/intel/esimd/detail/bfloat16_type_traits.hpp b/sycl/include/sycl/ext/intel/esimd/detail/bfloat16_type_traits.hpp index 2d0c17a3c6100..6a935ae9c3390 100644 --- a/sycl/include/sycl/ext/intel/esimd/detail/bfloat16_type_traits.hpp +++ b/sycl/include/sycl/ext/intel/esimd/detail/bfloat16_type_traits.hpp @@ -94,6 +94,8 @@ inline std::ostream &operator<<(std::ostream &O, bfloat16 const &rhs) { return O; } +template <> struct is_esimd_arithmetic_type : std::true_type {}; + } // namespace ext::intel::esimd::detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/ext/oneapi/bfloat16.hpp b/sycl/include/sycl/ext/oneapi/bfloat16.hpp index 7ff30b9438f9d..38af8fe5358a2 100644 --- a/sycl/include/sycl/ext/oneapi/bfloat16.hpp +++ b/sycl/include/sycl/ext/oneapi/bfloat16.hpp @@ -198,17 +198,6 @@ class bfloat16 { float f = static_cast(lhs); \ f op static_cast(rhs); \ return lhs = f; \ - } \ - template \ - friend bfloat16 &operator op(bfloat16 & lhs, const T & rhs) { \ - float f = static_cast(lhs); \ - f op static_cast(rhs); \ - return lhs = f; \ - } \ - template friend T &operator op(T & lhs, const bfloat16 & rhs) { \ - float f = static_cast(lhs); \ - f op static_cast(rhs); \ - return lhs = f; \ } OP(+=) OP(-=) @@ -222,11 +211,13 @@ class bfloat16 { return type{static_cast(lhs) op static_cast(rhs)}; \ } \ template \ - friend type operator op(const bfloat16 &lhs, const T &rhs) { \ + friend std::enable_if_t, type> operator op( \ + const bfloat16 & lhs, const T & rhs) { \ return type{static_cast(lhs) op static_cast(rhs)}; \ } \ template \ - friend type operator op(const T &lhs, const bfloat16 &rhs) { \ + friend std::enable_if_t, type> operator op( \ + const T & lhs, const bfloat16 & rhs) { \ return type{static_cast(lhs) op static_cast(rhs)}; \ } OP(bfloat16, +) diff --git a/sycl/test-e2e/ESIMD/regression/bfloat16_half_vector_plus_eq_scalar.cpp b/sycl/test-e2e/ESIMD/regression/bfloat16_half_vector_plus_eq_scalar.cpp index e6b456100762f..e78f0e22045ef 100644 --- a/sycl/test-e2e/ESIMD/regression/bfloat16_half_vector_plus_eq_scalar.cpp +++ b/sycl/test-e2e/ESIMD/regression/bfloat16_half_vector_plus_eq_scalar.cpp @@ -91,8 +91,7 @@ int main() { } #ifdef USE_BF16 -// TODO: Reenable once the issue with bfloat16 is resolved -// Passed &= test(Q); + Passed &= test(Q); #endif #ifdef USE_TF32 Passed &= test(Q); diff --git a/sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar.cpp b/sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar.cpp new file mode 100644 index 0000000000000..7f6388b0ffc2e --- /dev/null +++ b/sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar.cpp @@ -0,0 +1,100 @@ +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out +//==- bfloat16_vector_plus_scalar.cpp - Test for bfloat16 operators ------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#include "../esimd_test_utils.hpp" +#include +#include +#include + +using namespace sycl; +using namespace sycl::ext::intel::esimd; +using namespace sycl::ext::intel::experimental::esimd; + +template ESIMD_NOINLINE bool test(queue Q) { + std::cout << "Testing T=" << esimd_test::type_name() << "...\n"; + + constexpr int N = 8; + + constexpr int NumOps = 4; + constexpr int CSize = NumOps * N; + + T *Mem = malloc_shared(CSize, Q); + T TOne = static_cast(1); + T TTen = static_cast(10); + + Q.single_task([=]() SYCL_ESIMD_KERNEL { + { + simd Vec(TOne); + Vec = Vec + TTen; + Vec.copy_to(Mem); + } + { + simd Vec(TOne); + Vec = Vec - TTen; + Vec.copy_to(Mem + N); + } + { + simd Vec(TOne); + Vec = Vec * TTen; + Vec.copy_to(Mem + 2 * N); + } + { + simd Vec(TOne); + Vec = Vec / TTen; + Vec.copy_to(Mem + 3 * N); + } + }).wait(); + + bool ReturnValue = true; + for (int i = 0; i < N; ++i) { + if (Mem[i] != TOne + TTen) { + ReturnValue = false; + break; + } + if (Mem[i + N] != TOne - TTen) { + ReturnValue = false; + break; + } + if (Mem[i + 2 * N] != TOne * TTen) { + ReturnValue = false; + break; + } + if (!((Mem[i + 3 * N] == (TOne / TTen)) || + (std::abs((double)(Mem[i + 3 * N] - (TOne / TTen)) / + (double)(TOne / TTen)) <= 0.001))) { + ReturnValue = false; + break; + } + } + + free(Mem, Q); + return ReturnValue; +} + +int main() { + queue Q; + esimd_test::printTestLabel(Q); + + bool SupportsHalf = Q.get_device().has(aspect::fp16); + + bool Passed = true; + Passed &= test(Q); + Passed &= test(Q); + if (SupportsHalf) { + Passed &= test(Q); + } +#ifdef USE_BF16 + Passed &= test(Q); +#endif +#ifdef USE_TF32 + Passed &= test(Q); +#endif + std::cout << (Passed ? "Passed\n" : "FAILED\n"); + return Passed ? 0 : 1; +} \ No newline at end of file diff --git a/sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar_pvc.cpp b/sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar_pvc.cpp new file mode 100644 index 0000000000000..2bffa62cc3337 --- /dev/null +++ b/sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar_pvc.cpp @@ -0,0 +1,17 @@ +//==- bfloat16_vector_plus_scalar_pvc.cpp - Test for bfloat16 operators -==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// This test validates operations between simd vector and scalars for +// bfloat16 and tfloat32 types that are available only on PVC. +//===----------------------------------------------------------------------===// +// REQUIRES: gpu-intel-pvc +// RUN: %{build} -o %t.out +// RUN: %{run} %t.out + +#define USE_BF16 +#define USE_TF32 +#include "bfloat16_vector_plus_scalar.cpp" \ No newline at end of file diff --git a/sycl/test/type_traits/half_operator_types.cpp b/sycl/test/type_traits/half_operator_types.cpp index e0190935a4f85..17558d5c179ad 100644 --- a/sycl/test/type_traits/half_operator_types.cpp +++ b/sycl/test/type_traits/half_operator_types.cpp @@ -103,6 +103,8 @@ int main() { check_half_math_operator_types(Queue); check_half_math_operator_types(Queue); check_half_math_operator_types(Queue); + check_half_math_operator_types(Queue); check_half_logical_operator_types(Queue); check_half_logical_operator_types(Queue); @@ -110,4 +112,5 @@ int main() { check_half_logical_operator_types(Queue); check_half_logical_operator_types(Queue); check_half_logical_operator_types(Queue); + check_half_logical_operator_types(Queue); }