|
| 1 | +/*Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. */ |
| 14 | + |
| 15 | +#pragma once |
| 16 | + |
| 17 | +#include <memory> |
| 18 | +#include <string> |
| 19 | +#include <unordered_map> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "ngraph/ngraph.hpp" |
| 23 | +#include "paddle/fluid/operators/ngraph/ops/elementwise_node.h" |
| 24 | +#include "paddle/fluid/platform/ngraph_helper.h" |
| 25 | + |
| 26 | +namespace paddle { |
| 27 | +namespace operators { |
| 28 | +namespace ngraphs { |
| 29 | + |
| 30 | +void BuildIncrementNode( |
| 31 | + const std::shared_ptr<paddle::framework::OperatorBase>& op, |
| 32 | + std::shared_ptr< |
| 33 | + std::unordered_map<std::string, std::shared_ptr<ngraph::Node>>> |
| 34 | + ngb_node_map) { |
| 35 | + auto x = paddle::platform::GetInputNode(op, "X", ngb_node_map); |
| 36 | + auto op_attrs = paddle::framework::AttrReader(op->Attrs()); |
| 37 | + float step = op_attrs.Get<float>("step"); |
| 38 | + auto step_op = std::make_shared<ngraph::op::Constant>( |
| 39 | + x->get_element_type(), x->get_shape(), std::vector<float>{step}); |
| 40 | + std::shared_ptr<ngraph::Node> out = |
| 41 | + std::make_shared<ngraph::op::Add>(x, step_op); |
| 42 | + paddle::platform::SetOutputNode(op, "Out", out, ngb_node_map); |
| 43 | +} |
| 44 | + |
| 45 | +} // namespace ngraphs |
| 46 | +} // namespace operators |
| 47 | +} // namespace paddle |
| 48 | + |
| 49 | +REGISTER_NG_OP(increment, BuildIncrementNode); |
0 commit comments