|
| 1 | +// The test verifies support of bfloat16 <-> float conversions |
| 2 | + |
| 3 | +// Checks host+device compilation |
| 4 | +// RUN: %clangxx -fsycl -fsyntax-only %s |
| 5 | + |
| 6 | +// Checks that lowerESIMD pass builds proper vc-intrinsics |
| 7 | +// RUN: %clangxx -O2 -fsycl -c -fsycl-device-only -Xclang -emit-llvm %s -o %t |
| 8 | +// RUN: sycl-post-link -split-esimd -lower-esimd -O0 -S %t -o %t.table |
| 9 | +// RUN: FileCheck %s -input-file=%t_esimd_0.ll |
| 10 | + |
| 11 | +#include <sycl/ext/intel/esimd.hpp> |
| 12 | +#include <sycl/sycl.hpp> |
| 13 | + |
| 14 | +using namespace sycl::ext::intel::esimd; |
| 15 | + |
| 16 | +SYCL_ESIMD_FUNCTION SYCL_EXTERNAL void bf16_vector(); |
| 17 | +SYCL_ESIMD_FUNCTION SYCL_EXTERNAL void bf16_scalar(); |
| 18 | + |
| 19 | +using bfloat16 = sycl::ext::oneapi::bfloat16; |
| 20 | + |
| 21 | +class EsimdFunctor { |
| 22 | +public: |
| 23 | + void operator()() __attribute__((sycl_explicit_simd)) { |
| 24 | + bf16_vector(); |
| 25 | + bf16_scalar(); |
| 26 | + } |
| 27 | +}; |
| 28 | + |
| 29 | +template <typename name, typename Func> |
| 30 | +__attribute__((sycl_kernel)) void kernel(Func kernelFunc) { |
| 31 | + kernelFunc(); |
| 32 | +} |
| 33 | + |
| 34 | +SYCL_ESIMD_FUNCTION SYCL_EXTERNAL void bf16_vector() { |
| 35 | + simd<float, 8> F32 = 0; |
| 36 | + simd<bfloat16, 8> BF16 = F32; |
| 37 | + // CHECK: call <8 x half> @llvm.genx.bf.cvt.v8f16.v8f32(<8 x float> {{[^)]+}}) |
| 38 | + simd<float, 8> F32_conv = BF16; |
| 39 | + // CHECK: call <8 x float> @llvm.genx.bf.cvt.v8f32.v8f16(<8 x half> {{[^)]+}}) |
| 40 | +} |
| 41 | + |
| 42 | +SYCL_ESIMD_FUNCTION SYCL_EXTERNAL void bf16_scalar() { |
| 43 | + // Note that this is the compilation test only. It checks that IR is correct. |
| 44 | + // The actual support in GPU RT is on the way though. |
| 45 | + float F32_scalar = 1; |
| 46 | + bfloat16 BF16_scalar = F32_scalar; |
| 47 | + // CHECK: call spir_func zeroext i16 @__devicelib_ConvertFToBF16INTEL(float {{[^)]+}}) |
| 48 | + float F32_scalar_conv = BF16_scalar; |
| 49 | + // CHECK: call spir_func float @__devicelib_ConvertBF16ToFINTEL(i16 {{[^)]+}}) |
| 50 | +} |
0 commit comments