aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/NEON/functions
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2020-06-16 17:44:46 +0100
committerMichalis Spyrou <michalis.spyrou@arm.com>2020-06-17 09:29:40 +0000
commit1fd2c80692ed8ecefc4d8deb783564ad19eaf70c (patch)
treeb44219bdc8bdc17cb2906dd50a5ba1ee1e6b12fc /src/runtime/NEON/functions
parent27a9e4f10516679bc6e92bec104ae219e1fa7f15 (diff)
downloadComputeLibrary-1fd2c80692ed8ecefc4d8deb783564ad19eaf70c.tar.gz
COMPMID-3375: Port NEActivationLayer functions/kernels to run on
different tensors. Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com> Change-Id: I98782bb73e9dc0899ffb1796aca6f99714adea94 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3343 Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/runtime/NEON/functions')
-rw-r--r--src/runtime/NEON/functions/NEActivationLayer.cpp61
-rw-r--r--src/runtime/NEON/functions/NELSTMLayer.cpp32
-rw-r--r--src/runtime/NEON/functions/NERNNLayer.cpp10
-rw-r--r--src/runtime/NEON/functions/NEReshapeLayer.cpp42
4 files changed, 104 insertions, 41 deletions
diff --git a/src/runtime/NEON/functions/NEActivationLayer.cpp b/src/runtime/NEON/functions/NEActivationLayer.cpp
index e4d1125c79..889ff6b1f4 100644
--- a/src/runtime/NEON/functions/NEActivationLayer.cpp
+++ b/src/runtime/NEON/functions/NEActivationLayer.cpp
@@ -23,25 +23,76 @@
*/
#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h"
+#include "arm_compute/core/Error.h"
#include "arm_compute/core/NEON/kernels/NEActivationLayerKernel.h"
+#include "arm_compute/core/experimental/Types.h"
#include "arm_compute/runtime/IRuntimeContext.h"
+#include "arm_compute/runtime/Tensor.h"
#include "support/MemorySupport.h"
namespace arm_compute
{
-NEActivationLayer::NEActivationLayer(IRuntimeContext *ctx) // NOLINT
- : INESimpleFunctionNoBorder(ctx)
+namespace experimental
{
-}
-void NEActivationLayer::configure(ITensor *input, ITensor *output, ActivationLayerInfo activation_info)
+void NEActivationLayer::configure(const ITensorInfo *input, ITensorInfo *output, const ActivationLayerInfo &activation_info)
{
auto k = arm_compute::support::cpp14::make_unique<NEActivationLayerKernel>();
k->configure(input, output, activation_info);
_kernel = std::move(k);
}
+Status NEActivationLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &activation_info)
+{
+ return NEActivationLayerKernel::validate(input, output, activation_info);
+}
+
+MemoryRequirements NEActivationLayer::workspace() const
+{
+ return MemoryRequirements{};
+}
+} // namespace experimental
+
+struct NEActivationLayer::Impl
+{
+ const ITensor *src{ nullptr };
+ ITensor *dst{ nullptr };
+ IRuntimeContext *ctx{ nullptr };
+ std::unique_ptr<experimental::NEActivationLayer> op{ nullptr };
+};
+
+NEActivationLayer::NEActivationLayer(IRuntimeContext *ctx)
+ : _impl(support::cpp14::make_unique<Impl>())
+{
+ _impl->ctx = ctx;
+}
+
+NEActivationLayer::NEActivationLayer(NEActivationLayer &&) = default;
+
+NEActivationLayer &NEActivationLayer::operator=(NEActivationLayer &&) = default;
+
+NEActivationLayer::~NEActivationLayer() = default;
+
+void NEActivationLayer::configure(ITensor *input, ITensor *output, ActivationLayerInfo activation_info)
+{
+ ARM_COMPUTE_ERROR_ON_NULLPTR(input);
+
+ _impl->src = input;
+ _impl->dst = output == nullptr ? input : output;
+
+ _impl->op = arm_compute::support::cpp14::make_unique<experimental::NEActivationLayer>();
+ _impl->op->configure(_impl->src->info(), _impl->dst->info(), activation_info);
+}
+
Status NEActivationLayer::validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
{
- return NEActivationLayerKernel::validate(input, output, act_info);
+ return experimental::NEActivationLayer::validate(input, output, act_info);
+}
+
+void NEActivationLayer::run()
+{
+ const InputTensor src{ TensorType::ACL_SRC, _impl->src };
+ OutputTensor dst{ TensorType::ACL_DST, _impl->dst };
+
+ _impl->op->run({ src }, { dst }, {});
}
} // namespace arm_compute
diff --git a/src/runtime/NEON/functions/NELSTMLayer.cpp b/src/runtime/NEON/functions/NELSTMLayer.cpp
index f9d445fe71..0a111363e3 100644
--- a/src/runtime/NEON/functions/NELSTMLayer.cpp
+++ b/src/runtime/NEON/functions/NELSTMLayer.cpp
@@ -474,7 +474,7 @@ Status NELSTMLayer::validate(const ITensorInfo *input,
RoundingPolicy::TO_ZERO));
ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&forget_gate, forget_gate_bias, &forget_gate, ConvertPolicy::SATURATE));
}
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&forget_gate, &forget_gate, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&forget_gate, &forget_gate, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)));
// Validate input gate
if(!lstm_params.has_cifg_opt())
@@ -508,7 +508,7 @@ Status NELSTMLayer::validate(const ITensorInfo *input,
ARM_COMPUTE_RETURN_ON_ERROR(NEPixelWiseMultiplicationKernel::validate(&input_gate, lstm_params.input_layer_norm_weights(), &input_gate, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO));
ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&input_gate, lstm_params.input_gate_bias(), &input_gate, ConvertPolicy::SATURATE));
}
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&input_gate, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&input_gate, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)));
}
else
{
@@ -526,14 +526,14 @@ Status NELSTMLayer::validate(const ITensorInfo *input,
RoundingPolicy::TO_ZERO));
ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&cell_state_tmp, cell_bias, &cell_state_tmp, ConvertPolicy::SATURATE));
}
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&cell_state_tmp, nullptr, activation_info));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&cell_state_tmp, nullptr, activation_info));
ARM_COMPUTE_RETURN_ON_ERROR(NEPixelWiseMultiplicationKernel::validate(&cell_state_tmp, &input_gate, &cell_state_tmp, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO));
ARM_COMPUTE_RETURN_ON_ERROR(NEPixelWiseMultiplicationKernel::validate(&cell_state_tmp, &forget_gate, &cell_state_tmp, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO));
ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&cell_state_tmp, &cell_state_tmp, &cell_state_tmp, ConvertPolicy::SATURATE));
if(cell_threshold != 0.f)
{
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&cell_state_tmp, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -cell_threshold,
- cell_threshold)));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&cell_state_tmp, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -cell_threshold,
+ cell_threshold)));
}
// Validate output gate tmp
@@ -559,18 +559,18 @@ Status NELSTMLayer::validate(const ITensorInfo *input,
RoundingPolicy::TO_ZERO));
ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&output_gate_tmp, output_gate_bias, &output_gate_tmp, ConvertPolicy::SATURATE));
}
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&output_gate_tmp, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&output_gate_tmp, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)));
// Validate output state
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&cell_state_tmp, &cell_state_tmp, activation_info));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&cell_state_tmp, &cell_state_tmp, activation_info));
ARM_COMPUTE_RETURN_ON_ERROR(NEPixelWiseMultiplicationKernel::validate(&cell_state_tmp, &output_gate_tmp, &output_gate_tmp, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO));
if(lstm_params.has_projection())
{
ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(&output_gate_tmp, lstm_params.projection_weights(), lstm_params.projection_bias(), output_state_out));
if(projection_threshold != 0.f)
{
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(output_state_out, output_state_out,
- ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold)));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(output_state_out, output_state_out,
+ ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold)));
}
}
@@ -612,7 +612,7 @@ void NELSTMLayer::run()
NEScheduler::get().schedule(&_pixelwise_mul_forget_gate_coeff, Window::DimY);
NEScheduler::get().schedule(&_accum_forget_gate_bias, Window::DimY);
}
- NEScheduler::get().schedule(&_activation_forget_gate, Window::DimY);
+ _activation_forget_gate.run();
if(_run_cifg_opt)
{
@@ -642,7 +642,7 @@ void NELSTMLayer::run()
NEScheduler::get().schedule(&_pixelwise_mul_input_gate_coeff, Window::DimY);
NEScheduler::get().schedule(&_accum_input_gate_bias, Window::DimY);
}
- NEScheduler::get().schedule(&_activation_input_gate, Window::DimY);
+ _activation_input_gate.run();
}
_fully_connected_cell_state.run();
@@ -655,14 +655,14 @@ void NELSTMLayer::run()
NEScheduler::get().schedule(&_pixelwise_mul_cell_gate_coeff, Window::DimY);
NEScheduler::get().schedule(&_accum_cell_gate_bias, Window::DimY);
}
- NEScheduler::get().schedule(&_activation_cell_state, Window::DimY);
+ _activation_cell_state.run();
NEScheduler::get().schedule(&_pixelwise_mul_cell_state1, Window::DimY);
NEScheduler::get().schedule(&_pixelwise_mul_cell_state2, Window::DimY);
NEScheduler::get().schedule(&_accum_cell_state2, Window::DimY);
if(_perform_cell_clipping)
{
- NEScheduler::get().schedule(&_cell_clip, Window::DimY);
+ _cell_clip.run();
}
_fully_connected_output.run();
@@ -677,9 +677,9 @@ void NELSTMLayer::run()
NEScheduler::get().schedule(&_pixelwise_mul_output_gate_coeff, Window::DimY);
NEScheduler::get().schedule(&_accum_output_gate_bias, Window::DimY);
}
- NEScheduler::get().schedule(&_activation_output, Window::DimY);
+ _activation_output.run();
- NEScheduler::get().schedule(&_activation_output_state, Window::DimY);
+ _activation_output_state.run();
NEScheduler::get().schedule(&_pixelwise_mul_output_state2, Window::DimY);
if(_has_projection_weights)
@@ -687,7 +687,7 @@ void NELSTMLayer::run()
_fully_connected_output_state.run();
if(_perform_projection_clipping)
{
- NEScheduler::get().schedule(&_projection_clip, Window::DimY);
+ _projection_clip.run();
}
}
diff --git a/src/runtime/NEON/functions/NERNNLayer.cpp b/src/runtime/NEON/functions/NERNNLayer.cpp
index 154b060c3d..4a15777be9 100644
--- a/src/runtime/NEON/functions/NERNNLayer.cpp
+++ b/src/runtime/NEON/functions/NERNNLayer.cpp
@@ -34,8 +34,8 @@
namespace arm_compute
{
NERNNLayer::NERNNLayer(std::shared_ptr<IMemoryManager> memory_manager)
- : _memory_group(std::move(memory_manager)), _gemm_state_f(), _add_kernel(), _activation_kernel(), _fully_connected(memory_manager), _copy_kernel(), _fully_connected_out(), _gemm_output(),
- _add_output(), _is_prepared(false)
+ : _memory_group(std::move(memory_manager)), _gemm_state_f(), _add_kernel(), _activation(), _fully_connected(memory_manager), _copy_kernel(), _fully_connected_out(), _gemm_output(), _add_output(),
+ _is_prepared(false)
{
}
@@ -60,7 +60,7 @@ Status NERNNLayer::validate(const ITensorInfo *input, const ITensorInfo *weights
ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(input, weights, bias, &shape_info));
ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAdditionKernel::validate(&shape_info, &shape_info, &shape_info, ConvertPolicy::SATURATE));
- ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayerKernel::validate(&shape_info, &shape_info, info));
+ ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&shape_info, &shape_info, info));
return Status{};
}
@@ -95,7 +95,7 @@ void NERNNLayer::configure(const ITensor *input, const ITensor *weights, const I
_fully_connected_out.allocator()->allocate();
_gemm_output.allocator()->allocate();
- _activation_kernel.configure(&_add_output, hidden_state, info);
+ _activation.configure(&_add_output, hidden_state, info);
_add_output.allocator()->allocate();
_copy_kernel.configure(hidden_state, output);
@@ -112,7 +112,7 @@ void NERNNLayer::run()
_gemm_state_f.run();
NEScheduler::get().schedule(&_add_kernel, Window::DimY);
- NEScheduler::get().schedule(&_activation_kernel, Window::DimY);
+ _activation.run();
// copy hidden out to output
NEScheduler::get().schedule(&_copy_kernel, Window::DimY);
diff --git a/src/runtime/NEON/functions/NEReshapeLayer.cpp b/src/runtime/NEON/functions/NEReshapeLayer.cpp
index 680abef026..daf358e7db 100644
--- a/src/runtime/NEON/functions/NEReshapeLayer.cpp
+++ b/src/runtime/NEON/functions/NEReshapeLayer.cpp
@@ -44,7 +44,7 @@ void NEReshapeLayer::configure(const ITensorInfo *input, ITensorInfo *output)
Status NEReshapeLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
{
- return arm_compute::NEReshapeLayer::validate(input, output);
+ return arm_compute::NEReshapeLayerKernel::validate(input, output);
}
MemoryRequirements NEReshapeLayer::workspace() const
@@ -53,32 +53,44 @@ MemoryRequirements NEReshapeLayer::workspace() const
}
} // namespace experimental
-void NEReshapeLayer::configure(const ITensor *input, ITensor *output)
+struct NEReshapeLayer::Impl
{
- _input = input;
- _output = output;
+ const ITensor *src{ nullptr };
+ ITensor *dst{ nullptr };
+ std::unique_ptr<experimental::NEReshapeLayer> op{ nullptr };
+};
- auto k = arm_compute::support::cpp14::make_unique<NEReshapeLayerKernel>();
- k->configure(input->info(), output->info());
- _kernel = std::move(k);
+NEReshapeLayer::NEReshapeLayer()
+ : _impl(support::cpp14::make_unique<Impl>())
+{
+}
+
+NEReshapeLayer::NEReshapeLayer(NEReshapeLayer &&) = default;
+
+NEReshapeLayer &NEReshapeLayer::operator=(NEReshapeLayer &&) = default;
+
+NEReshapeLayer::~NEReshapeLayer() = default;
+
+void NEReshapeLayer::configure(const ITensor *input, ITensor *output)
+{
+ _impl->src = input;
+ _impl->dst = output;
+ _impl->op = arm_compute::support::cpp14::make_unique<experimental::NEReshapeLayer>();
+ _impl->op->configure(input->info(), output->info());
}
Status NEReshapeLayer::validate(const ITensorInfo *input, const ITensorInfo *output)
{
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
- ARM_COMPUTE_RETURN_ON_ERROR(NEReshapeLayerKernel::validate(input, output));
+ ARM_COMPUTE_RETURN_ON_ERROR(experimental::NEReshapeLayer::validate(input, output));
return Status{};
}
void NEReshapeLayer::run()
{
- InputOperatorTensors src_0 = std::make_pair(TensorType::ACL_SRC, _input);
- OutputOperatorTensors dst_0 = std::make_pair(TensorType::ACL_DST, _output);
-
- std::vector<InputOperatorTensors *> inputs = { &src_0 };
- std::vector<OutputOperatorTensors *> outputs = { &dst_0 };
-
- NEScheduler::get().schedule_op(_kernel.get(), Window::DimY, inputs, outputs);
+ const InputTensor src{ TensorType::ACL_SRC, _impl->src };
+ OutputTensor dst{ TensorType::ACL_DST, _impl->dst };
+ _impl->op->run({ src }, { dst }, {});
}
} // namespace arm_compute