From 8d22b7efee913bb15a75af777aa69ac507159d32 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ivan=20Vagin/AI=20Tools=20Lab=20/SRR/Engineer/=EC=82=BC?= =?utf8?q?=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Fri, 25 Jan 2019 17:15:40 +0300 Subject: [PATCH] [nnc] Implemented PadOp in ACL backend (#2925) Implemented ACL backend pad operation. Signed-off-by: Ivan Vagin --- .../passes/acl_soft_backend/AclCppOpGenerator.cpp | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/contrib/nnc/passes/acl_soft_backend/AclCppOpGenerator.cpp b/contrib/nnc/passes/acl_soft_backend/AclCppOpGenerator.cpp index b493697..edb2733 100644 --- a/contrib/nnc/passes/acl_soft_backend/AclCppOpGenerator.cpp +++ b/contrib/nnc/passes/acl_soft_backend/AclCppOpGenerator.cpp @@ -36,6 +36,7 @@ #include "core/modelIR/operations/GemmOp.h" #include "core/modelIR/operations/InputOp.h" #include "core/modelIR/operations/LeakyReluOp.h" +#include "core/modelIR/operations/PadOp.h" #include "core/modelIR/operations/PoolOp.h" #include "core/modelIR/operations/ReduceFOp.h" #include "core/modelIR/operations/ReluOp.h" @@ -710,8 +711,32 @@ void AclCppOpGenerator::visit(ops::EluOp&) { throw AclCppException("EluOp not supported by the ACL library yet."); } -void AclCppOpGenerator::visit(ops::PadOp&) { - throw AclCppException("PadOp not supported by the ACL library yet."); +void AclCppOpGenerator::visit(ops::PadOp& op) { + // Get the id of the input tensor. + auto in_op = op.getPrevNodes()[0].op; + auto input = AF::id(tensorName(in_op)); + + // Create the output tensor in the DOM + auto out = genTensor(op, op.getOutputShape(0)); + addToPersistentTensors(out); + + // Generate PadLayer params + auto prefix = out->name() + "_pad_layer"; + auto pad_list_decl = _constrBlock->var("arm_compute::PaddingList", prefix + "_pads"); + auto pad_list = pad_list_decl->use(); + for (int i = 0; i < op.getNumDim(); ++i) { + auto pad_var = _constrBlock->var("arm_compute::PaddingInfo", prefix + "_pad_" + to_string(i), + {}, + {AF::lit(to_string(op.getPaddingForDim(i).first)), + AF::lit(to_string(op.getPaddingForDim(i).second))}); + auto pad = pad_var->use(); + _constrBlock->call("push_back", {pad}, pad_list); + } + + // Generate PadLayer + auto layer = genLayer("arm_compute::CLPadLayer", prefix, + {AF::ref(input), AF::ref(out), pad_list}); + genLayerExecution(layer); } template -- 2.7.4