You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Paddle/paddle/fluid/framework/ir/node.h

77 lines
1.9 KiB

7 years ago
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
7 years ago
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
7 years ago
#include <string>
#include <vector>
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/var_desc.h"
7 years ago
#include "paddle/fluid/platform/macros.h"
7 years ago
namespace paddle {
7 years ago
namespace framework {
7 years ago
namespace ir {
7 years ago
class Node {
public:
7 years ago
enum class Type { kOperation, kVariable };
7 years ago
static const char kControlDepVarName[];
7 years ago
explicit Node(const std::string& name, Type type)
: name_(name), var_desc_(nullptr), op_desc_(nullptr), type_(type) {}
7 years ago
7 years ago
explicit Node(VarDesc* var_desc)
: name_(var_desc->Name()),
var_desc_(var_desc),
op_desc_(nullptr),
type_(Type::kVariable) {}
7 years ago
7 years ago
explicit Node(OpDesc* op_desc)
: name_(op_desc->Type()),
var_desc_(nullptr),
op_desc_(op_desc),
type_(Type::kOperation) {}
7 years ago
Type NodeType() const { return type_; }
7 years ago
std::string Name() const { return name_; }
7 years ago
7 years ago
VarDesc* Var() {
PADDLE_ENFORCE(type_ == Type::kVariable);
return var_desc_;
}
7 years ago
OpDesc* Op() {
PADDLE_ENFORCE(type_ == Type::kOperation);
return op_desc_;
7 years ago
}
std::vector<Node*> inputs;
std::vector<Node*> outputs;
7 years ago
protected:
7 years ago
const std::string name_;
VarDesc* var_desc_;
OpDesc* op_desc_;
7 years ago
Type type_;
7 years ago
private:
7 years ago
DISABLE_COPY_AND_ASSIGN(Node);
};
7 years ago
} // namespace ir
7 years ago
} // namespace framework
7 years ago
} // namespace paddle