From 237be03ada644232b19005f44742b97efa5dbfc6 Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Mon, 25 Jan 2021 15:44:02 +0000 Subject: Make Gpu Elementwise Operations kernels and functions state-less Partially resolves COMPMID-4004 Change-Id: Ie99b6c676af5be4c2a67affc06fec378f3dff8ec Signed-off-by: Michele Di Giorgio Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4918 Reviewed-by: Gian Marco Iodice Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- .../CL/functions/CLElementwiseOperations.cpp | 175 ++++----------------- 1 file changed, 34 insertions(+), 141 deletions(-) (limited to 'src/runtime/CL/functions/CLElementwiseOperations.cpp') diff --git a/src/runtime/CL/functions/CLElementwiseOperations.cpp b/src/runtime/CL/functions/CLElementwiseOperations.cpp index 9b809eebc7..60c699cbb8 100644 --- a/src/runtime/CL/functions/CLElementwiseOperations.cpp +++ b/src/runtime/CL/functions/CLElementwiseOperations.cpp @@ -23,124 +23,17 @@ */ #include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h" +#include "arm_compute/core/CL/CLKernelLibrary.h" #include "arm_compute/core/CL/ICLTensor.h" -#include "arm_compute/runtime/CL/CLScheduler.h" -#include "src/core/gpu/cl/kernels/ClElementwiseKernel.h" +#include "arm_compute/core/Types.h" +#include "src/core/CL/ICLKernel.h" #include "src/runtime/gpu/cl/operators/ClAdd.h" +#include "src/runtime/gpu/cl/operators/ClElementwiseOperations.h" #include "src/runtime/gpu/cl/operators/ClSub.h" -#include - namespace arm_compute { -namespace experimental -{ -CLArithmeticDivision::CLArithmeticDivision() -{ -} - -void CLArithmeticDivision::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - auto k = std::make_unique(); - k->configure(compile_context, ArithmeticOperation::DIV, input1, input2, output, act_info); - _kernel = std::move(k); -} - -Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - return arm_compute::opencl::kernels::ClArithmeticKernel::validate(ArithmeticOperation::DIV, input1, input2, output, act_info); -} - -void CLArithmeticDivision::run(ITensorPack &tensors) -{ - ICLOperator::run(tensors); -} - -CLElementwiseMax::CLElementwiseMax() -{ -} - -void CLElementwiseMax::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - auto k = std::make_unique(); - k->configure(compile_context, ArithmeticOperation::MAX, input1, input2, output, act_info); - _kernel = std::move(k); -} - -Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - return arm_compute::opencl::kernels::ClArithmeticKernel::validate(ArithmeticOperation::MAX, input1, input2, output, act_info); -} - -void CLElementwiseMax::run(ITensorPack &tensors) -{ - ICLOperator::run(tensors); -} - -CLElementwiseMin::CLElementwiseMin() -{ -} - -void CLElementwiseMin::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - auto k = std::make_unique(); - k->configure(compile_context, ArithmeticOperation::MIN, input1, input2, output, act_info); - _kernel = std::move(k); -} - -Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - return arm_compute::opencl::kernels::ClArithmeticKernel::validate(ArithmeticOperation::MIN, input1, input2, output, act_info); -} - -void CLElementwiseMin::run(ITensorPack &tensors) -{ - ICLOperator::run(tensors); -} - -CLElementwiseSquaredDiff::CLElementwiseSquaredDiff() -{ -} - -void CLElementwiseSquaredDiff::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - auto k = std::make_unique(); - k->configure(compile_context, ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info); - _kernel = std::move(k); -} - -Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - return arm_compute::opencl::kernels::ClArithmeticKernel::validate(ArithmeticOperation::SQUARED_DIFF, input1, input2, output, act_info); -} - -void CLElementwiseSquaredDiff::run(ITensorPack &tensors) -{ - ICLOperator::run(tensors); -} - -CLElementwisePower::CLElementwisePower() -{ -} - -void CLElementwisePower::configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - auto k = std::make_unique(); - k->configure(compile_context, ArithmeticOperation::POWER, input1, input2, output, act_info); - _kernel = std::move(k); -} - -Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) -{ - return arm_compute::opencl::kernels::ClArithmeticKernel::validate(ArithmeticOperation::POWER, input1, input2, output, act_info); -} - -void CLElementwisePower::run(ITensorPack &tensors) -{ - ICLOperator::run(tensors); -} -} // namespace experimental struct CLArithmeticAddition::Impl { const ICLTensor *src_0{ nullptr }; @@ -235,10 +128,10 @@ void CLArithmeticSubtraction::run() struct CLArithmeticDivision::Impl { - const ICLTensor *src_0{ nullptr }; - const ICLTensor *src_1{ nullptr }; - ICLTensor *dst{ nullptr }; - std::unique_ptr op{ nullptr }; + const ICLTensor *src_0{ nullptr }; + const ICLTensor *src_1{ nullptr }; + ICLTensor *dst{ nullptr }; + std::unique_ptr op{ nullptr }; }; CLArithmeticDivision::CLArithmeticDivision() @@ -259,13 +152,13 @@ void CLArithmeticDivision::configure(const CLCompileContext &compile_context, co _impl->src_0 = input1; _impl->src_1 = input2; _impl->dst = output; - _impl->op = std::make_unique(); + _impl->op = std::make_unique(); _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); } Status CLArithmeticDivision::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) { - return experimental::CLArithmeticDivision::validate(input1, input2, output, act_info); + return opencl::ClElementwiseDivision::validate(input1, input2, output, act_info); } void CLArithmeticDivision::run() @@ -280,10 +173,10 @@ void CLArithmeticDivision::run() struct CLElementwiseMax::Impl { - const ICLTensor *src_0{ nullptr }; - const ICLTensor *src_1{ nullptr }; - ICLTensor *dst{ nullptr }; - std::unique_ptr op{ nullptr }; + const ICLTensor *src_0{ nullptr }; + const ICLTensor *src_1{ nullptr }; + ICLTensor *dst{ nullptr }; + std::unique_ptr op{ nullptr }; }; CLElementwiseMax::CLElementwiseMax() @@ -304,13 +197,13 @@ void CLElementwiseMax::configure(const CLCompileContext &compile_context, ICLTen _impl->src_0 = input1; _impl->src_1 = input2; _impl->dst = output; - _impl->op = std::make_unique(); + _impl->op = std::make_unique(); _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); } Status CLElementwiseMax::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) { - return experimental::CLElementwiseMax::validate(input1, input2, output, act_info); + return opencl::ClElementwiseMax::validate(input1, input2, output, act_info); } void CLElementwiseMax::run() @@ -325,10 +218,10 @@ void CLElementwiseMax::run() struct CLElementwiseMin::Impl { - const ICLTensor *src_0{ nullptr }; - const ICLTensor *src_1{ nullptr }; - ICLTensor *dst{ nullptr }; - std::unique_ptr op{ nullptr }; + const ICLTensor *src_0{ nullptr }; + const ICLTensor *src_1{ nullptr }; + ICLTensor *dst{ nullptr }; + std::unique_ptr op{ nullptr }; }; CLElementwiseMin::CLElementwiseMin() @@ -349,13 +242,13 @@ void CLElementwiseMin::configure(const CLCompileContext &compile_context, ICLTen _impl->src_0 = input1; _impl->src_1 = input2; _impl->dst = output; - _impl->op = std::make_unique(); + _impl->op = std::make_unique(); _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); } Status CLElementwiseMin::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) { - return experimental::CLElementwiseMin::validate(input1, input2, output, act_info); + return opencl::ClElementwiseMin::validate(input1, input2, output, act_info); } void CLElementwiseMin::run() @@ -370,10 +263,10 @@ void CLElementwiseMin::run() struct CLElementwiseSquaredDiff::Impl { - const ICLTensor *src_0{ nullptr }; - const ICLTensor *src_1{ nullptr }; - ICLTensor *dst{ nullptr }; - std::unique_ptr op{ nullptr }; + const ICLTensor *src_0{ nullptr }; + const ICLTensor *src_1{ nullptr }; + ICLTensor *dst{ nullptr }; + std::unique_ptr op{ nullptr }; }; CLElementwiseSquaredDiff::CLElementwiseSquaredDiff() @@ -394,13 +287,13 @@ void CLElementwiseSquaredDiff::configure(const CLCompileContext &compile_context _impl->src_0 = input1; _impl->src_1 = input2; _impl->dst = output; - _impl->op = std::make_unique(); + _impl->op = std::make_unique(); _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); } Status CLElementwiseSquaredDiff::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) { - return experimental::CLElementwiseSquaredDiff::validate(input1, input2, output, act_info); + return opencl::ClElementwiseSquaredDiff::validate(input1, input2, output, act_info); } void CLElementwiseSquaredDiff::run() @@ -415,10 +308,10 @@ void CLElementwiseSquaredDiff::run() struct CLElementwisePower::Impl { - const ICLTensor *src_0{ nullptr }; - const ICLTensor *src_1{ nullptr }; - ICLTensor *dst{ nullptr }; - std::unique_ptr op{ nullptr }; + const ICLTensor *src_0{ nullptr }; + const ICLTensor *src_1{ nullptr }; + ICLTensor *dst{ nullptr }; + std::unique_ptr op{ nullptr }; }; CLElementwisePower::CLElementwisePower() @@ -439,13 +332,13 @@ void CLElementwisePower::configure(const CLCompileContext &compile_context, ICLT _impl->src_0 = input1; _impl->src_1 = input2; _impl->dst = output; - _impl->op = std::make_unique(); + _impl->op = std::make_unique(); _impl->op->configure(compile_context, input1->info(), input2->info(), output->info(), act_info); } Status CLElementwisePower::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info) { - return experimental::CLElementwisePower::validate(input1, input2, output, act_info); + return opencl::ClElementwisePower::validate(input1, input2, output, act_info); } void CLElementwisePower::run() -- cgit v1.2.1