From e4ab40a7b9940e84d26ec9ffb777b290899a5aae Mon Sep 17 00:00:00 2001 From: baojun-nervana Date: Tue, 26 Feb 2019 19:55:44 +0000 Subject: [PATCH] added concat op test=develop --- paddle/fluid/operators/ngraph/ops/concat_op.h | 50 +++++++++++++++++++ .../unittests/ngraph/test_concat_ngraph_op.py | 21 ++++++++ 2 files changed, 71 insertions(+) create mode 100644 paddle/fluid/operators/ngraph/ops/concat_op.h create mode 100644 python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py diff --git a/paddle/fluid/operators/ngraph/ops/concat_op.h b/paddle/fluid/operators/ngraph/ops/concat_op.h new file mode 100644 index 0000000000..27d7968515 --- /dev/null +++ b/paddle/fluid/operators/ngraph/ops/concat_op.h @@ -0,0 +1,50 @@ +/*Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#pragma once + +#include +#include +#include +#include +#include "ngraph/ngraph.hpp" +#include "paddle/fluid/operators/ngraph/ops/op_bridge.h" +#include "paddle/fluid/platform/ngraph_helper.h" + +namespace paddle { +namespace operators { +namespace ngraphs { + +void BuildConcatNode( + const std::shared_ptr& op, + std::shared_ptr< + std::unordered_map>> + ngb_node_map) { + std::vector> args; + for (auto& var_name_item : op->Inputs()) { + for (auto& var_name : var_name_item.second) { + auto& node0 = ngb_node_map->at(var_name); + args.push_back(node0); + } + } + auto op_attrs = framework::AttrReader(op->Attrs()); + const size_t axis = op_attrs.Get("axis"); + auto out = std::make_shared(args, axis); + platform::SetOutputNode(op, "Out", out, ngb_node_map); +} +} // namespace ngraphs +} // namespace operators +} // namespace paddle + +REGISTER_NG_OP(concat, BuildConcatNode); diff --git a/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py b/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py new file mode 100644 index 0000000000..a223d73a74 --- /dev/null +++ b/python/paddle/fluid/tests/unittests/ngraph/test_concat_ngraph_op.py @@ -0,0 +1,21 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +import unittest +from paddle.fluid.tests.unittests.test_concat_op import TestConcatOp, TestConcatOp2, TestConcatOp3 + +if __name__ == '__main__': + unittest.main() -- GitLab