diff options
Diffstat (limited to 'tests/CL')
-rw-r--r-- | tests/CL/CLAccessor.h | 13 | ||||
-rw-r--r-- | tests/CL/CLArrayAccessor.h | 2 | ||||
-rw-r--r-- | tests/CL/CLHOGAccessor.h | 70 | ||||
-rw-r--r-- | tests/CL/CLLutAccessor.h | 96 | ||||
-rw-r--r-- | tests/CL/Helper.h | 145 |
5 files changed, 142 insertions, 184 deletions
diff --git a/tests/CL/CLAccessor.h b/tests/CL/CLAccessor.h index c0aee56b8a..ef1983364b 100644 --- a/tests/CL/CLAccessor.h +++ b/tests/CL/CLAccessor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -26,6 +26,7 @@ #include "arm_compute/runtime/CL/CLTensor.h" #include "tests/IAccessor.h" +#include "tests/framework/Framework.h" namespace arm_compute { @@ -86,12 +87,18 @@ private: inline CLAccessor::CLAccessor(CLTensor &tensor) : _tensor{ tensor } { - _tensor.map(); + if(!framework::Framework::get().configure_only() || !framework::Framework::get().new_fixture_call()) + { + _tensor.map(); + } } inline CLAccessor::~CLAccessor() { - _tensor.unmap(); + if(!framework::Framework::get().configure_only() || !framework::Framework::get().new_fixture_call()) + { + _tensor.unmap(); + } } inline TensorShape CLAccessor::shape() const diff --git a/tests/CL/CLArrayAccessor.h b/tests/CL/CLArrayAccessor.h index 08c86b1c46..cfc63095a2 100644 --- a/tests/CL/CLArrayAccessor.h +++ b/tests/CL/CLArrayAccessor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2019 Arm Limited. * * SPDX-License-Identifier: MIT * diff --git a/tests/CL/CLHOGAccessor.h b/tests/CL/CLHOGAccessor.h deleted file mode 100644 index 0d8751b5c3..0000000000 --- a/tests/CL/CLHOGAccessor.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018-2020 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_CLHOGACCESSOR_H -#define ARM_COMPUTE_TEST_CLHOGACCESSOR_H - -#include "arm_compute/runtime/CL/CLHOG.h" -#include "tests/IHOGAccessor.h" - -namespace arm_compute -{ -namespace test -{ -/** Accessor implementation for @ref CLHOG objects. */ -class CLHOGAccessor : public IHOGAccessor -{ -public: - /** Create an accessor for the given @p CLHOG. */ - CLHOGAccessor(CLHOG &hog) - : _hog{ hog } - { - _hog.map(); - } - - /** Destructor that unmaps the CL memory. */ - ~CLHOGAccessor() - { - _hog.unmap(); - } - - /** Prevent instances of this class from being copied (As this class contains references). */ - CLHOGAccessor(const CLHOGAccessor &) = delete; - /** Prevent instances of this class from being copied (As this class contains references). */ - CLHOGAccessor &operator=(const CLHOGAccessor &) = delete; - - /** Pointer to the first element of the array which stores the linear SVM coefficients of HOG descriptor - * - * @return A pointer to the first element of the array which stores the linear SVM coefficients of HOG descriptor - */ - float *descriptor() const override - { - return _hog.descriptor(); - } - -private: - CLHOG &_hog; -}; -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CLHOGACCESSOR_H */ diff --git a/tests/CL/CLLutAccessor.h b/tests/CL/CLLutAccessor.h deleted file mode 100644 index 57047e244f..0000000000 --- a/tests/CL/CLLutAccessor.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2017-2019 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_CL_CLLUTACCESSOR_H -#define ARM_COMPUTE_TEST_CL_CLLUTACCESSOR_H - -#include "tests/ILutAccessor.h" - -#include "arm_compute/runtime/CL/CLLut.h" - -namespace arm_compute -{ -namespace test -{ -/** Accessor implementation for @ref CLLut objects. */ -template <typename T> -class CLLutAccessor : public ILutAccessor<T> -{ -public: - /** Create an accessor for the given @p CLLut. - */ - CLLutAccessor(CLLut &lut) - : _lut{ lut } - { - _lut.map(true); - } - /** Default destructor */ - ~CLLutAccessor() - { - _lut.unmap(); - } - - /** Prevent instances of this class from being copy constructed */ - CLLutAccessor(const CLLutAccessor &) = delete; - /** Prevent instances of this class from being copied */ - CLLutAccessor &operator=(const CLLutAccessor &) = delete; - /** Allow instances of this class to be move constructed */ - CLLutAccessor(CLLutAccessor &&) = default; - /** Allow instance of this class to be moved */ - CLLutAccessor &operator=(CLLutAccessor &&) = default; - - int num_elements() const override - { - return _lut.num_elements(); - } - - const T &operator[](T input_value) const override - { - auto lut = reinterpret_cast<T *>(_lut.buffer()); - int32_t real_index = _lut.index_offset() + static_cast<int32_t>(input_value); - - if(0 <= real_index && real_index < num_elements()) - { - return lut[real_index]; - } - ARM_COMPUTE_ERROR("Error index not in range."); - } - - T &operator[](T input_value) override - { - auto lut = reinterpret_cast<T *>(_lut.buffer()); - int32_t real_index = _lut.index_offset() + static_cast<int32_t>(input_value); - - if(0 <= real_index && real_index < num_elements()) - { - return lut[real_index]; - } - ARM_COMPUTE_ERROR("Error index not in range."); - } - -private: - CLLut &_lut; -}; -} // namespace test -} // namespace arm_compute -#endif /* ARM_COMPUTE_TEST_CL_CLLUTACCESSOR_H */ diff --git a/tests/CL/Helper.h b/tests/CL/Helper.h index 50d6162acc..dd5e8647b0 100644 --- a/tests/CL/Helper.h +++ b/tests/CL/Helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 ARM Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -24,19 +24,103 @@ #ifndef ARM_COMPUTE_TEST_CL_HELPER_H #define ARM_COMPUTE_TEST_CL_HELPER_H -#include "arm_compute/core/CL/ICLKernel.h" -#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h" -#include "arm_compute/core/CL/kernels/CLMemsetKernel.h" - #include "arm_compute/runtime/CL/CLScheduler.h" #include "arm_compute/runtime/CL/ICLSimpleFunction.h" +#include "arm_compute/runtime/CL/functions/CLFill.h" #include "arm_compute/runtime/IFunction.h" -#include "support/MemorySupport.h" +#include "src/core/CL/kernels/CLFillBorderKernel.h" +#include "src/gpu/cl/IClOperator.h" +#include "src/gpu/cl/operators/ClFill.h" + +#include "src/core/CL/ICLKernel.h" +#include "support/Cast.h" + +#include <memory> namespace arm_compute { namespace test { +/** This template synthetizes a simple IOperator which runs the given kernel K */ +template <typename K> +class CLSynthetizeOperator : public opencl::IClOperator +{ +public: + /** Configure the kernel. + * + * @param[in] args Configuration arguments. + */ + template <typename... Args> + void configure(Args &&... args) + { + auto k = std::make_unique<K>(); + k->configure(CLKernelLibrary::get().get_compile_context(), std::forward<Args>(args)...); + _kernel = std::move(k); + } + /** Configure the kernel setting the GPU target as well + * + * @param[in] gpu_target GPUTarget to set + * @param[in] args Configuration arguments. + */ + template <typename... Args> + void configure(GPUTarget gpu_target, Args &&... args) + { + auto k = std::make_unique<K>(); + k->set_target(gpu_target); + k->configure(CLKernelLibrary::get().get_compile_context(), std::forward<Args>(args)...); + _kernel = std::move(k); + } + /** Validate input arguments + * + * @param[in] args Configuration arguments. + */ + template <typename... Args> + static Status validate(Args &&... args) + { + return K::validate(std::forward<Args>(args)...); + } +}; + +/** As above but this also initializes to zero the input tensor */ +template <typename K, int bordersize> +class CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder : public opencl::IClOperator +{ +public: + /** Configure the kernel. + * + * @param[in] first First input argument. + * @param[in] second Second input argument. + * @param[in] args Rest of the configuration arguments. + */ + template <typename T, typename... Args> + void configure(T first, T second, Args &&... args) + { + auto cctx = CLKernelLibrary::get().get_compile_context(); + auto k = std::make_unique<K>(); + k->set_target(CLScheduler::get().target()); + k->configure(cctx, first, second, std::forward<Args>(args)...); + _kernel = std::move(k); + _border_handler.configure(cctx, first, BorderSize(bordersize), BorderMode::CONSTANT, PixelValue()); + _fill.configure(cctx, second, PixelValue()); + } + + // Inherited method overridden: + void run(ITensorPack &tensors) override final + { + ARM_COMPUTE_ERROR_ON_MSG(!_kernel, "The CL kernel or function isn't configured"); + + ITensorPack fill_pack = { { ACL_SRC, tensors.get_tensor(TensorType::ACL_DST) } }; + _fill.run(fill_pack); + CLScheduler::get().enqueue_op(_border_handler, tensors); + CLScheduler::get().enqueue_op(*_kernel, tensors); + } + +private: + opencl::ClFill _fill{}; /**< Kernel to initialize the tensor */ + CLFillBorderKernel _border_handler{}; /**< Kernel to handle borders */ + std::unique_ptr<ICLKernel> _kernel{}; /**< Kernel to run */ +}; + /** This template synthetizes an ICLSimpleFunction which runs the given kernel K */ template <typename K> class CLSynthetizeFunction : public ICLSimpleFunction @@ -49,7 +133,7 @@ public: template <typename... Args> void configure(Args &&... args) { - auto k = arm_compute::support::cpp14::make_unique<K>(); + auto k = std::make_unique<K>(); k->configure(std::forward<Args>(args)...); _kernel = std::move(k); } @@ -61,7 +145,7 @@ public: template <typename... Args> void configure(GPUTarget gpu_target, Args &&... args) { - auto k = arm_compute::support::cpp14::make_unique<K>(); + auto k = std::make_unique<K>(); k->set_target(gpu_target); k->configure(std::forward<Args>(args)...); _kernel = std::move(k); @@ -90,10 +174,10 @@ public: template <typename T, typename... Args> void configure(T first, Args &&... args) { - auto k = arm_compute::support::cpp14::make_unique<K>(); + auto k = std::make_unique<K>(); k->configure(first, std::forward<Args>(args)...); _kernel = std::move(k); - _border_handler.configure(first, BorderSize(bordersize), BorderMode::CONSTANT, PixelValue()); + _border_handler->configure(first, BorderSize(bordersize), BorderMode::CONSTANT, PixelValue()); } }; @@ -111,12 +195,12 @@ public: template <typename T, typename... Args> void configure(T first, T second, Args &&... args) { - auto k = arm_compute::support::cpp14::make_unique<K>(); + auto k = std::make_unique<K>(); k->set_target(CLScheduler::get().target()); k->configure(first, second, std::forward<Args>(args)...); _kernel = std::move(k); _border_handler.configure(first, BorderSize(bordersize), BorderMode::CONSTANT, PixelValue()); - _memset_kernel.configure(second, PixelValue()); + _fill.configure(second, PixelValue()); } // Inherited method overridden: @@ -124,16 +208,49 @@ public: { ARM_COMPUTE_ERROR_ON_MSG(!_kernel, "The CL kernel or function isn't configured"); - CLScheduler::get().enqueue(_memset_kernel, false); + _fill.run(); CLScheduler::get().enqueue(_border_handler, false); CLScheduler::get().enqueue(*_kernel); } private: - CLMemsetKernel _memset_kernel{}; /**< Kernel to initialize the tensor */ + CLFill _fill{}; /**< Kernel to initialize the tensor */ CLFillBorderKernel _border_handler{}; /**< Kernel to handle borders */ std::unique_ptr<ICLKernel> _kernel{}; /**< Kernel to run */ }; + +/** As above but this also setups a Zero border on the input tensor of the kernel's bordersize */ +template <typename K> +class ClSynthetizeOperatorWithBorder : public opencl::IClOperator +{ +public: + /** Configure the kernel. + * + * @param[in] first First configuration argument. + * @param[in] args Rest of the configuration arguments. + */ + template <typename T, typename... Args> + void configure(T first, Args &&... args) + { + auto k = std::make_unique<K>(); + k->configure(CLKernelLibrary::get().get_compile_context(), first, std::forward<Args>(args)...); + _kernel = std::move(k); + + auto b = std::make_unique<CLFillBorderKernel>(); + b->configure(CLKernelLibrary::get().get_compile_context(), first, BorderSize(_kernel->border_size()), BorderMode::CONSTANT, PixelValue()); + _border_handler = std::move(b); + } + + void run(ITensorPack &tensors) override + { + CLScheduler::get().enqueue(*_border_handler); + CLScheduler::get().enqueue_op(*_kernel, tensors); + } + +private: + std::unique_ptr<ICLKernel> _border_handler{ nullptr }; /**< Kernel to handle borders */ + std::unique_ptr<ICLKernel> _kernel{}; /**< Kernel to run */ +}; } // namespace test } // namespace arm_compute #endif /* ARM_COMPUTE_TEST_CL_HELPER_H */ |