diff options
author | Abe Mbise <abe.mbise@arm.com> | 2017-09-27 18:39:19 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:35:24 +0000 |
commit | 4bd2cb8aec96de89eb9cf652b83298bf89486bca (patch) | |
tree | 33605a193813778611f8abe6f586297875257c3b /tests | |
parent | f6705ec6ed137233680929e941c674af6baae1dc (diff) | |
download | ComputeLibrary-4bd2cb8aec96de89eb9cf652b83298bf89486bca.tar.gz |
COMPMID-511: Port FixedPoint arithmetic to new validation
Change-Id: Iae85c195a4ecdaf6df1d0055f3ad09582d128dc1
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/88669
Reviewed-by: Pablo Tello <pablo.tello@arm.com>
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Diffstat (limited to 'tests')
19 files changed, 754 insertions, 1154 deletions
diff --git a/tests/validation_old/CL/FixedPoint/FixedPoint_QS8.cpp b/tests/validation/CL/FixedPoint/FixedPointTarget.h index 4f7764c49b..38473545d9 100644 --- a/tests/validation_old/CL/FixedPoint/FixedPoint_QS8.cpp +++ b/tests/validation/CL/FixedPoint/FixedPointTarget.h @@ -21,53 +21,29 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "CL/CLAccessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/Reference.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" +#ifndef ARM_COMPUTE_TEST_FIXED_POINT_CL_TARGET +#define ARM_COMPUTE_TEST_FIXED_POINT_CL_TARGET -#include "arm_compute/core/CL/CLKernelLibrary.h" -#include "arm_compute/core/CL/ICLKernel.h" -#include "arm_compute/core/CL/OpenCL.h" -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/core/Window.h" #include "arm_compute/runtime/CL/CLScheduler.h" -#include "arm_compute/runtime/CL/CLSubTensor.h" -#include "arm_compute/runtime/CL/CLTensor.h" -#include "arm_compute/runtime/CL/CLTensorAllocator.h" - -#include "arm_compute/core/CL/ICLTensor.h" - -#include "tests/validation_old/boost_wrapper.h" -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; +#include "tests/Globals.h" +#include "tests/Types.h" +namespace arm_compute +{ +namespace test +{ +namespace validation +{ namespace { -const float tolerance_exp = 1.0f; /**< Tolerance value for comparing reference's output against implementation's output (exponential)*/ -const float tolerance_invsqrt = 4.0f; /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) */ -const float tolerance_log = 5.0f; /**< Tolerance value for comparing reference's output against implementation's output (logarithm) */ - -/** Compute Neon fixed point operation for signed 8bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -CLTensor compute_fixed_point_op(const TensorShape &shape, int fixed_point_position, FixedPointOp op) +template <typename TensorType, typename AccessorType, typename T> +void compute_target_impl(const TensorShape &shape, DataType dt, FixedPointOp op, int fixed_point_position, TensorType &src, TensorType &dst) { std::string fixed_point_operation_kernel; #ifndef EMBEDDED_KERNELS + std::cout << "EMBEDDED_KERNELS NOT DEFINED" << std::endl; + fixed_point_operation_kernel += "#include \"fixed_point.h\"\n"; #endif /* EMBEDDED_KERNELS */ fixed_point_operation_kernel += @@ -91,17 +67,6 @@ CLTensor compute_fixed_point_op(const TensorShape &shape, int fixed_point_positi "} \n" "\n"; - // Create tensors - CLTensor src = create_tensor<CLTensor>(shape, DataType::QS8, 1, fixed_point_position); - CLTensor dst = create_tensor<CLTensor>(shape, DataType::QS8, 1, fixed_point_position); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - // Set build options std::string build_opts = "-DFIXED_POINT_POS=" + support::cpp11::to_string(fixed_point_position); build_opts += " -DDATA_TYPE=qs8"; @@ -111,27 +76,28 @@ CLTensor compute_fixed_point_op(const TensorShape &shape, int fixed_point_positi int max = 0; switch(op) { - case FixedPointOp::EXP: + case(FixedPointOp::EXP): min = -(1 << (fixed_point_position - 1)); max = (1 << (fixed_point_position - 1)); build_opts += " -DFIXED_POINT_OP=0"; break; - case FixedPointOp::INV_SQRT: + case(FixedPointOp::INV_SQRT): min = 1; - max = 0x7F; + max = (dt == DataType::QS8) ? 0x7F : 0x7FFF; build_opts += " -DFIXED_POINT_OP=1"; break; - case FixedPointOp::LOG: + case(FixedPointOp::LOG): min = (1 << (fixed_point_position - 1)); - max = 0x3F; + max = (dt == DataType::QS8) ? 0x3F : 0x3FFF; build_opts += " -DFIXED_POINT_OP=2"; break; default: - ARM_COMPUTE_ERROR("Operation not supported"); + ARM_COMPUTE_ERROR("Fixed point operation not supported"); + break; } std::uniform_int_distribution<> distribution(min, max); - library->fill(CLAccessor(src), distribution, 0); + library->fill(AccessorType(src), distribution, 0); std::vector<std::string> sources; @@ -157,68 +123,9 @@ CLTensor compute_fixed_point_op(const TensorShape &shape, int fixed_point_positi ::cl::NDRange gws(shape[0] / 16, 1, 1); CLScheduler::get().queue().enqueueNDRangeKernel(kernel, 0, gws); - - return dst; } } // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(CL) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS8) - -BOOST_AUTO_TEST_SUITE(Exp) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 6), shape, fixed_point_position) -{ - // Compute function - CLTensor dst = compute_fixed_point_op(shape, fixed_point_position, FixedPointOp::EXP); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::EXP, fixed_point_position); - - // Validate output - validate(CLAccessor(dst), ref_dst, tolerance_exp); -} - -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(Log) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(3, 6), shape, fixed_point_position) -{ - // Compute function - CLTensor dst = compute_fixed_point_op(shape, fixed_point_position, FixedPointOp::LOG); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::LOG, fixed_point_position); - - // Validate output - validate(CLAccessor(dst), ref_dst, tolerance_log); -} - -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(Invsqrt) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 6), shape, fixed_point_position) -{ - // Compute function - CLTensor dst = compute_fixed_point_op(shape, fixed_point_position, FixedPointOp::INV_SQRT); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::INV_SQRT, fixed_point_position); - - // Validate output - validate(CLAccessor(dst), ref_dst, tolerance_invsqrt); -} - -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_FIXED_POINT_TARGET */ diff --git a/tests/validation/CL/FixedPoint/FixedPoint_QS8.cpp b/tests/validation/CL/FixedPoint/FixedPoint_QS8.cpp new file mode 100644 index 0000000000..0fb464112a --- /dev/null +++ b/tests/validation/CL/FixedPoint/FixedPoint_QS8.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "FixedPointTarget.h" + +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "tests/CL/CLAccessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/FixedPointFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +constexpr AbsoluteTolerance<float> tolerance_exp(1.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential)*/ +constexpr AbsoluteTolerance<float> tolerance_invsqrt(4.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) */ +constexpr AbsoluteTolerance<float> tolerance_log(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) */ +} // namespace + +TEST_SUITE(CL) +TEST_SUITE(FixedPoint) +TEST_SUITE(QS8) + +template <typename T> +using CLFixedPointFixture = FixedPointValidationFixture<CLTensor, CLAccessor, T>; + +TEST_SUITE(Exp) +FIXTURE_DATA_TEST_CASE(RunSmall, CLFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::EXP)), + framework::dataset::make("FractionalBits", 1, 6))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_exp); +} +TEST_SUITE_END() + +TEST_SUITE(Log) +FIXTURE_DATA_TEST_CASE(RunSmall, CLFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::LOG)), + framework::dataset::make("FractionalBits", 3, 6))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_log); +} +TEST_SUITE_END() + +TEST_SUITE(Invsqrt) +FIXTURE_DATA_TEST_CASE(RunSmall, CLFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::INV_SQRT)), + framework::dataset::make("FractionalBits", 1, 6))) +{ + // Validate output + validate(CLAccessor(_target), _reference, tolerance_invsqrt); +} +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/FixedPoint.cpp b/tests/validation/CPP/FixedPoint.cpp new file mode 100644 index 0000000000..a016093ed6 --- /dev/null +++ b/tests/validation/CPP/FixedPoint.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "FixedPoint.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> fixed_point_operation(const SimpleTensor<T> &src, FixedPointOp op) +{ + SimpleTensor<T> result(src.shape(), src.data_type()); + + const int p = src.fixed_point_position(); + switch(op) + { + case FixedPointOp::EXP: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::exp(fixed_point_arithmetic::fixed_point<T>(src[i], p, true)).raw(); + } + break; + case FixedPointOp::LOG: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::log(fixed_point_arithmetic::fixed_point<T>(src[i], p, true)).raw(); + } + break; + case FixedPointOp::INV_SQRT: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::inv_sqrt(fixed_point_arithmetic::fixed_point<T>(src[i], p, true)).raw(); + } + break; + case FixedPointOp::RECIPROCAL: + for(int i = 0; i < src.num_elements(); ++i) + { + result[i] = fixed_point_arithmetic::div(fixed_point_arithmetic::fixed_point<T>(1, p), fixed_point_arithmetic::fixed_point<T>(src[i], p, true)).raw(); + } + break; + default: + ARM_COMPUTE_ERROR("Fixed point operation not supported"); + break; + } + + return result; +} + +template SimpleTensor<int8_t> fixed_point_operation(const SimpleTensor<int8_t> &src, FixedPointOp op); +template SimpleTensor<int16_t> fixed_point_operation(const SimpleTensor<int16_t> &src, FixedPointOp op); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/FixedPoint.h b/tests/validation/CPP/FixedPoint.h new file mode 100644 index 0000000000..f0117f9dd0 --- /dev/null +++ b/tests/validation/CPP/FixedPoint.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ +#define __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ + +#include "tests/SimpleTensor.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template <typename T> +SimpleTensor<T> fixed_point_operation(const SimpleTensor<T> &src, FixedPointOp op); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_FIXED_POINT_OPERATION_H__ */ diff --git a/tests/validation/NEON/FixedPoint/FixedPoint.cpp b/tests/validation/NEON/FixedPoint/FixedPoint.cpp new file mode 100644 index 0000000000..3b25b0524b --- /dev/null +++ b/tests/validation/NEON/FixedPoint/FixedPoint.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "FixedPointTarget.h" + +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" +#include "tests/NEON/Accessor.h" +#include "tests/PaddingCalculator.h" +#include "tests/datasets/ShapeDatasets.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" +#include "tests/validation/fixtures/FixedPointFixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +constexpr AbsoluteTolerance<float> tolerance_exp_qs8(0.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential) for DataType::QS8 */ +constexpr AbsoluteTolerance<float> tolerance_exp_qs16(1.0f); /**< Tolerance value for comparing reference's output against implementation's output (exponential) for DataType::QS16 */ +constexpr AbsoluteTolerance<float> tolerance_invsqrt_qs8(4.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) for DataType::QS8 */ +constexpr AbsoluteTolerance<float> tolerance_invsqrt_qs16(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (inverse square-root) for DataType::QS16 */ +constexpr AbsoluteTolerance<float> tolerance_log_qs8(5.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) for DataType::QS8 */ +constexpr AbsoluteTolerance<float> tolerance_log_qs16(7.0f); /**< Tolerance value for comparing reference's output against implementation's output (logarithm) for DataType::QS16 */ +constexpr AbsoluteTolerance<float> tolerance_reciprocal_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output (reciprocal) for DataType::QS8 */ +constexpr AbsoluteTolerance<float> tolerance_reciprocal_qs16(11.0f); /**< Tolerance value for comparing reference's output against implementation's output (reciprocal) for DataType::QS16 */ +} // namespace + +TEST_SUITE(NEON) +TEST_SUITE(FixedPoint) +template <typename T> +using NEFixedPointFixture = FixedPointValidationFixture<Tensor, Accessor, T>; + +TEST_SUITE(QS8) +TEST_SUITE(Exp) + +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::EXP)), + framework::dataset::make("FractionalBits", 1, 7))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_exp_qs8, 0); +} +TEST_SUITE_END() + +TEST_SUITE(Invsqrt) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::INV_SQRT)), + framework::dataset::make("FractionalBits", 1, 6))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_invsqrt_qs8, 0); +} +TEST_SUITE_END() + +TEST_SUITE(Log) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::LOG)), + framework::dataset::make("FractionalBits", 3, 6))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_log_qs8, 0); +} +TEST_SUITE_END() + +TEST_SUITE(Reciprocal) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS8)), + framework::dataset::make("FixedPointOp", FixedPointOp::RECIPROCAL)), + framework::dataset::make("FractionalBits", 1, 6))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_reciprocal_qs8, 0); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE(QS16) +TEST_SUITE(Exp) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS16)), + framework::dataset::make("FixedPointOp", FixedPointOp::EXP)), + framework::dataset::make("FractionalBits", 1, 15))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_exp_qs16, 0); +} +TEST_SUITE_END() + +TEST_SUITE(Invsqrt) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::make("Shape", TensorShape(8192U)), + framework::dataset::make("DataType", + DataType::QS16)), + framework::dataset::make("FixedPointOp", FixedPointOp::INV_SQRT)), + framework::dataset::make("FractionalBits", 1, 14))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_invsqrt_qs16, 0); +} +TEST_SUITE_END() + +TEST_SUITE(Log) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS16)), + framework::dataset::make("FixedPointOp", FixedPointOp::LOG)), + framework::dataset::make("FractionalBits", 4, 14))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_log_qs16, 0); +} +TEST_SUITE_END() + +TEST_SUITE(Reciprocal) +FIXTURE_DATA_TEST_CASE(RunSmall, NEFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::Small1DShape(), framework::dataset::make("DataType", + DataType::QS16)), + framework::dataset::make("FixedPointOp", FixedPointOp::RECIPROCAL)), + framework::dataset::make("FractionalBits", 1, 14))) +{ + // Validate output + validate(Accessor(_target), _reference, tolerance_reciprocal_qs16, 0); +} +TEST_SUITE_END() +TEST_SUITE_END() + +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/NEON/FixedPoint/FixedPointTarget.h b/tests/validation/NEON/FixedPoint/FixedPointTarget.h new file mode 100644 index 0000000000..fa1d97f152 --- /dev/null +++ b/tests/validation/NEON/FixedPoint/FixedPointTarget.h @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_FIXED_POINT_NEON_TARGET +#define ARM_COMPUTE_TEST_FIXED_POINT_NEON_TARGET + +#include "arm_compute/core/NEON/NEFixedPoint.h" + +#include "tests/Globals.h" +#include "tests/Types.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace +{ +template <typename TensorType, typename AccessorType, typename T> +void compute_target_impl(const TensorShape &shape, DataType dt, FixedPointOp op, int fixed_point_position, TensorType &src, TensorType &dst) +{ + Window window; + + switch(dt) + { + case DataType::QS8: + { + constexpr unsigned int num_elems_processed_per_iteration = 16; + window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); + AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); + AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); + break; + } + case DataType::QS16: + { + constexpr unsigned int num_elems_processed_per_iteration = 8; + window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); + AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); + AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); + break; + } + default: + ARM_COMPUTE_ERROR("Not Supported"); + break; + } + + int min; + int max; + switch(op) + { + case FixedPointOp::EXP: + { + // Fill tensors. Keep the range between [-1.0, 1.0) so the result won't + // overflow. + min = -(1 << (fixed_point_position - 1)); + max = (1 << (fixed_point_position - 1)); + break; + } + case FixedPointOp::INV_SQRT: + { + if(dt == DataType::QS8) + { + // Fill tensors. Keep the range between [1, 127). + min = 1; + max = 127; + } + else + { + // Fill tensors. Keep the range between [1, 0x7FFF) + min = 1; + max = 0x7FFF; + } + break; + } + case FixedPointOp::LOG: + { + if(dt == DataType::QS8) + { + // Fill tensors. Keep the range between [(1 << (fixed_point_position - 1), 63) so the result won't + // overflow. E.g. for Q2.5 ln(0.001) = -6.9, which cannot be represented. + min = (1 << (fixed_point_position - 1)); + max = 0x3F; + } + else + { + // Fill tensors. Keep the range between [(1 << (fixed_point_position - 1), 0x3FFF) so the result won't + // overflow. + min = (1 << (fixed_point_position - 1)); + max = 0x3FFF; + } + break; + } + case FixedPointOp::RECIPROCAL: + { + if(dt == DataType::QS8) + { + // Fill tensors. Keep the range between [15, 100) so the result won't + // overflow. E.g. for Q2.5 reciprocal(0.001) = 1000, which cannot be represented. + min = 15; + max = 0x7F; + } + else + { + // Fill tensors. Keep the range between [15, 0x7FFF) so the result won't + // overflow. + min = 15; + max = 0x7FFF; + } + break; + } + default: + ARM_COMPUTE_ERROR("Not Supported"); + break; + } + + std::uniform_int_distribution<> distribution(min, max); + library->fill(AccessorType(src), distribution, 0); + + Iterator input(&src, window); + Iterator output(&dst, window); + + const auto loop_function = [&](const Coordinates & id) + { + switch(dt) + { + case DataType::QS8: + { + const qint8x16_t qs8in = vld1q_s8(reinterpret_cast<const qint8_t *>(input.ptr())); + switch(op) + { + case FixedPointOp::EXP: + { + // Use saturated exp + vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vqexpq_qs8(qs8in, fixed_point_position)); + break; + } + case FixedPointOp::INV_SQRT: + { + vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vqinvsqrtq_qs8(qs8in, fixed_point_position)); + break; + } + case FixedPointOp::LOG: + { + vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vlogq_qs8(qs8in, fixed_point_position)); + break; + } + case FixedPointOp::RECIPROCAL: + { + vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vrecipq_qs8(qs8in, fixed_point_position)); + break; + } + default: + ARM_COMPUTE_ERROR("Not Supported"); + break; + } + break; + } + case DataType::QS16: + { + const qint16x8_t qs16in = vld1q_qs16(reinterpret_cast<const qint16_t *>(input.ptr())); + switch(op) + { + case FixedPointOp::EXP: + { + // Use saturated exp + vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqexpq_qs16(qs16in, fixed_point_position)); + break; + } + case FixedPointOp::INV_SQRT: + { + vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqinvsqrtq_qs16(qs16in, fixed_point_position)); + break; + } + case FixedPointOp::LOG: + { + vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vlogq_qs16(qs16in, fixed_point_position)); + break; + } + case FixedPointOp::RECIPROCAL: + { + vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqrecipq_qs16(qs16in, fixed_point_position)); + break; + } + default: + ARM_COMPUTE_ERROR("Not Supported"); + break; + } + break; + } + default: + ARM_COMPUTE_ERROR("Not Supported"); + break; + } + }; + + execute_window_loop(window, loop_function, input, output); +} +} // namespace +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_FIXED_POINT_NEON_TARGET */ diff --git a/tests/validation/fixtures/FixedPointFixture.h b/tests/validation/fixtures/FixedPointFixture.h new file mode 100644 index 0000000000..2980e2f324 --- /dev/null +++ b/tests/validation/fixtures/FixedPointFixture.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef ARM_COMPUTE_TEST_FIXED_POINT_FIXTURE +#define ARM_COMPUTE_TEST_FIXED_POINT_FIXTURE + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/AssetsLibrary.h" +#include "tests/Globals.h" +#include "tests/IAccessor.h" +#include "tests/framework/Asserts.h" +#include "tests/framework/Fixture.h" +#include "tests/validation/CPP/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +template <typename TensorType, typename AccessorType, typename T> +class FixedPointValidationFixture : public framework::Fixture +{ +public: + template <typename...> + void setup(TensorShape shape, DataType dt, FixedPointOp op, int fractional_bits) + { + _fractional_bits = fractional_bits; + _target = compute_target(shape, dt, op, fractional_bits); + _reference = compute_reference(shape, dt, op, fractional_bits); + } + +protected: + template <typename U> + void fill(U &&tensor, int min, int max, int i) + { + std::uniform_int_distribution<> distribution(min, max); + library->fill(tensor, distribution, i); + } + + TensorType compute_target(const TensorShape &shape, DataType dt, FixedPointOp op, int fixed_point_position) + { + // Create tensors + TensorType src = create_tensor<TensorType>(shape, dt, 1, fixed_point_position); + TensorType dst = create_tensor<TensorType>(shape, dt, 1, fixed_point_position); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + compute_target_impl<TensorType, AccessorType, T>(shape, dt, op, fixed_point_position, src, dst); + + return dst; + } + + SimpleTensor<T> compute_reference(const TensorShape &shape, DataType dt, FixedPointOp op, int fixed_point_position) + { + // Create reference + SimpleTensor<T> src{ shape, dt, 1, fixed_point_position }; + + // Fill reference + int min = 0; + int max = 0; + switch(op) + { + case FixedPointOp::EXP: + min = -(1 << (fixed_point_position - 1)); + max = (1 << (fixed_point_position - 1)); + break; + case FixedPointOp::INV_SQRT: + min = 1; + max = (dt == DataType::QS8) ? 0x7F : 0x7FFF; + break; + case FixedPointOp::LOG: + min = (1 << (fixed_point_position - 1)); + max = (dt == DataType::QS8) ? 0x3F : 0x3FFF; + break; + case FixedPointOp::RECIPROCAL: + min = 15; + max = (dt == DataType::QS8) ? 0x7F : 0x7FFF; + break; + default: + ARM_COMPUTE_ERROR("Fixed point operation not supported"); + break; + } + fill(src, min, max, 0); + + return reference::fixed_point_operation<T>(src, op); + } + + TensorType _target{}; + SimpleTensor<T> _reference{}; + int _fractional_bits{}; +}; +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_FIXED_POINT_FIXTURE */ diff --git a/tests/validation_old/NEON/Fixedpoint/Exp_QS16.cpp b/tests/validation_old/NEON/Fixedpoint/Exp_QS16.cpp deleted file mode 100644 index a0e785e112..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Exp_QS16.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 1.0f; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon exponential function for signed 16 bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_exp_qs16(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 8; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [-1.0, 1.0) so the result won't - // overflow. - std::uniform_int_distribution<> distribution(-(1 << (fixed_point_position - 1)), (1 << (fixed_point_position - 1))); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint16x8_t in = vld1q_qs16(reinterpret_cast<const qint16_t *>(input.ptr())); - // Use saturated exp - vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqexpq_qs16(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS16) -BOOST_AUTO_TEST_SUITE(Exp) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 15), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_exp_qs16(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS16, DataType::QS16, FixedPointOp::EXP, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Exp_QS8.cpp b/tests/validation_old/NEON/Fixedpoint/Exp_QS8.cpp deleted file mode 100644 index dbae11640a..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Exp_QS8.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 0.0f; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon exponential function for signed 8bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_exp_qs8(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 16; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [-1.0, 1.0) so the result won't - // overflow. E.g. e^7 = 1096, which cannot be represented in QS8 - std::uniform_int_distribution<> distribution(-(1 << (fixed_point_position - 1)), (1 << (fixed_point_position - 1))); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint8x16_t in = vld1q_s8(reinterpret_cast<const qint8_t *>(input.ptr())); - // Use saturated exp - vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vqexpq_qs8(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS8) -BOOST_AUTO_TEST_SUITE(Exp) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 7), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_exp_qs8(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::EXP, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Invsqrt_QS16.cpp b/tests/validation_old/NEON/Fixedpoint/Invsqrt_QS16.cpp deleted file mode 100644 index 1d06e0799d..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Invsqrt_QS16.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 5.0f; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon inverse square root function for signed 16 bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_invsqrt_qs16(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 8; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [1, 0x7FFF) - std::uniform_int_distribution<> distribution(1, 0x7FFF); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint16x8_t in = vld1q_qs16(reinterpret_cast<const qint16_t *>(input.ptr())); - vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqinvsqrtq_qs16(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS16) -BOOST_AUTO_TEST_SUITE(Invsqrt) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, boost::unit_test::data::xrange(1, 14), fixed_point_position) -{ - TensorShape shape(8192U); - - // Compute function - Tensor dst = compute_invsqrt_qs16(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS16, DataType::QS16, FixedPointOp::INV_SQRT, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Invsqrt_QS8.cpp b/tests/validation_old/NEON/Fixedpoint/Invsqrt_QS8.cpp deleted file mode 100644 index ea21b8f4d6..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Invsqrt_QS8.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 4.0f; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon inverse square root function for signed 8bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_invsqrt_qs8(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 16; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [1, 127). - std::uniform_int_distribution<> distribution(1, 127); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint8x16_t in = vld1q_s8(reinterpret_cast<const qint8_t *>(input.ptr())); - vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vqinvsqrtq_qs8(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS8) -BOOST_AUTO_TEST_SUITE(Invsqrt) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(Small1DShape, SmallShapes() * boost::unit_test::data::xrange(1, 6), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_invsqrt_qs8(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::INV_SQRT, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Log_QS16.cpp b/tests/validation_old/NEON/Fixedpoint/Log_QS16.cpp deleted file mode 100644 index d85112abcc..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Log_QS16.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 7.0f; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon logarithm function for signed 16 bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_log_qs16(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 8; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [(1 << (fixed_point_position - 1), 0x3FFF) so the result won't - // overflow. - std::uniform_int_distribution<> distribution((1 << (fixed_point_position - 1)), 0x3FFF); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint16x8_t in = vld1q_qs16(reinterpret_cast<const qint16_t *>(input.ptr())); - vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vlogq_qs16(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS16) -BOOST_AUTO_TEST_SUITE(Log) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(4, 14), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_log_qs16(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS16, DataType::QS16, FixedPointOp::LOG, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Log_QS8.cpp b/tests/validation_old/NEON/Fixedpoint/Log_QS8.cpp deleted file mode 100644 index 41b285650a..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Log_QS8.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 5; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon logarithm function for signed 8bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_log_qs8(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 16; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [(1 << (fixed_point_position - 1), 63) so the result won't - // overflow. E.g. for Q2.5 ln(0.001) = -6.9, which cannot be represented. - std::uniform_int_distribution<> distribution((1 << (fixed_point_position - 1)), 0x3F); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint8x16_t in = vld1q_s8(reinterpret_cast<const qint8_t *>(input.ptr())); - vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vlogq_qs8(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS8) -BOOST_AUTO_TEST_SUITE(Log) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(3, 6), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_log_qs8(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::LOG, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Reciprocal_QS16.cpp b/tests/validation_old/NEON/Fixedpoint/Reciprocal_QS16.cpp deleted file mode 100644 index 9605595d80..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Reciprocal_QS16.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 11.0f; /**< Tolerance value for comparing reference's output against implementation's output. */ - -/** Compute Neon reciprocal function for signed 16 bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_reciprocal_qs16(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS16, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 8; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [15, 0x7FFF) so the result won't - // overflow. - std::uniform_int_distribution<> distribution(15, 0x7FFF); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint16x8_t in = vld1q_qs16(reinterpret_cast<const qint16_t *>(input.ptr())); - vst1q_qs16(reinterpret_cast<qint16_t *>(output.ptr()), vqrecipq_qs16(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS16) -BOOST_AUTO_TEST_SUITE(Reciprocal) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 14), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_reciprocal_qs16(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS16, DataType::QS16, FixedPointOp::RECIPROCAL, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/NEON/Fixedpoint/Reciprocal_QS8.cpp b/tests/validation_old/NEON/Fixedpoint/Reciprocal_QS8.cpp deleted file mode 100644 index 7a1c5b72a7..0000000000 --- a/tests/validation_old/NEON/Fixedpoint/Reciprocal_QS8.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#include "NEON/Accessor.h" -#include "Utils.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/validation_old/Datasets.h" -#include "tests/validation_old/ReferenceCPP.h" -#include "tests/validation_old/Validation.h" -#include "utils/TypePrinter.h" - -#include "arm_compute/core/Helpers.h" -#include "arm_compute/core/NEON/NEFixedPoint.h" -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/Tensor.h" -#include "arm_compute/runtime/TensorAllocator.h" - -#include "tests/validation_old/boost_wrapper.h" - -#include <random> -#include <string> - -using namespace arm_compute; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -namespace -{ -const float tolerance = 3; /**< Tolerance value for comparing reference's output against implementation's output */ - -/** Compute Neon reciprocal function for signed 8bit fixed point. - * - * @param[in] shape Shape of the input and output tensors. - * - * @return Computed output tensor. - */ -Tensor compute_reciprocal_qs8(const TensorShape &shape, int fixed_point_position) -{ - // Create tensors - Tensor src = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - Tensor dst = create_tensor<Tensor>(shape, DataType::QS8, 1, fixed_point_position); - - constexpr unsigned int num_elems_processed_per_iteration = 16; - Window window = calculate_max_window(*src.info(), Steps(num_elems_processed_per_iteration)); - AccessWindowHorizontal input_access(src.info(), 0, num_elems_processed_per_iteration); - AccessWindowHorizontal output_access(dst.info(), 0, num_elems_processed_per_iteration); - - update_window_and_padding(window, input_access, output_access); - output_access.set_valid_region(window, src.info()->valid_region()); - - // Allocate tensors - src.allocator()->allocate(); - dst.allocator()->allocate(); - - BOOST_TEST(!src.info()->is_resizable()); - BOOST_TEST(!dst.info()->is_resizable()); - - // Fill tensors. Keep the range between [15, 100) so the result won't - // overflow. E.g. for Q2.5 reciprocal(0.001) = 1000, which cannot be represented. - std::uniform_int_distribution<> distribution(15, 0x7F); - library->fill(Accessor(src), distribution, 0); - - Iterator input(&src, window); - Iterator output(&dst, window); - - execute_window_loop(window, [&](const Coordinates & id) - { - qint8x16_t in = vld1q_s8(reinterpret_cast<const qint8_t *>(input.ptr())); - vst1q_s8(reinterpret_cast<qint8_t *>(output.ptr()), vrecipq_qs8(in, fixed_point_position)); - }, - input, output); - - return dst; -} -} // namespace - -#ifndef DOXYGEN_SKIP_THIS -BOOST_AUTO_TEST_SUITE(NEON) -BOOST_AUTO_TEST_SUITE(FixedPoint) -BOOST_AUTO_TEST_SUITE(QS8) -BOOST_AUTO_TEST_SUITE(Reciprocal) - -BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) -BOOST_DATA_TEST_CASE(RunSmall, Small1DShape() * boost::unit_test::data::xrange(1, 6), shape, fixed_point_position) -{ - // Compute function - Tensor dst = compute_reciprocal_qs8(shape, fixed_point_position); - - // Compute reference - RawTensor ref_dst = Reference::compute_reference_fixed_point_operation(shape, DataType::QS8, DataType::QS8, FixedPointOp::RECIPROCAL, fixed_point_position); - - // Validate output - validate(Accessor(dst), ref_dst, tolerance, 0); -} - -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -BOOST_AUTO_TEST_SUITE_END() -#endif /* DOXYGEN_SKIP_THIS */ diff --git a/tests/validation_old/Reference.cpp b/tests/validation_old/Reference.cpp index a3beee5906..628bd11f4b 100644 --- a/tests/validation_old/Reference.cpp +++ b/tests/validation_old/Reference.cpp @@ -186,45 +186,6 @@ RawTensor Reference::compute_reference_roi_pooling_layer(const TensorShape &shap return ref_dst; } -RawTensor Reference::compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position) -{ - // Create reference - RawTensor ref_src(shape, dt_in, 1, fixed_point_position); - RawTensor ref_dst(shape, dt_out, 1, fixed_point_position); - - // Fill reference - int min = 0; - int max = 0; - switch(op) - { - case(FixedPointOp::INV_SQRT): - min = 1; - max = (dt_in == DataType::QS8) ? 0x7F : 0x7FFF; - break; - case(FixedPointOp::LOG): - min = (1 << (fixed_point_position - 1)); - max = (dt_in == DataType::QS8) ? 0x3F : 0x3FFF; - break; - case(FixedPointOp::EXP): - min = -(1 << (fixed_point_position - 1)); - max = (1 << (fixed_point_position - 1)); - break; - case(FixedPointOp::RECIPROCAL): - min = 15; - max = (dt_in == DataType::QS8) ? 0x7F : 0x7FFF; - break; - default: - ARM_COMPUTE_ERROR("Fixed point operation not supported"); - } - std::uniform_int_distribution<> distribution(min, max); - library->fill(ref_src, distribution, 0); - - // Compute reference - ReferenceCPP::fixed_point_operation(ref_src, ref_dst, op); - - return ref_dst; -} - } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation_old/Reference.h b/tests/validation_old/Reference.h index 724f9505b8..f6235f5309 100644 --- a/tests/validation_old/Reference.h +++ b/tests/validation_old/Reference.h @@ -126,17 +126,6 @@ public: * @param[in] pool_info ROI Pooling Layer information. */ static RawTensor compute_reference_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); - /** Compute reference fixed point operation. - * - * @param[in] shape Shape of the input and output tensors. - * @param[in] dt_in Data type of the input tensor. - * @param[in] dt_out Data type of the output tensor. - * @param[in] op Fixed point operation to perform. - * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers - * - * @return Computed raw tensor. - */ - static RawTensor compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position); protected: Reference() = default; diff --git a/tests/validation_old/ReferenceCPP.cpp b/tests/validation_old/ReferenceCPP.cpp index c48de36902..fc274f5c4b 100644 --- a/tests/validation_old/ReferenceCPP.cpp +++ b/tests/validation_old/ReferenceCPP.cpp @@ -165,14 +165,6 @@ void ReferenceCPP::roi_pooling_layer(const RawTensor &src, RawTensor &dst, const boost::apply_visitor(tensor_visitors::roi_pooling_layer_visitor(s, rois, pool_info), d); } -// Fixed point operation -void ReferenceCPP::fixed_point_operation(const RawTensor &src, RawTensor &dst, FixedPointOp op) -{ - const TensorVariant s = TensorFactory::get_tensor(src); - TensorVariant d = TensorFactory::get_tensor(dst); - boost::apply_visitor(tensor_visitors::fixed_point_operation_visitor(s, op), d); -} - } // namespace validation } // namespace test } // namespace arm_compute diff --git a/tests/validation_old/ReferenceCPP.h b/tests/validation_old/ReferenceCPP.h index 1adf59dc9d..6bc44b32b4 100644 --- a/tests/validation_old/ReferenceCPP.h +++ b/tests/validation_old/ReferenceCPP.h @@ -148,13 +148,6 @@ public: * @param[in] pool_info ROI Pooling Layer information. */ static void roi_pooling_layer(const RawTensor &src, RawTensor &dst, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info); - /** Fixed point operations of @p src - * - * @param[in] src Input tensor. - * @param[out] dst Result tensor. - * @param[in] op Fixed point operation to perform. - */ - static void fixed_point_operation(const RawTensor &src, RawTensor &dst, FixedPointOp op); private: ReferenceCPP() = delete; |