type_defs.h 2.5 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
2

L
Luo Tao 已提交
3 4 5
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
6

L
Luo Tao 已提交
7
    http://www.apache.org/licenses/LICENSE-2.0
8

L
Luo Tao 已提交
9 10 11 12 13
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. */
14 15 16 17

#pragma once
#include <functional>
#include <map>
18
#include <memory>
Y
Yu Yang 已提交
19 20 21 22
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Y
Yi Wang 已提交
23
#include "paddle/fluid/platform/variant.h"
24 25 26 27

namespace paddle {
namespace framework {
class OperatorBase;
Y
Yu Yang 已提交
28
class OpDesc;
29
class InferShapeContext;
M
minqiyang 已提交
30
class InferVarTypeContext;
Y
Yu Yang 已提交
31
class BlockDesc;
X
Xin Pan 已提交
32
class Variable;
S
sneaxiy 已提交
33
class NoNeedBufferVarsInference;
34

35
using VariableNameMap = std::map<std::string, std::vector<std::string>>;
X
Xin Pan 已提交
36 37
// TODO(panyx0718): Replace vector with something like gtl::Vector.
using VariableValueMap = std::map<std::string, std::vector<Variable*>>;
38 39 40

// The order should be as same as framework.proto
using Attribute =
41 42 43 44
    boost::variant<boost::blank, int, float, std::string, std::vector<int>,
                   std::vector<float>, std::vector<std::string>, bool,
                   std::vector<bool>, BlockDesc*, int64_t,
                   std::vector<BlockDesc*>, std::vector<int64_t>>;
45 46 47 48 49 50 51

using AttributeMap = std::unordered_map<std::string, Attribute>;

using OpCreator = std::function<OperatorBase*(
    const std::string& /*type*/, const VariableNameMap& /*inputs*/,
    const VariableNameMap& /*outputs*/, const AttributeMap& /*attrs*/)>;

Y
Yu Yang 已提交
52 53
using GradOpMakerFN = std::function<std::vector<std::unique_ptr<OpDesc>>(
    const OpDesc&, const std::unordered_set<std::string>& /*no_grad_set*/,
Y
Yu Yang 已提交
54
    std::unordered_map<std::string, std::string>* /*grad_to_var*/,
Y
Yu Yang 已提交
55
    const std::vector<BlockDesc*>& grad_block)>;
Y
Yu Yang 已提交
56

Y
Yu Yang 已提交
57
using InferVarTypeFN =
M
minqiyang 已提交
58
    std::function<void(framework::InferVarTypeContext* /*context*/)>;
Y
Yu Yang 已提交
59

60 61
using InferShapeFN = std::function<void(InferShapeContext*)>;

D
dzhwinter 已提交
62 63 64
using InplacePair = std::unordered_map<std::string, std::string>;
using InferInplaceOpFN = std::function<InplacePair(const OpDesc&, BlockDesc*)>;

S
sneaxiy 已提交
65 66 67 68
using InferNoNeedBufferVarsFN = std::function<std::unordered_set<std::string>(
    const VariableNameMap& /*inputs*/, const VariableNameMap& /*outputs*/,
    const AttributeMap& /*attrs*/)>;

69 70
}  // namespace framework
}  // namespace paddle