diff options
Diffstat (limited to 'tests/CL/Helper.h')
-rw-r--r-- | tests/CL/Helper.h | 139 |
1 files changed, 127 insertions, 12 deletions
diff --git a/tests/CL/Helper.h b/tests/CL/Helper.h index e548af4938..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,21 +24,103 @@ #ifndef ARM_COMPUTE_TEST_CL_HELPER_H #define ARM_COMPUTE_TEST_CL_HELPER_H -#include "src/core/CL/kernels/CLFillBorderKernel.h" -#include "src/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 "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 "support/MemorySupport.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 @@ -51,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); } @@ -63,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); @@ -92,7 +174,7 @@ 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()); @@ -113,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: @@ -126,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 */ |