-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Limit bfloat16 operators to scalar datatypes convertible to fl…
…oat (#12477) Aligns implementation with the spec: https://github.com/intel/llvm/blob/48ec4dd6ff45b25b405b99d63f3c5b8537b1475d/sycl/doc/extensions/supported/sycl_ext_oneapi_bfloat16.asciidoc It also enables the ESIMD tests for bfloat16 type arithmetics.
- Loading branch information
Showing
6 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <iostream> | ||
#include <sycl/ext/intel/esimd.hpp> | ||
#include <sycl/sycl.hpp> | ||
|
||
using namespace sycl; | ||
using namespace sycl::ext::intel::esimd; | ||
using namespace sycl::ext::intel::experimental::esimd; | ||
|
||
template <typename T> ESIMD_NOINLINE bool test(queue Q) { | ||
std::cout << "Testing T=" << esimd_test::type_name<T>() << "...\n"; | ||
|
||
constexpr int N = 8; | ||
|
||
constexpr int NumOps = 4; | ||
constexpr int CSize = NumOps * N; | ||
|
||
T *Mem = malloc_shared<T>(CSize, Q); | ||
T TOne = static_cast<T>(1); | ||
T TTen = static_cast<T>(10); | ||
|
||
Q.single_task([=]() SYCL_ESIMD_KERNEL { | ||
{ | ||
simd<T, N> Vec(TOne); | ||
Vec = Vec + TTen; | ||
Vec.copy_to(Mem); | ||
} | ||
{ | ||
simd<T, N> Vec(TOne); | ||
Vec = Vec - TTen; | ||
Vec.copy_to(Mem + N); | ||
} | ||
{ | ||
simd<T, N> Vec(TOne); | ||
Vec = Vec * TTen; | ||
Vec.copy_to(Mem + 2 * N); | ||
} | ||
{ | ||
simd<T, N> 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<int>(Q); | ||
Passed &= test<float>(Q); | ||
if (SupportsHalf) { | ||
Passed &= test<sycl::half>(Q); | ||
} | ||
#ifdef USE_BF16 | ||
Passed &= test<sycl::ext::oneapi::bfloat16>(Q); | ||
#endif | ||
#ifdef USE_TF32 | ||
Passed &= test<sycl::ext::intel::experimental::esimd::tfloat32>(Q); | ||
#endif | ||
std::cout << (Passed ? "Passed\n" : "FAILED\n"); | ||
return Passed ? 0 : 1; | ||
} |
17 changes: 17 additions & 0 deletions
17
sycl/test-e2e/ESIMD/regression/bfloat16_vector_plus_scalar_pvc.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters