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/validation/CL | |
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/validation/CL')
-rw-r--r-- | tests/validation/CL/FixedPoint/FixedPointTarget.h | 131 | ||||
-rw-r--r-- | tests/validation/CL/FixedPoint/FixedPoint_QS8.cpp | 96 |
2 files changed, 227 insertions, 0 deletions
diff --git a/tests/validation/CL/FixedPoint/FixedPointTarget.h b/tests/validation/CL/FixedPoint/FixedPointTarget.h new file mode 100644 index 0000000000..38473545d9 --- /dev/null +++ b/tests/validation/CL/FixedPoint/FixedPointTarget.h @@ -0,0 +1,131 @@ +/* + * 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_CL_TARGET +#define ARM_COMPUTE_TEST_FIXED_POINT_CL_TARGET + +#include "arm_compute/runtime/CL/CLScheduler.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) +{ + 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 += + "__kernel void fixed_point_operation_qs8( \n" + " __global char* src, \n" + " __global char* dst) \n" + "{ \n" + " char16 in = vload16(0, src + get_global_id(0) * 16); \n" + " if(FIXED_POINT_OP == 0) \n" + " { \n" + " vstore16(EXP_OP_EXPAND(in, DATA_TYPE, 16, FIXED_POINT_POS), 0, dst + get_global_id(0) * 16); \n" + " } \n" + " else if(FIXED_POINT_OP == 1) \n" + " { \n" + " vstore16(INVSQRT_OP_EXPAND(in, DATA_TYPE, 16, FIXED_POINT_POS), 0, dst + get_global_id(0) * 16); \n" + " } \n" + " else \n" + " { \n" + " vstore16(LOG_OP_EXPAND(in, DATA_TYPE, 16, FIXED_POINT_POS), 0, dst + get_global_id(0) * 16); \n" + " } \n" + "} \n" + "\n"; + + // Set build options + std::string build_opts = "-DFIXED_POINT_POS=" + support::cpp11::to_string(fixed_point_position); + build_opts += " -DDATA_TYPE=qs8"; + + // Fill tensors. + int min = 0; + int max = 0; + switch(op) + { + 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): + min = 1; + max = (dt == DataType::QS8) ? 0x7F : 0x7FFF; + build_opts += " -DFIXED_POINT_OP=1"; + break; + case(FixedPointOp::LOG): + min = (1 << (fixed_point_position - 1)); + max = (dt == DataType::QS8) ? 0x3F : 0x3FFF; + build_opts += " -DFIXED_POINT_OP=2"; + break; + default: + ARM_COMPUTE_ERROR("Fixed point operation not supported"); + break; + } + + std::uniform_int_distribution<> distribution(min, max); + library->fill(AccessorType(src), distribution, 0); + + std::vector<std::string> sources; + +#ifndef EMBEDDED_KERNELS + build_opts += " -I" + CLKernelLibrary::get().get_kernel_path(); +#else /* EMBEDDED_KERNELS */ + sources.push_back(CLKernelLibrary::get().get_program_source("fixed_point.h")); +#endif /* EMBEDDED_KERNELS */ + + sources.push_back(fixed_point_operation_kernel); + + // Create program + ::cl::Program program(sources); + + // Build program + program.build(build_opts.c_str()); + + ::cl::Kernel kernel(program, "fixed_point_operation_qs8", nullptr); + + unsigned int idx = 0; + kernel.setArg(idx++, src.cl_buffer()); + kernel.setArg(idx++, dst.cl_buffer()); + + ::cl::NDRange gws(shape[0] / 16, 1, 1); + CLScheduler::get().queue().enqueueNDRangeKernel(kernel, 0, gws); +} +} // namespace +} // 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 |