Skip to content

Commit 276b3c2

Browse files
[SYCL] Disable _bf16 instrinsics for SYCL (#7338)
This fixes compilation errors of immintrin.h
1 parent 4be64e7 commit 276b3c2

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

clang/lib/Headers/avxintrin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ typedef _Float16 __v16hf __attribute__((__vector_size__(32), __aligned__(32)));
4545
typedef _Float16 __m256h __attribute__((__vector_size__(32), __aligned__(32)));
4646
typedef _Float16 __m256h_u __attribute__((__vector_size__(32), __aligned__(1)));
4747

48+
#ifndef __SYCL_DEVICE_ONLY__
4849
typedef __bf16 __v16bf __attribute__((__vector_size__(32), __aligned__(32)));
4950
typedef __bf16 __m256bh __attribute__((__vector_size__(32), __aligned__(32)));
5051
#endif
52+
#endif
5153

5254
/* Define the default attributes for the functions in this file. */
5355
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("avx"), __min_vector_width__(256)))

clang/lib/Headers/avxneconvertintrin.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
__attribute__((__always_inline__, __nodebug__, __target__("avxneconvert"), \
2626
__min_vector_width__(256)))
2727

28+
#ifndef __SYCL_DEVICE_ONLY__
2829
/// Convert scalar BF16 (16-bit) floating-point element
2930
/// stored at memory locations starting at location \a __A to a
3031
/// single-precision (32-bit) floating-point, broadcast it to packed
@@ -90,6 +91,7 @@ static __inline__ __m256 __DEFAULT_FN_ATTRS256
9091
_mm256_bcstnebf16_ps(const void *__A) {
9192
return (__m256)__builtin_ia32_vbcstnebf162ps256((const __bf16 *)__A);
9293
}
94+
#endif
9395

9496
/// Convert scalar half-precision (16-bit) floating-point element
9597
/// stored at memory locations starting at location \a __A to a
@@ -157,6 +159,7 @@ _mm256_bcstnesh_ps(const void *__A) {
157159
return (__m256)__builtin_ia32_vbcstnesh2ps256((const _Float16 *)__A);
158160
}
159161

162+
#ifndef __SYCL_DEVICE_ONLY__
160163
/// Convert packed BF16 (16-bit) floating-point even-indexed elements
161164
/// stored at memory locations starting at location \a __A to packed
162165
/// single-precision (32-bit) floating-point elements, and store the results in
@@ -222,6 +225,7 @@ static __inline__ __m256 __DEFAULT_FN_ATTRS256
222225
_mm256_cvtneebf16_ps(const __m256bh *__A) {
223226
return (__m256)__builtin_ia32_vcvtneebf162ps256((const __v16bf *)__A);
224227
}
228+
#endif
225229

226230
/// Convert packed half-precision (16-bit) floating-point even-indexed elements
227231
/// stored at memory locations starting at location \a __A to packed
@@ -289,6 +293,7 @@ _mm256_cvtneeph_ps(const __m256h *__A) {
289293
return (__m256)__builtin_ia32_vcvtneeph2ps256((const __v16hf *)__A);
290294
}
291295

296+
#ifndef __SYCL_DEVICE_ONLY__
292297
/// Convert packed BF16 (16-bit) floating-point odd-indexed elements
293298
/// stored at memory locations starting at location \a __A to packed
294299
/// single-precision (32-bit) floating-point elements, and store the results in
@@ -354,6 +359,7 @@ static __inline__ __m256 __DEFAULT_FN_ATTRS256
354359
_mm256_cvtneobf16_ps(const __m256bh *__A) {
355360
return (__m256)__builtin_ia32_vcvtneobf162ps256((const __v16bf *)__A);
356361
}
362+
#endif
357363

358364
/// Convert packed half-precision (16-bit) floating-point odd-indexed elements
359365
/// stored at memory locations starting at location \a __A to packed
@@ -421,6 +427,7 @@ _mm256_cvtneoph_ps(const __m256h *__A) {
421427
return (__m256)__builtin_ia32_vcvtneoph2ps256((const __v16hf *)__A);
422428
}
423429

