aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Marquez Tello <pablo.tello@arm.com>2023-01-11 09:54:00 +0000
committerPablo Marquez Tello <pablo.tello@arm.com>2023-01-11 13:57:06 +0000
commit6bcdc578a388782f5ec80ec348c5dd3f5c1f8363 (patch)
tree07221f61b69faa7efb3280bf053667ef1906a470
parent1b2f868b7b55e3e952520f0380e9174696c3ad1b (diff)
downloadComputeLibrary-6bcdc578a388782f5ec80ec348c5dd3f5c1f8363.tar.gz
Deprecated BF16 support in DepthConvert
* Removed BF16 validation tests for DepthConvert * Revert back to using inline assembly to convert to/from BF16 * Resolves COMPMID-5800 Change-Id: I803b2ad19ead297417f780c97c5b724cca6b394c Signed-off-by: Pablo Marquez Tello <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/8929 Reviewed-by: Jakub Sujak <jakub.sujak@arm.com> Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--SConstruct4
-rw-r--r--filedefs.json2
-rw-r--r--src/core/NEON/wrapper/intrinsics/cvt.h22
-rw-r--r--src/cpu/kernels/CpuCastKernel.h4
-rw-r--r--src/cpu/kernels/cast/generic/neon/bfloat16.cpp94
-rw-r--r--src/cpu/operators/CpuCast.h5
-rw-r--r--tests/validation/NEON/DepthConvertLayer.cpp28
-rw-r--r--utils/TypePrinter.h4
8 files changed, 94 insertions, 69 deletions
diff --git a/SConstruct b/SConstruct
index 161b3f2c60..8603017f71 100644
--- a/SConstruct
+++ b/SConstruct
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright (c) 2016-2022 Arm Limited.
+# Copyright (c) 2016-2023 Arm Limited.
#
# SPDX-License-Identifier: MIT
#
@@ -302,7 +302,7 @@ if env['multi_isa']:
if "disable_mmla_fp" not in env['custom_options']:
env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM'])
- env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16+bf16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
+ env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined
else: # NONE "multi_isa" builds
diff --git a/filedefs.json b/filedefs.json
index c8a66e3429..3422eeb252 100644
--- a/filedefs.json
+++ b/filedefs.json
@@ -5,7 +5,7 @@
"cxxflags": ["-march=armv8.2-a"]
},
"armv8.2-a": {
- "cxxflags": ["-march=armv8.2-a+fp16+bf16"],
+ "cxxflags": ["-march=armv8.2-a+fp16"],
"cppdefines": ["ARM_COMPUTE_ENABLE_FP16"]
},
"armv8.2-a-sve": {
diff --git a/src/core/NEON/wrapper/intrinsics/cvt.h b/src/core/NEON/wrapper/intrinsics/cvt.h
index c75d43dbf2..1c77a9e9f0 100644
--- a/src/core/NEON/wrapper/intrinsics/cvt.h
+++ b/src/core/NEON/wrapper/intrinsics/cvt.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2022 Arm Limited.
+ * Copyright (c) 2020, 2022-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -87,6 +87,26 @@ vcvta(const float32x4_t &a)
return vcvtaq_s32_f32(a);
}
#endif //__aarch64__
+
+#if defined(ARM_COMPUTE_ENABLE_BF16)
+/** Convert 2x128-bit floating point vectors into 1x128-bit bfloat16 vector
+ *
+ * @param[in] inptr Pointer to the input memory to load values from
+ * @param[in,out] outptr Pointer to the output memory to store values to
+ */
+inline void vcvt_bf16_f32(const float *inptr, uint16_t *outptr)
+{
+ __asm __volatile(
+ "ldp q0, q1, [%[inptr]]\n"
+ ".inst 0xea16800\n" // BFCVTN v0, v0
+ ".inst 0x4ea16820\n" // BFCVTN2 v0, v1
+ "str q0, [%[outptr]]\n"
+ : [inptr] "+r"(inptr)
+ : [outptr] "r"(outptr)
+ : "v0", "v1", "memory");
+}
+#endif /* defined(ARM_COMPUTE_ENABLE_BF16) */
+
} // namespace wrapper
} // namespace arm_compute
#endif /* ARM_COMPUTE_WRAPPER_CVT_H */
diff --git a/src/cpu/kernels/CpuCastKernel.h b/src/cpu/kernels/CpuCastKernel.h
index 95d46fad23..de4ace2140 100644
--- a/src/cpu/kernels/CpuCastKernel.h
+++ b/src/cpu/kernels/CpuCastKernel.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022 Arm Limited.
+ * Copyright (c) 2016-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -62,6 +62,8 @@ public:
* @param[in] src The src tensor to convert. Data types supported: QASYMM8_SIGNED/QASYMM8/U8/U16/S16/BFLOAT16/F16/F32.
* @param[out] dst The dst tensor. Data types supported: QASYMM8_SIGNED/QASYMM8/U8/U16/S16/U32/S32/BFLOAT16/F16/F32.
* @param[in] policy Conversion policy.
+ *
+ * @deprecated Support for BFLOAT16 will be removed in 23.05 release
*/
void configure(const ITensorInfo *src, ITensorInfo *dst, ConvertPolicy policy);
/** Static function to check if given info will lead to a valid configuration
diff --git a/src/cpu/kernels/cast/generic/neon/bfloat16.cpp b/src/cpu/kernels/cast/generic/neon/bfloat16.cpp
index 942bdfae61..91c15be279 100644
--- a/src/cpu/kernels/cast/generic/neon/bfloat16.cpp
+++ b/src/cpu/kernels/cast/generic/neon/bfloat16.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022 Arm Limited.
+ * Copyright (c) 2016-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -24,8 +24,10 @@
#if defined(ARM_COMPUTE_ENABLE_BF16)
#include "arm_compute/core/TensorInfo.h"
+#include "src/core/NEON/wrapper/wrapper.h"
#include "src/cpu/kernels/CpuCastKernel.h"
#include "src/cpu/kernels/cast/list.h"
+#include "support/SaturateCast.h"
namespace arm_compute
{
@@ -36,9 +38,9 @@ void neon_fp32_to_bfloat16_cast(const ITensor *_src, ITensor *_dst, const Thread
ARM_COMPUTE_UNUSED(info);
ARM_COMPUTE_UNUSED(_policy);
- const auto window_start_x = static_cast<int>(window.x().start());
- const auto window_end_x = static_cast<int>(window.x().end());
- constexpr int window_step_x = 8;
+ const auto window_start_x = static_cast<int>(window.x().start());
+ const auto window_end_x = static_cast<int>(window.x().end());
+ const int window_step_x = 16;
ARM_COMPUTE_ERROR_ON_NULLPTR(_src, _dst);
ARM_COMPUTE_ERROR_ON(_src == _dst);
@@ -50,23 +52,25 @@ void neon_fp32_to_bfloat16_cast(const ITensor *_src, ITensor *_dst, const Thread
Iterator src(_src, win);
Iterator dst(_dst, win);
+
/* Down-conversion F32 -> BFLOAT16 */
execute_window_loop(win, [&](const Coordinates &)
{
- const auto src_ptr = reinterpret_cast<const float *>(src.ptr());
- const auto dst_ptr = reinterpret_cast<bfloat16_t *>(dst.ptr());
- int x = window_start_x;
- const int right_bound = (window_end_x - window_step_x);
- for(; x <= right_bound; x += window_step_x)
+ const auto src_ptr = reinterpret_cast<const float *>(src.ptr());
+ const auto dst_ptr = reinterpret_cast<bfloat16 *>(dst.ptr());
+
+ int x = window_start_x;
+ for(; x <= (window_end_x - window_step_x); x += window_step_x)
{
- const auto vbf16_0 = vcombine_bf16(
- vcvt_bf16_f32(vld1q_f32(src_ptr + x)),
- vcvt_bf16_f32(vld1q_f32(src_ptr + x + 4)));
- vst1q_bf16(dst_ptr + x, vbf16_0);
+ wrapper::vcvt_bf16_f32(reinterpret_cast<float *>(src.ptr()),
+ reinterpret_cast<uint16_t *>(dst.ptr()));
+ wrapper::vcvt_bf16_f32(reinterpret_cast<float *>(src.ptr()) + 8,
+ reinterpret_cast<uint16_t *>(dst.ptr()) + 8);
}
+
for(; x < window_end_x; ++x)
{
- *(reinterpret_cast<bfloat16 *>(dst.ptr()) + x) = *(src_ptr + x);
+ *(dst_ptr + x) = *(src_ptr + x);
}
},
src, dst);
@@ -77,9 +81,9 @@ void neon_bfloat16_to_fp32_cast(const ITensor *_src, ITensor *_dst, const Thread
ARM_COMPUTE_UNUSED(info);
ARM_COMPUTE_UNUSED(_policy);
- const auto window_start_x = static_cast<int>(window.x().start());
- const auto window_end_x = static_cast<int>(window.x().end());
- constexpr int window_step_x = 8;
+ const auto window_start_x = static_cast<int>(window.x().start());
+ const auto window_end_x = static_cast<int>(window.x().end());
+ const int window_step_x = 16;
ARM_COMPUTE_ERROR_ON_NULLPTR(_src, _dst);
ARM_COMPUTE_ERROR_ON(_src == _dst);
@@ -91,26 +95,48 @@ void neon_bfloat16_to_fp32_cast(const ITensor *_src, ITensor *_dst, const Thread
Iterator src(_src, win);
Iterator dst(_dst, win);
- /* Up-conversion BFLOAT16 -> F32 */
- execute_window_loop(win, [&](const Coordinates &)
+ switch(_dst->info()->data_type())
{
- const auto src_ptr = reinterpret_cast<const bfloat16_t *>(src.ptr());
- const auto dst_ptr = reinterpret_cast<float *>(dst.ptr());
-
- int x = window_start_x;
- const int right_bound(window_end_x - window_step_x);
- for(; x <= right_bound; x += window_step_x)
+ case DataType::F32:
{
- const bfloat16x8_t vinput = vld1q_bf16(src_ptr + x);
- vst1q_f32(dst_ptr + x, vcvt_f32_bf16(vget_low_bf16(vinput)));
- vst1q_f32(dst_ptr + x + 4, vcvt_f32_bf16(vget_high_bf16(vinput)));
+ /* Up-conversion BFLOAT16 -> F32 */
+ execute_window_loop(win, [&](const Coordinates &)
+ {
+ const auto src_ptr = reinterpret_cast<const bfloat16 *>(src.ptr());
+ const auto dst_ptr = reinterpret_cast<float *>(dst.ptr());
+
+ int x = window_start_x;
+ for(; x <= (window_end_x - window_step_x); x += window_step_x)
+ {
+ const uint16x8x2_t texels =
+ {
+ {
+ vld1q_u16(reinterpret_cast<uint16_t *>(src.ptr())),
+ vld1q_u16(reinterpret_cast<uint16_t *>(src.ptr()) + 8)
+ }
+ };
+
+ vst1q_f32(reinterpret_cast<float *>(dst.ptr()),
+ vreinterpretq_f32_u32(vshlq_n_u32(vmovl_u16(vget_low_u16(texels.val[0])), 16)));
+ vst1q_f32(reinterpret_cast<float *>(dst.ptr()) + 4,
+ vreinterpretq_f32_u32(vshlq_n_u32(vmovl_u16(vget_high_u16(texels.val[0])), 16)));
+ vst1q_f32(reinterpret_cast<float *>(dst.ptr()) + 8,
+ vreinterpretq_f32_u32(vshlq_n_u32(vmovl_u16(vget_low_u16(texels.val[1])), 16)));
+ vst1q_f32(reinterpret_cast<float *>(dst.ptr()) + 12,
+ vreinterpretq_f32_u32(vshlq_n_u32(vmovl_u16(vget_high_u16(texels.val[1])), 16)));
+ }
+
+ for(; x < window_end_x; ++x)
+ {
+ *(dst_ptr + x) = float(*(src_ptr + x));
+ }
+ },
+ src, dst);
+ break;
}
- for(; x < window_end_x; ++x)
- {
- *(dst_ptr + x) = float(*(reinterpret_cast<const bfloat16 *>(src_ptr) + x));
- }
- },
- src, dst);
+ default:
+ ARM_COMPUTE_ERROR("dst data type unsupported");
+ }
}
} // namespace cpu
diff --git a/src/cpu/operators/CpuCast.h b/src/cpu/operators/CpuCast.h
index 5e5f3e0ca6..a8342581cb 100644
--- a/src/cpu/operators/CpuCast.h
+++ b/src/cpu/operators/CpuCast.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited.
+ * Copyright (c) 2021, 2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -56,6 +56,9 @@ public:
* @param[in] src The source tensor to convert. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
* @param[out] dst The destination tensor. Data types supported: U8/S8/U16/S16/U32/S32/F16/F32.
* @param[in] policy Conversion policy.
+ *
+ * @deprecated Support for BFLOAT16 will be removed in 23.05 release
+ *
*/
void configure(const ITensorInfo *src, ITensorInfo *dst, ConvertPolicy policy);
/** Static function to check if given info will lead to a valid configuration
diff --git a/tests/validation/NEON/DepthConvertLayer.cpp b/tests/validation/NEON/DepthConvertLayer.cpp
index 378652c24f..4972708144 100644
--- a/tests/validation/NEON/DepthConvertLayer.cpp
+++ b/tests/validation/NEON/DepthConvertLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2022 Arm Limited.
+ * Copyright (c) 2017-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -56,14 +56,12 @@ const auto DepthConvertLayerU16toU8Dataset = combine(framework::dataset::ma
const auto DepthConvertLayerU16toU32Dataset = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U32));
const auto DepthConvertLayerS16toU8Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::U8));
const auto DepthConvertLayerS16toS32Dataset = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::S32));
-const auto DepthConvertLayerBF16toF32Dataset = combine(framework::dataset::make("DataType", DataType::BFLOAT16), framework::dataset::make("DataType", DataType::F32));
const auto DepthConvertLayerF16toU8Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::U8));
const auto DepthConvertLayerF16toF32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F32));
const auto DepthConvertLayerF16toS32Dataset = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::S32));
const auto DepthConvertLayerF32toF16Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F16));
const auto DepthConvertLayerF32toS32Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::S32));
const auto DepthConvertLayerF32toU8Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::U8));
-const auto DepthConvertLayerF32toBF16Dataset = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::BFLOAT16));
const auto DepthConvertLayerS32toF32Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::F32));
const auto DepthConvertLayerS32toQASYMM8Dataset = combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::QASYMM8));
@@ -127,8 +125,6 @@ using NEDepthConvertLayerToU8Fixture = DepthConvertLayerValidationFixture<Tensor
template <typename T>
using NEDepthConvertLayerToU32Fixture = DepthConvertLayerValidationFixture<Tensor, Accessor, NEDepthConvertLayer, T, uint32_t>;
template <typename T>
-using NEDepthConvertLayerToBF16Fixture = DepthConvertLayerValidationFixture<Tensor, Accessor, NEDepthConvertLayer, T, bfloat16>;
-template <typename T>
using NEDepthConvertLayerToF16Fixture = DepthConvertLayerValidationFixture<Tensor, Accessor, NEDepthConvertLayer, T, half>;
template <typename T>
using NEDepthConvertLayerToF32Fixture = DepthConvertLayerValidationFixture<Tensor, Accessor, NEDepthConvertLayer, T, float>;
@@ -342,28 +338,6 @@ FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthConvertLayerToS32Fixture<int16_t>, frame
}
TEST_SUITE_END() // S16_to_S32
-#if defined(ARM_COMPUTE_ENABLE_BF16)
-TEST_SUITE(BFLOAT16_to_F32)
-FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConvertLayerToF32Fixture<bfloat16>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerBF16toF32Dataset),
- framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
- DepthConvertLayerZeroShiftDataset))
-{
- // Validate output
- validate(Accessor(_target), _reference);
-}
-TEST_SUITE_END() // BFLOAT16_to_F32
-
-TEST_SUITE(F32_to_BFLOAT16)
-FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConvertLayerToBF16Fixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerF32toBF16Dataset),
- framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
- DepthConvertLayerZeroShiftDataset))
-{
- // Validate output
- validate(Accessor(_target), _reference);
-}
-TEST_SUITE_END() // F32_to_BFLOAT16
-#endif /* defined(ARM_COMPUTE_ENABLE_BF16) */
-
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
TEST_SUITE(F16_to_QASYMM8)
FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthConvertLayerToQASYMM8Fixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h
index a31a0e559b..8f9c24955e 100644
--- a/utils/TypePrinter.h
+++ b/utils/TypePrinter.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2022 Arm Limited.
+ * Copyright (c) 2017-2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -482,7 +482,7 @@ inline ::std::ostream &operator<<(::std::ostream &os, const BoundingBoxTransform
inline ::std::ostream &operator<<(::std::ostream &os, const bfloat16 &v)
{
std::stringstream str;
- str << static_cast<float>(v);
+ str << v;
os << str.str();
return os;
}