forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][ESIMD]Limit bfloat16 operators to scalars to enable operations…
… with simd vectors (intel#12089) The purpose of this change is to limit operators defined for bfloat16 to scalar types to allow arithmetic operations between bfloat16 scalars and simd vectors. This allows to use simd operators that are defined separately and support operations between vectors and scalars
- Loading branch information
Showing
5 changed files
with
282 additions
and
61 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; | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
//==- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// 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" |