430+
#ifndef __SYCL_DEVICE_ONLY__
424431
/// Convert packed single-precision (32-bit) floating-point elements in \a __A
425432
/// to packed BF16 (16-bit) floating-point elements, and store the results in \a
426433
/// dst.
@@ -476,6 +483,7 @@ static __inline__ __m128bh __DEFAULT_FN_ATTRS256
476483
_mm256_cvtneps_avx_pbh(__m256 __A) {
477484
return (__m128bh)__builtin_ia32_vcvtneps2bf16256((__v8sf)__A);
478485
}
486+
#endif
479487

480488
#undef __DEFAULT_FN_ATTRS128
481489
#undef __DEFAULT_FN_ATTRS256

clang/lib/Headers/emmintrin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ typedef _Float16 __v8hf __attribute__((__vector_size__(16), __aligned__(16)));
4444
typedef _Float16 __m128h __attribute__((__vector_size__(16), __aligned__(16)));
4545
typedef _Float16 __m128h_u __attribute__((__vector_size__(16), __aligned__(1)));
4646

47+
#ifndef __SYCL_DEVICE_ONLY__
4748
typedef __bf16 __v8bf __attribute__((__vector_size__(16), __aligned__(16)));
4849
typedef __bf16 __m128bh __attribute__((__vector_size__(16), __aligned__(16)));
4950
#endif
51+
#endif
5052

5153
/* Define the default attributes for the functions in this file. */
5254
#define __DEFAULT_FN_ATTRS \

clang/lib/Headers/immintrin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
#include <avx512vlfp16intrin.h>
230230
#endif
231231

232+
#ifndef __SYCL_DEVICE_ONLY__
232233
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
233234
defined(__AVX512BF16__)
234235
#include <avx512bf16intrin.h>
@@ -238,6 +239,7 @@
238239
(defined(__AVX512VL__) && defined(__AVX512BF16__))
239240
#include <avx512vlbf16intrin.h>
240241
#endif
242+
#endif
241243

242244
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
243245
defined(__PKU__)

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,13 +1527,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
15271527
break;
15281528
case DeclSpec::TST_half: Result = Context.HalfTy; break;
15291529
case DeclSpec::TST_BFloat16:
1530-
// Disable errors for SYCL and OpenMP device since definition of __bf16 is
1531-
// being moved to a shared header and it causes new errors emitted when
1532-
// host code is compiled with device compiler for SPIR target.
1533-
// FIXME: device code specific diagnostic is probably needed.
1534-
if (!S.Context.getTargetInfo().hasBFloat16Type() &&
1535-
!S.getLangOpts().SYCLIsDevice && !S.getLangOpts().OpenMPIsDevice)
1536-
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported) << "__bf16";
1530+
if (!S.Context.getTargetInfo().hasBFloat16Type())
1531+
S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_unsupported)
1532+
<< "__bf16";
15371533
Result = Context.BFloat16Ty;
15381534
break;
15391535
case DeclSpec::TST_float: Result = Context.FloatTy; break;
@@ -2730,15 +2726,8 @@ QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
27302726
}
27312727

27322728
if (!TypeSize || VectorSizeBits % TypeSize) {
2733-
// Disable errors for SYCL and OpenMP device since definition of __bf16 is
2734-
// being moved to a shared header and it causes new errors emitted when
2735-
// host code is compiled with device compiler for SPIR target.
2736-
// FIXME: device code specific diagnostic is probably needed.
2737-
if (!(!TypeSize &&
2738-
(getLangOpts().OpenMPIsDevice || getLangOpts().SYCLIsDevice))) {
27392729
Diag(AttrLoc, diag::err_attribute_invalid_size)
27402730
<< SizeExpr->getSourceRange();
2741-
}
27422731
return QualType();
27432732
}
27442733

0 commit comments

Comments
 (0)