Skip to content

Commit 4e2a9cf

Browse files
committed
Add inline to function templates to avoid multiple definitions.
1 parent 02d6322 commit 4e2a9cf

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

sycl/include/sycl/ext/oneapi/bfloat16.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ extern "C" __DPCPP_SYCL_EXTERNAL void
232232
__devicelib_ConvertBF16ToFINTELVec16(const uint16_t *, float *) noexcept;
233233
#endif
234234

235-
template <int N> void BF16VecToFloatVec(const bfloat16 src[N], float dst[N]) {
235+
template <int N>
236+
inline void BF16VecToFloatVec(const bfloat16 src[N], float dst[N]) {
236237
static_assert(N == 1 || N == 2 || N == 3 || N == 4 || N == 8 || N == 16,
237238
"Unsupported vector size");
238239
#if defined(__SYCL_DEVICE_ONLY__) && (defined(__SPIR__) || defined(__SPIRV__))
@@ -272,7 +273,7 @@ extern "C" __DPCPP_SYCL_EXTERNAL void
272273
__devicelib_ConvertFToBF16INTELVec16(const float *, uint16_t *) noexcept;
273274
#endif
274275

275-
template <int N> void FloatVecToBF16Vec(float src[N], bfloat16 dst[N]) {
276+
template <int N> inline void FloatVecToBF16Vec(float src[N], bfloat16 dst[N]) {
276277
static_assert(N == 1 || N == 2 || N == 3 || N == 4 || N == 8 || N == 16,
277278
"Unsupported vector size");
278279
#if defined(__SYCL_DEVICE_ONLY__) && (defined(__SPIR__) || defined(__SPIRV__))
@@ -436,7 +437,7 @@ inline bfloat16 getBFloat16FromDoubleWithRTE(const double &d) {
436437
}
437438

438439
// Function to get the most significant bit position of a number.
439-
template <typename Ty> size_t get_msb_pos(const Ty &x) {
440+
template <typename Ty> inline size_t get_msb_pos(const Ty &x) {
440441
assert(x != 0);
441442
size_t idx = 0;
442443
Ty mask = ((Ty)1 << (sizeof(Ty) * 8 - 1));
@@ -454,7 +455,7 @@ template <typename Ty> size_t get_msb_pos(const Ty &x) {
454455
// Reference:
455456
// https://github.com/intel/llvm/blob/sycl/libdevice/imf_bf16.hpp#L302
456457
template <typename T>
457-
bfloat16
458+
inline bfloat16
458459
getBFloat16FromUIntegralWithRoundingMode(T &u, SYCLRoundingMode roundingMode) {
459460

460461
size_t msb_pos = get_msb_pos(u);
@@ -508,7 +509,7 @@ getBFloat16FromUIntegralWithRoundingMode(T &u, SYCLRoundingMode roundingMode) {
508509
// Reference:
509510
// https://github.com/intel/llvm/blob/sycl/libdevice/imf_bf16.hpp#L353
510511
template <typename T>
511-
bfloat16
512+
inline bfloat16
512513
getBFloat16FromSIntegralWithRoundingMode(T &i, SYCLRoundingMode roundingMode) {
513514
// Get unsigned type corresponding to T.
514515
typedef typename std::make_unsigned_t<T> UTy;
@@ -557,9 +558,8 @@ getBFloat16FromSIntegralWithRoundingMode(T &i, SYCLRoundingMode roundingMode) {
557558
}
558559

559560
template <typename Ty, int rm>
560-
bfloat16 getBfloat16WithRoundingMode(const Ty &a) {
561-
562-
if (!a)
561+
inline bfloat16 getBfloat16WithRoundingMode(const Ty &a) {
562+
if (a == 0)
563563
return bfloat16{0.0f};
564564

565565
constexpr SYCLRoundingMode roundingMode = static_cast<SYCLRoundingMode>(rm);

0 commit comments

Comments
 (0)