From bf28a3cde6f77cbac3e3409d5597085ccbc71499 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Tue, 18 Sep 2018 14:34:48 +0100 Subject: COMPMID-1564: Add QASYMM8 on CLPixelwiseMultiplication Change-Id: I5f719f5b2915c18cd0ca6271db401152112863a6 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/148982 Tested-by: bsgcomp Reviewed-by: Isabella Gottardi Reviewed-by: Anthony Barbier Reviewed-by: Giuseppe Rossini --- src/core/CL/CLKernelLibrary.cpp | 1 + src/core/CL/cl_kernels/pixelwise_mul_float.cl | 4 +- src/core/CL/cl_kernels/pixelwise_mul_int.cl | 68 ++++++++++++++++++++++ .../CL/kernels/CLPixelWiseMultiplicationKernel.cpp | 45 +++++++++----- tests/validation/CL/PixelWiseMultiplication.cpp | 41 ++++++++----- .../fixtures/PixelWiseMultiplicationFixture.h | 58 +++++++++++++----- .../reference/PixelWiseMultiplication.cpp | 40 +++++++++++-- .../validation/reference/PixelWiseMultiplication.h | 5 +- 8 files changed, 211 insertions(+), 51 deletions(-) diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp index a7a95b8b94..391a0bb6d5 100644 --- a/src/core/CL/CLKernelLibrary.cpp +++ b/src/core/CL/CLKernelLibrary.cpp @@ -332,6 +332,7 @@ const std::map CLKernelLibrary::_kernel_program_map = { "permute_3201", "permute.cl" }, { "pixelwise_mul_float", "pixelwise_mul_float.cl" }, { "pixelwise_mul_int", "pixelwise_mul_int.cl" }, + { "pixelwise_mul_quantized", "pixelwise_mul_int.cl" }, { "pooling_layer_2", "pooling_layer.cl" }, { "pooling_layer_3", "pooling_layer.cl" }, { "pooling_layer_optimized_3", "pooling_layer.cl" }, diff --git a/src/core/CL/cl_kernels/pixelwise_mul_float.cl b/src/core/CL/cl_kernels/pixelwise_mul_float.cl index f4f36a02af..9fa540e946 100644 --- a/src/core/CL/cl_kernels/pixelwise_mul_float.cl +++ b/src/core/CL/cl_kernels/pixelwise_mul_float.cl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 ARM Limited. + * Copyright (c) 2016-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,6 +30,7 @@ #endif /* SATURATE */ #define CONVERT_OP_FLOAT(x, type, round) CONVERT_OP_FLOAT_STR(x, type, round) +#if defined(DATA_TYPE_IN1) && defined(DATA_TYPE_IN2) && defined(DATA_TYPE_RES) && defined(DATA_TYPE_OUT) /** Performs a pixelwise multiplication with float scale of either integer or float inputs. * * @attention The inputs and output data types need to be passed at compile time using -DDATA_TYPE_IN1, -DDATA_TYPE_IN2 and -DDATA_TYPE_OUT: @@ -93,3 +94,4 @@ __kernel void pixelwise_mul_float( // Store result vstore16(res, 0, (__global DATA_TYPE_OUT *)out.ptr); } +#endif /* defined(DATA_TYPE_IN1) && defined(DATA_TYPE_IN2) && defined(DATA_TYPE_RES) && defined(DATA_TYPE_OUT) */ \ No newline at end of file diff --git a/src/core/CL/cl_kernels/pixelwise_mul_int.cl b/src/core/CL/cl_kernels/pixelwise_mul_int.cl index c99a08a583..5b3acb7ae6 100644 --- a/src/core/CL/cl_kernels/pixelwise_mul_int.cl +++ b/src/core/CL/cl_kernels/pixelwise_mul_int.cl @@ -32,6 +32,7 @@ #define MUL_OP(x, y, scale, type, size) CONVERT_OP_INT((x) * (y) >> scale, type, size) +#if defined(DATA_TYPE_IN1) && defined(DATA_TYPE_IN2) && defined(DATA_TYPE_RES) && defined(DATA_TYPE_OUT) /** Performs a pixelwise multiplication with integer scale of integer inputs. * * @attention The inputs and output data types need to be passed at compile time using -DDATA_TYPE_IN1, -DDATA_TYPE_IN2 and -DDATA_TYPE_OUT: @@ -85,3 +86,70 @@ __kernel void pixelwise_mul_int( // Perform multiplication and store result vstore16(MUL_OP(in1_data, in2_data, scale, DATA_TYPE_OUT, 16), 0, (__global DATA_TYPE_OUT *)out.ptr); } +#endif /* defined(DATA_TYPE_IN1) && defined(DATA_TYPE_IN2) && defined(DATA_TYPE_RES) && defined(DATA_TYPE_OUT) */ + +#if defined(OFFSET_IN1) && defined(OFFSET_IN2) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_IN2) && defined(SCALE_OUT) +/** Performs a pixelwise multiplication with float scale of quantized inputs. + * + * @note The quantization offset of the first operand must be passed at compile time using -DOFFSET_IN1, e.g. -DOFFSET_IN1=10 + * @note The quantization offset of the second operand must be passed at compile time using -DOFFSET_IN2, e.g. -DOFFSET_IN2=10 + * @note The quantization offset of the output must be passed at compile time using -DOFFSET_OUT, e.g. -DOFFSET_OUT=10 + * @note The quantization scale of the first operand must be passed at compile time using -DSCALE_IN1, e.g. -DSCALE_IN1=10 + * @note The quantization scale of the second operand must be passed at compile time using -DSCALE_IN2, e.g. -DSCALE_IN2=10 + * @note The quantization scale of the output must be passed at compile time using -DSCALE_OUT, e.g. -DSCALE_OUT=10 + * @note To perform saturating operation -DSATURATE has to be passed to the compiler otherwise wrapping policy will be used. + * + * @param[in] in1_ptr Pointer to the source image. Supported data types: U8, S16, F16, F32 + * @param[in] in1_stride_x Stride of the source image in X dimension (in bytes) + * @param[in] in1_step_x in1_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] in1_stride_y Stride of the source image in Y dimension (in bytes) + * @param[in] in1_step_y in1_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] in1_stride_z Stride of the source image in Y dimension (in bytes) + * @param[in] in1_step_z in1_stride_z * number of elements along Y processed per workitem(in bytes) + * @param[in] in1_offset_first_element_in_bytes The offset of the first element in the source image + * @param[in] in2_ptr Pointer to the source image. Supported data types: U8, S16, F16, F32 + * @param[in] in2_stride_x Stride of the source image in X dimension (in bytes) + * @param[in] in2_step_x in2_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] in2_stride_y Stride of the source image in Y dimension (in bytes) + * @param[in] in2_step_y in2_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] in2_stride_z Stride of the source image in Y dimension (in bytes) + * @param[in] in2_step_z in2_stride_z * number of elements along Y processed per workitem(in bytes) + * @param[in] in2_offset_first_element_in_bytes The offset of the first element in the source image + * @param[out] out_ptr Pointer to the destination image. Supported data types: U8, S16, F16, F32 + * @param[in] out_stride_x Stride of the destination image in X dimension (in bytes) + * @param[in] out_step_x out_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] out_stride_y Stride of the destination image in Y dimension (in bytes) + * @param[in] out_step_y out_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] out_stride_z Stride of the destination image in Y dimension (in bytes) + * @param[in] out_step_z out_stride_z * number of elements along Y processed per workitem(in bytes) + * @param[in] out_offset_first_element_in_bytes The offset of the first element in the destination image + * @param[in] scale Float scaling factor. Supported data types: F32 + */ +__kernel void pixelwise_mul_quantized( + TENSOR3D_DECLARATION(in1), + TENSOR3D_DECLARATION(in2), + TENSOR3D_DECLARATION(out), + const float scale) +{ + // Get pixels pointer + Tensor3D in1 = CONVERT_TO_TENSOR3D_STRUCT(in1); + Tensor3D in2 = CONVERT_TO_TENSOR3D_STRUCT(in2); + Tensor3D out = CONVERT_TO_TENSOR3D_STRUCT(out); + + // Load data + int16 in_a = CONVERT(vload16(0, (__global uchar *)in1.ptr), int16); + int16 in_b = CONVERT(vload16(0, (__global uchar *)in2.ptr), int16); + + // Dequantize + in_a -= (int16)(int)OFFSET_IN1; + in_b -= (int16)(int)OFFSET_IN2; + const float16 in1f32 = convert_float16(in_a) * (float16)(float)SCALE_IN1; + const float16 in2f32 = convert_float16(in_b) * (float16)(float)SCALE_IN2; + + const float16 qresf32 = (in1f32 * in2f32 * scale) / ((float16)(float)SCALE_OUT) + ((float16)((float16)OFFSET_OUT)); + const uchar16 res = convert_uchar16_sat(convert_int16_rte(qresf32)); + + // Store result + vstore16(res, 0, (__global uchar *)out.ptr); +} +#endif /* defined(OFFSET_IN1) && defined(OFFSET_IN2) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_IN2) && defined(SCALE_OUT) */ \ No newline at end of file diff --git a/src/core/CL/kernels/CLPixelWiseMultiplicationKernel.cpp b/src/core/CL/kernels/CLPixelWiseMultiplicationKernel.cpp index 4ca2ef8aa3..286b94ebdc 100644 --- a/src/core/CL/kernels/CLPixelWiseMultiplicationKernel.cpp +++ b/src/core/CL/kernels/CLPixelWiseMultiplicationKernel.cpp @@ -51,9 +51,9 @@ Status validate_arguments(const ITensorInfo *input1, const ITensorInfo *input2, ARM_COMPUTE_UNUSED(rounding_policy); ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input1); - ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8, DataType::S16, DataType::F16, DataType::F32); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input1, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input2); - ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input2, 1, DataType::U8, DataType::S16, DataType::F16, DataType::F32); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input2, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); ARM_COMPUTE_RETURN_ERROR_ON_MSG(scale < 0, "Scale cannot be negative."); const TensorShape &out_shape = TensorShape::broadcast_shape(input1->tensor_shape(), input2->tensor_shape()); @@ -64,7 +64,7 @@ Status validate_arguments(const ITensorInfo *input1, const ITensorInfo *input2, if(output->total_size() > 0) { ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(output); - ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::S16, DataType::F16, DataType::F32); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); ARM_COMPUTE_RETURN_ERROR_ON_MSG(output->data_type() == DataType::U8 && (input1->data_type() != DataType::U8 || input2->data_type() != DataType::U8), "Output can only be U8 if both inputs are U8"); ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output->tensor_shape(), 0), "Wrong shape for output"); @@ -168,27 +168,44 @@ void CLPixelWiseMultiplicationKernel::configure(const ICLTensor *input1, const I data_type = "DATA_TYPE_INT"; } + const bool is_quantized = is_data_type_quantized_asymmetric(input1->info()->data_type()); + // Construct kernel name std::string kernel_name = "pixelwise_mul"; - kernel_name += (scale_int >= 0) ? "_int" : "_float"; + if(!is_data_type_quantized(output->info()->data_type())) + { + kernel_name += (scale_int >= 0) ? "_int" : "_float"; + } // Set kernel build options - std::set build_opts; - build_opts.emplace((overflow_policy == ConvertPolicy::WRAP || is_data_type_float(output->info()->data_type())) ? "-DWRAP" : "-DSATURATE"); - build_opts.emplace((rounding_policy == RoundingPolicy::TO_ZERO) ? "-DROUND=_rtz" : "-DROUND=_rte"); - build_opts.emplace("-DDATA_TYPE_IN1=" + get_cl_type_from_data_type(input1->info()->data_type())); - build_opts.emplace("-DDATA_TYPE_IN2=" + get_cl_type_from_data_type(input2->info()->data_type())); - build_opts.emplace("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(output->info()->data_type())); - build_opts.emplace("-DDATA_TYPE_RES=" + compute_type); - build_opts.emplace("-D" + data_type); + CLBuildOptions build_opts; + if(is_quantized) + { + build_opts.add_option("-DOFFSET_IN1=" + support::cpp11::to_string(input1->info()->quantization_info().offset)); + build_opts.add_option("-DOFFSET_IN2=" + support::cpp11::to_string(input2->info()->quantization_info().offset)); + build_opts.add_option("-DOFFSET_OUT=" + support::cpp11::to_string(output->info()->quantization_info().offset)); + build_opts.add_option("-DSCALE_IN1=" + support::cpp11::to_string(input1->info()->quantization_info().scale)); + build_opts.add_option("-DSCALE_IN2=" + support::cpp11::to_string(input2->info()->quantization_info().scale)); + build_opts.add_option("-DSCALE_OUT=" + support::cpp11::to_string(output->info()->quantization_info().scale)); + kernel_name += "_quantized"; + } + else + { + build_opts.add_option_if_else(overflow_policy == ConvertPolicy::WRAP || is_data_type_float(output->info()->data_type()), "-DWRAP", "-DSATURATE"); + build_opts.add_option_if_else(rounding_policy == RoundingPolicy::TO_ZERO, "-DROUND=_rtz", "-DROUND=_rte"); + build_opts.add_option("-DDATA_TYPE_IN1=" + get_cl_type_from_data_type(input1->info()->data_type())); + build_opts.add_option("-DDATA_TYPE_IN2=" + get_cl_type_from_data_type(input2->info()->data_type())); + build_opts.add_option("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(output->info()->data_type())); + build_opts.add_option("-DDATA_TYPE_RES=" + compute_type); + } // Create kernel - _kernel = static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts)); + _kernel = static_cast(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options())); // Set scale argument unsigned int idx = 3 * num_arguments_per_3D_tensor(); //Skip the inputs and output parameters - if(scale_int >= 0) + if(scale_int >= 0 && !is_quantized) { _kernel.setArg(idx++, scale_int); } diff --git a/tests/validation/CL/PixelWiseMultiplication.cpp b/tests/validation/CL/PixelWiseMultiplication.cpp index 8aa19dc105..b61ec394ea 100644 --- a/tests/validation/CL/PixelWiseMultiplication.cpp +++ b/tests/validation/CL/PixelWiseMultiplication.cpp @@ -38,8 +38,11 @@ namespace validation { namespace { -const float scale_255 = 1.f / 255.f; - +namespace +{ +const float scale_255 = 1.f / 255.f; +constexpr AbsoluteTolerance tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */ +} //namespace // *INDENT-OFF* // clang-format off #define VALIDATE(TYPE, TOLERANCE) validate(CLAccessor(_target), _reference, AbsoluteTolerance(TOLERANCE), 0.f); @@ -105,31 +108,41 @@ DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( // *INDENT-ON* TEST_SUITE(F16toF16) - TEST_SUITE(Scale255) PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF16Fixture, PRECOMMIT, SmallShapes(), F16, F16, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) TEST_SUITE_END() // Scale255 - TEST_SUITE_END() // F16toF16 TEST_SUITE(F32toF32) - TEST_SUITE(Scale255) PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, ToF32Fixture, PRECOMMIT, SmallShapes(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) TEST_SUITE_END() // Scale255 - TEST_SUITE_END() // F32toF32 -TEST_SUITE_END() // PixelWiseMultiplication - -TEST_SUITE(FixedPointPixelWiseMultiplication) +PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, BroadcastFixture, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) -TEST_SUITE(Broadcast) -PIXEL_WISE_MULTIPLICATION_FIXTURE_DATA_TEST_CASE(RunSmall, BroadcastFixture, PRECOMMIT, SmallShapesBroadcast(), F32, F32, scale_255, TO_NEAREST_UP, VALIDATE(float, 1.f)) -TEST_SUITE_END() // Broadcast +template +using CLPixelWiseMultiplicationQuantizedFixture = PixelWiseMultiplicationValidationQuantizedFixture; + +TEST_SUITE(Quantized) +TEST_SUITE(QASYMM8) +FIXTURE_DATA_TEST_CASE(RunSmall, CLPixelWiseMultiplicationQuantizedFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(combine(combine(datasets::SmallShapes(), + framework::dataset::make("DataType", DataType::QASYMM8)), + framework::dataset::make("Scale", { 1.f, 2.f })), + framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })), + framework::dataset::make("RoundingPolicy", RoundingPolicy::TO_NEAREST_EVEN)), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })), + framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_qasymm8); +} +TEST_SUITE_END() // QASYMM8 +TEST_SUITE_END() // Quantized -TEST_SUITE_END() // FixedPointPixelWiseMultiplication -TEST_SUITE_END() +TEST_SUITE_END() // PixelWiseMultiplication +TEST_SUITE_END() // CL } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/fixtures/PixelWiseMultiplicationFixture.h b/tests/validation/fixtures/PixelWiseMultiplicationFixture.h index b9f19f3e77..9927b75032 100644 --- a/tests/validation/fixtures/PixelWiseMultiplicationFixture.h +++ b/tests/validation/fixtures/PixelWiseMultiplicationFixture.h @@ -40,7 +40,7 @@ namespace test namespace validation { template -class PixelWiseMultiplicationBroadcastValidationFixture : public framework::Fixture +class PixelWiseMultiplicationGenericValidationFixture : public framework::Fixture { public: template @@ -50,10 +50,13 @@ public: DataType dt_in2, float scale, ConvertPolicy convert_policy, - RoundingPolicy rounding_policy) + RoundingPolicy rounding_policy, + QuantizationInfo qinfo0, + QuantizationInfo qinfo1, + QuantizationInfo qinfo_out) { - _target = compute_target(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy); - _reference = compute_reference(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy); + _target = compute_target(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy, qinfo0, qinfo1, qinfo_out); + _reference = compute_reference(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy, qinfo0, qinfo1, qinfo_out); } protected: @@ -64,12 +67,13 @@ protected: } TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2, - float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) + float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) { // Create tensors - TensorType src1 = create_tensor(shape0, dt_in1); - TensorType src2 = create_tensor(shape1, dt_in2); - TensorType dst = create_tensor(TensorShape::broadcast_shape(shape0, shape1), dt_in2); + TensorType src1 = create_tensor(shape0, dt_in1, 1, qinfo0); + TensorType src2 = create_tensor(shape1, dt_in2, 1, qinfo1); + TensorType dst = create_tensor(TensorShape::broadcast_shape(shape0, shape1), dt_in2, 1, qinfo_out); // Create and configure function FunctionType multiply; @@ -99,17 +103,18 @@ protected: } SimpleTensor compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2, - float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) + float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) { // Create reference - SimpleTensor src1{ shape0, dt_in1 }; - SimpleTensor src2{ shape1, dt_in2 }; + SimpleTensor src1{ shape0, dt_in1, 1, qinfo0 }; + SimpleTensor src2{ shape1, dt_in2, 1, qinfo1 }; // Fill reference fill(src1, 0); fill(src2, 1); - return reference::pixel_wise_multiplication(src1, src2, scale, convert_policy, rounding_policy); + return reference::pixel_wise_multiplication(src1, src2, scale, convert_policy, rounding_policy, qinfo_out); } TensorType _target{}; @@ -117,16 +122,41 @@ protected: }; template -class PixelWiseMultiplicationValidationFixture : public PixelWiseMultiplicationBroadcastValidationFixture +class PixelWiseMultiplicationValidationFixture : public PixelWiseMultiplicationGenericValidationFixture { public: template void setup(const TensorShape &shape, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) { - PixelWiseMultiplicationBroadcastValidationFixture::setup(shape, shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy); + PixelWiseMultiplicationGenericValidationFixture::setup(shape, shape, dt_in1, dt_in2, scale, convert_policy, rounding_policy, + QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); } }; +template +class PixelWiseMultiplicationBroadcastValidationFixture : public PixelWiseMultiplicationGenericValidationFixture +{ +public: + template + void setup(const TensorShape &shape0, const TensorShape &shape1, DataType dt_in1, DataType dt_in2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) + { + PixelWiseMultiplicationGenericValidationFixture::setup(shape0, shape1, dt_in1, dt_in2, scale, convert_policy, rounding_policy, + QuantizationInfo(), QuantizationInfo(), QuantizationInfo()); + } +}; + +template +class PixelWiseMultiplicationValidationQuantizedFixture : public PixelWiseMultiplicationGenericValidationFixture +{ +public: + template + void setup(const TensorShape &shape, DataType dt, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, + QuantizationInfo qinfo0, QuantizationInfo qinfo1, QuantizationInfo qinfo_out) + { + PixelWiseMultiplicationGenericValidationFixture::setup(shape, shape, dt, dt, scale, convert_policy, rounding_policy, + qinfo0, qinfo1, qinfo_out); + } +}; } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation/reference/PixelWiseMultiplication.cpp b/tests/validation/reference/PixelWiseMultiplication.cpp index 859da5ce59..d86f8aae0d 100644 --- a/tests/validation/reference/PixelWiseMultiplication.cpp +++ b/tests/validation/reference/PixelWiseMultiplication.cpp @@ -23,6 +23,8 @@ */ #include "PixelWiseMultiplication.h" +#include "tests/validation/Helpers.h" + namespace arm_compute { namespace test @@ -126,8 +128,10 @@ struct BroadcastUnroll<0> } // namespace template -SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, QuantizationInfo qout) { + ARM_COMPUTE_UNUSED(qout); + SimpleTensor dst(TensorShape::broadcast_shape(src1.shape(), src2.shape()), src2.data_type()); if(scale < 0) @@ -142,13 +146,37 @@ SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const S return dst; } +template <> +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, + QuantizationInfo qout) +{ + SimpleTensor dst(TensorShape::broadcast_shape(src1.shape(), src2.shape()), src2.data_type(), 1, qout); + + if(src1.data_type() == DataType::QASYMM8 && src2.data_type() == DataType::QASYMM8) + { + SimpleTensor src1_tmp = convert_from_asymmetric(src1); + SimpleTensor src2_tmp = convert_from_asymmetric(src2); + SimpleTensor dst_tmp = pixel_wise_multiplication(src1_tmp, src2_tmp, scale, convert_policy, rounding_policy, qout); + dst = convert_to_asymmetric(dst_tmp, qout); + } + else + { + if(scale < 0) + { + ARM_COMPUTE_ERROR("Scale of pixel-wise multiplication must be non-negative"); + } + + Coordinates id_src1, id_src2, id_dst; + BroadcastUnroll::unroll(src1, src2, dst, scale, convert_policy, rounding_policy, id_src1, id_src2, id_dst); + } + return dst; +} // *INDENT-OFF* // clang-format off -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); -template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, QuantizationInfo qout); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, QuantizationInfo qout); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, QuantizationInfo qout); +template SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy, QuantizationInfo qout); // clang-format on // *INDENT-ON* } // namespace reference diff --git a/tests/validation/reference/PixelWiseMultiplication.h b/tests/validation/reference/PixelWiseMultiplication.h index 1dce154719..787a7b23e2 100644 --- a/tests/validation/reference/PixelWiseMultiplication.h +++ b/tests/validation/reference/PixelWiseMultiplication.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -35,7 +35,8 @@ namespace validation namespace reference { template -SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy); +SimpleTensor pixel_wise_multiplication(const SimpleTensor &src1, const SimpleTensor &src2, float scale, + ConvertPolicy convert_policy, RoundingPolicy rounding_policy, QuantizationInfo qout = QuantizationInfo()); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1