|
| 1 | +/* Copyright (c) 2018 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 | +#include "paddle/fluid/inference/analysis/node.h" |
| 16 | +#include "glog/logging.h" |
| 17 | +#include "paddle/fluid/platform/enforce.h" |
| 18 | + |
| 19 | +namespace paddle { |
| 20 | +namespace inference { |
| 21 | +namespace analysis { |
| 22 | + |
| 23 | +std::vector<Dot::Attr> Value::dot_attrs() const { |
| 24 | + return std::vector<Dot::Attr>({Dot::Attr("style", "filled,rounded"), |
| 25 | + Dot::Attr("shape", "box"), |
| 26 | + Dot::Attr("fillcolor", "red")}); |
| 27 | +} |
| 28 | + |
| 29 | +std::vector<Dot::Attr> Function::dot_attrs() const { |
| 30 | + return std::vector<Dot::Attr>({Dot::Attr("style", "filled,rounded"), |
| 31 | + Dot::Attr("shape", "diamond"), |
| 32 | + Dot::Attr("fillcolor", "yellow")}); |
| 33 | +} |
| 34 | + |
| 35 | +Node *NodeMap::Create(Node::Type type) { |
| 36 | + switch (type) { |
| 37 | + case Node::Type::kFunction: |
| 38 | + nodes_.emplace_back(new Function); |
| 39 | + break; |
| 40 | + case Node::Type::kValue: |
| 41 | + nodes_.emplace_back(new Value); |
| 42 | + break; |
| 43 | + default: |
| 44 | + PADDLE_THROW("Not supported node type."); |
| 45 | + } |
| 46 | + nodes_.back()->id_ = size() - 1; |
| 47 | + return nodes_.back().get(); |
| 48 | +} |
| 49 | + |
| 50 | +Node *NodeMap::GetMutable(size_t id) { |
| 51 | + PADDLE_ENFORCE_GT(size(), id); |
| 52 | + return nodes_[id].get(); |
| 53 | +} |
| 54 | + |
| 55 | +const Node &NodeMap::Get(size_t id) const { |
| 56 | + PADDLE_ENFORCE_GT(size(), id); |
| 57 | + return *nodes_[id].get(); |
| 58 | +} |
| 59 | + |
| 60 | +void NodeMap::Delete(size_t id) { |
| 61 | + PADDLE_ENFORCE_LT(id, size()); |
| 62 | + nodes_[id]->SetDeleted(); |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace analysis |
| 66 | +} // namespace inference |
| 67 | +} // namespace paddle |
0 commit comments