aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2017-11-24 09:54:20 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:41:04 +0000
commit7bfe4c52823b3fad82339e5a686aa94e30d57e7b (patch)
tree619a7f096bb27f4b00059254024526dd233343e0 /src
parentf3dfa279d536906dac3e618244b2c1d33e5ff28a (diff)
downloadComputeLibrary-7bfe4c52823b3fad82339e5a686aa94e30d57e7b.tar.gz
COMPMID-554 Add Nodes
- DepthwiseConvolutionLayer Change-Id: Icaef85d7474f7532bf7d93d11b5c787712e57bdd Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/110524 Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'src')
-rw-r--r--src/graph/nodes/DepthwiseConvolutionLayer.cpp84
-rw-r--r--src/graph/operations/CLSimpleOperations.cpp50
-rw-r--r--src/graph/operations/NESimpleOperations.cpp50
3 files changed, 184 insertions, 0 deletions
diff --git a/src/graph/nodes/DepthwiseConvolutionLayer.cpp b/src/graph/nodes/DepthwiseConvolutionLayer.cpp
new file mode 100644
index 0000000000..1c006d61db
--- /dev/null
+++ b/src/graph/nodes/DepthwiseConvolutionLayer.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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 "arm_compute/graph/nodes/DepthwiseConvolutionLayer.h"
+
+#include "arm_compute/graph/Error.h"
+#include "arm_compute/graph/NodeContext.h"
+#include "arm_compute/graph/OperationRegistry.h"
+#include "support/ToolchainSupport.h"
+
+using namespace arm_compute::graph;
+
+std::unique_ptr<arm_compute::IFunction> DepthwiseConvolutionLayer::instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output)
+{
+ ARM_COMPUTE_ERROR_ON_UNALLOCATED_TENSOR_OBJECT(input, output);
+
+ arm_compute::ITensor *in = input->tensor();
+ arm_compute::ITensor *out = output->tensor();
+ _target_hint = ctx.hints().target_hint();
+
+ if(_weights.tensor() == nullptr)
+ {
+ TensorShape shape = in->info()->tensor_shape();
+ shape.set(Window::DimX, _conv_width);
+ shape.set(Window::DimY, _conv_height);
+ _weights.set_info(TensorInfo(TensorShape(shape), in->info()->num_channels(), in->info()->data_type(), in->info()->fixed_point_position()));
+ }
+ if(_biases.has_accessor() && _biases.tensor() == nullptr)
+ {
+ _biases.set_info(TensorInfo(TensorShape(in->info()->dimension(2)), in->info()->num_channels(), in->info()->data_type(), in->info()->fixed_point_position()));
+ }
+
+ bool weights_is_loaded = _weights.tensor() != nullptr;
+ bool biases_is_loaded = _biases.has_accessor() ? _biases.tensor() != nullptr : false;
+
+ _weights.set_target(_target_hint);
+ _biases.set_target(_target_hint);
+
+ // Create node context
+ NodeContext node_ctx(OperationType::DepthwiseConvolutionLayer);
+ node_ctx.set_target(_target_hint);
+ node_ctx.add_input(in);
+ node_ctx.add_input(_weights.tensor());
+ if(_biases.has_accessor())
+ {
+ node_ctx.add_input(_biases.tensor());
+ }
+ node_ctx.add_output(out);
+ node_ctx.add_parameter<PadStrideInfo>("ConvolutionInfo", _conv_info);
+ node_ctx.add_parameter<bool>("Optimized3x3", _opt3x3);
+
+ // Fill tensors
+ if(!weights_is_loaded)
+ {
+ _weights.allocate_and_fill_if_needed();
+ }
+ if(!biases_is_loaded)
+ {
+ _biases.allocate_and_fill_if_needed();
+ }
+
+ // Get function
+ return OperationRegistry::get().find_operation(OperationType::DepthwiseConvolutionLayer, _target_hint)->configure(node_ctx);
+}
diff --git a/src/graph/operations/CLSimpleOperations.cpp b/src/graph/operations/CLSimpleOperations.cpp
index 4ec3a22f37..881f4910ad 100644
--- a/src/graph/operations/CLSimpleOperations.cpp
+++ b/src/graph/operations/CLSimpleOperations.cpp
@@ -135,6 +135,56 @@ REGISTER_SIMPLE_OPERATION(CLDepthConvertLayerOperation, OPENCL, OperationType::D
return std::move(depthconvert);
}
+/* DepthwiseConvolutionLayer Layer */
+REGISTER_SIMPLE_OPERATION(CLDepthwiseConvolutionOperation, OPENCL, OperationType::DepthwiseConvolutionLayer)
+{
+ ARM_COMPUTE_ERROR_ON(ctx.num_inputs() != 2 || ctx.num_inputs() != 3);
+ ARM_COMPUTE_ERROR_ON(ctx.num_outputs() != 1);
+ ARM_COMPUTE_ERROR_ON(dynamic_cast<arm_compute::ICLTensor *>(ctx.input(0)) == nullptr);
+ ARM_COMPUTE_ERROR_ON(dynamic_cast<arm_compute::ICLTensor *>(ctx.output(0)) == nullptr);
+
+ // Extract IO and info
+ auto *in = dynamic_cast<arm_compute::ICLTensor *>(ctx.input(0));
+ auto *weights = dynamic_cast<arm_compute::ICLTensor *>(ctx.input(1));
+ auto *biases = ctx.num_inputs() == 3 ? dynamic_cast<arm_compute::ICLTensor *>(ctx.input(2)) : nullptr;
+ auto *out = dynamic_cast<arm_compute::ICLTensor *>(ctx.output(0));
+ const auto conv_info = ctx.parameter<PadStrideInfo>("ConvolutionInfo");
+ const auto opt3x3 = ctx.parameter<bool>("Optimized3x3");
+
+ // Create and configure function
+ std::unique_ptr<arm_compute::IFunction> func;
+ bool run_3x3_opt = opt3x3 && weights->info()->dimension(0) == 3;
+ if(run_3x3_opt)
+ {
+ auto depwthwise_conv = arm_compute::support::cpp14::make_unique<arm_compute::CLDepthwiseConvolution>();
+ depwthwise_conv->configure(in, weights, biases, out, conv_info);
+ func = std::move(depwthwise_conv);
+ }
+ else
+ {
+ auto depwthwise_conv = arm_compute::support::cpp14::make_unique<arm_compute::CLDepthwiseConvolution3x3>();
+ depwthwise_conv->configure(in, weights, biases, out, conv_info);
+ func = std::move(depwthwise_conv);
+ }
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiating CLDepthwiseConvolutionLayer"
+ << " Data Type: " << in->info()->data_type()
+ << " Input shape: " << in->info()->tensor_shape()
+ << " Weights shape: " << weights->info()->tensor_shape()
+ << " Output shape: " << out->info()->tensor_shape());
+ if(biases == nullptr)
+ {
+ ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: No biases provided" << std::endl);
+ }
+ else
+ {
+ ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: " << biases->info()->tensor_shape() << std::endl);
+ }
+
+ return func;
+}
+
/* DeQuantizationLayer Layer */
REGISTER_SIMPLE_OPERATION(CLDequantizationLayerOperation, OPENCL, OperationType::DequantizationLayer)
{
diff --git a/src/graph/operations/NESimpleOperations.cpp b/src/graph/operations/NESimpleOperations.cpp
index 12f8c6c76b..c77aeeca11 100644
--- a/src/graph/operations/NESimpleOperations.cpp
+++ b/src/graph/operations/NESimpleOperations.cpp
@@ -135,6 +135,56 @@ REGISTER_SIMPLE_OPERATION(NEDepthConvertLayerOperation, NEON, OperationType::Dep
return std::move(depthconvert);
}
+/* DepthwiseConvolutionLayer Layer */
+REGISTER_SIMPLE_OPERATION(NEDepthwiseConvolutionOperation, NEON, OperationType::DepthwiseConvolutionLayer)
+{
+ ARM_COMPUTE_ERROR_ON(ctx.num_inputs() != 2 || ctx.num_inputs() != 3);
+ ARM_COMPUTE_ERROR_ON(ctx.num_outputs() != 1);
+ ARM_COMPUTE_ERROR_ON(dynamic_cast<arm_compute::ITensor *>(ctx.input(0)) == nullptr);
+ ARM_COMPUTE_ERROR_ON(dynamic_cast<arm_compute::ITensor *>(ctx.output(0)) == nullptr);
+
+ // Extract IO and info
+ auto *in = dynamic_cast<arm_compute::ITensor *>(ctx.input(0));
+ auto *weights = dynamic_cast<arm_compute::ITensor *>(ctx.input(1));
+ auto *biases = ctx.num_inputs() == 3 ? dynamic_cast<arm_compute::ITensor *>(ctx.input(2)) : nullptr;
+ auto *out = dynamic_cast<arm_compute::ITensor *>(ctx.output(0));
+ const auto conv_info = ctx.parameter<PadStrideInfo>("ConvolutionInfo");
+ const auto opt3x3 = ctx.parameter<bool>("Optimized3x3");
+
+ // Create and configure function
+ std::unique_ptr<arm_compute::IFunction> func;
+ bool run_3x3_opt = opt3x3 && weights->info()->dimension(0) == 3;
+ if(run_3x3_opt)
+ {
+ auto depwthwise_conv = arm_compute::support::cpp14::make_unique<arm_compute::NEDepthwiseConvolution>();
+ depwthwise_conv->configure(in, weights, biases, out, conv_info);
+ func = std::move(depwthwise_conv);
+ }
+ else
+ {
+ auto depwthwise_conv = arm_compute::support::cpp14::make_unique<arm_compute::NEDepthwiseConvolution3x3>();
+ depwthwise_conv->configure(in, weights, biases, out, conv_info);
+ func = std::move(depwthwise_conv);
+ }
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiating NEDepthwiseConvolutionLayer"
+ << " Data Type: " << in->info()->data_type()
+ << " Input shape: " << in->info()->tensor_shape()
+ << " Weights shape: " << weights->info()->tensor_shape()
+ << " Output shape: " << out->info()->tensor_shape());
+ if(biases == nullptr)
+ {
+ ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: No biases provided" << std::endl);
+ }
+ else
+ {
+ ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: " << biases->info()->tensor_shape() << std::endl);
+ }
+
+ return func;
+}
+
/* DeQuantizationLayer Layer */
REGISTER_SIMPLE_OPERATION(NEDequantizationLayerOperation, NEON, OperationType::DequantizationLayer)
{