type_defs.h 2.0 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;
Y
Yu Yang 已提交
30
class BlockDesc;
31

32 33 34 35
using VariableNameMap = std::map<std::string, std::vector<std::string>>;

// The order should be as same as framework.proto
using Attribute =
36 37 38 39
    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>>;
40 41 42 43 44 45 46

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 已提交
47 48
using GradOpMakerFN = std::function<std::vector<std::unique_ptr<OpDesc>>(
    const OpDesc&, const std::unordered_set<std::string>& /*no_grad_set*/,
Y
Yu Yang 已提交
49
    std::unordered_map<std::string, std::string>* /*grad_to_var*/,
Y
Yu Yang 已提交
50
    const std::vector<BlockDesc*>& grad_block)>;
Y
Yu Yang 已提交
51

Y
Yu Yang 已提交
52 53
using InferVarTypeFN =
    std::function<void(const OpDesc& /*op_desc*/, BlockDesc* /*block*/)>;
Y
Yu Yang 已提交
54

55 56
using InferShapeFN = std::function<void(InferShapeContext*)>;

57 58
}  // namespace framework
}  // namespace paddle