Skip to content

Commit 506f279

Browse files
authored
[ESIMD] Fix errors caused by move of bfloat16 from experimental ns (#… (#7981)
…9143) The error in LIT test esimd/intel_fp16_converts.cpp is caused by #6524 which - moved 'bfloat16' out of 'experimental' namespace - created a wrapper __devicelib_ConvertBF16ToFINTEL() which simply calls __spirv_ConvertBF16ToFINTEL() The fix - creates a test for bfloat16 conversions. - allows __devicelib_ConvertBF16ToFINTEL() and __devicelib_ConvertFToBF16INTEL() for ESIMD context. Signed-off-by: Vyacheslav N Klochkov <vyacheslav.n.klochkov@intel.com>
1 parent 8a7cf2b commit 506f279

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
261261
const IdentifierInfo *Id = FDecl->getIdentifier();
262262
if ((getEmissionReason(FDecl) == Sema::DeviceDiagnosticReason::Sycl) &&
263263
Id && !Id->getName().startswith("__spirv_") &&
264-
!Id->getName().startswith("__sycl_")) {
264+
!Id->getName().startswith("__sycl_") &&
265+
!Id->getName().startswith("__devicelib_ConvertBF16ToFINTEL") &&
266+
!Id->getName().startswith("__devicelib_ConvertFToBF16INTEL")) {
265267
SYCLDiagIfDeviceCode(
266268
*Locs.begin(), diag::err_sycl_device_function_is_called_from_esimd,
267269
Sema::DeviceDiagnosticReason::Esimd);

llvm/lib/SYCLLowerIR/ESIMD/ESIMDVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static const char *LegalSYCLFunctions[] = {
5454
"^sycl::_V1::ext::oneapi::sub_group::.+",
5555
"^sycl::_V1::ext::oneapi::experimental::spec_constant<.+>::.+",
5656
"^sycl::_V1::ext::oneapi::experimental::this_sub_group",
57-
"^sycl::_V1::ext::oneapi::experimental::bfloat16::.+",
57+
"^sycl::_V1::ext::oneapi::bfloat16::.+",
5858
"^sycl::_V1::ext::oneapi::experimental::if_architecture_is"};
5959

6060
static const char *LegalSYCLFunctionsInStatelessMode[] = {

sycl/test/esimd/fp16_converts.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)