multi_devices_helper.h 2.0 KB
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//   Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
//
// 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

Y
Yu Yang 已提交
17 18
#include <memory>
#include <string>
X
Xin Pan 已提交
19
#include <vector>
Y
Yu Yang 已提交
20

X
clean  
Xin Pan 已提交
21 22 23
#include "paddle/fluid/framework/details/op_handle_base.h"
#include "paddle/fluid/framework/details/var_handle.h"

Y
Yu Yang 已提交
24 25 26
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/platform/place.h"

X
Xin Pan 已提交
27
#include "paddle/fluid/framework/ir/graph.h"
28
#include "paddle/fluid/framework/ir/pass.h"
X
Xin Pan 已提交
29

Y
Yu Yang 已提交
30 31 32 33
namespace paddle {
namespace framework {
namespace details {

X
clean  
Xin Pan 已提交
34 35 36 37 38
// all variable in each devices.
// The outside vector is the device vector. Each element of this vector is a
// map from variable name to variables. The variables, who have the same name,
// will have a differsent version. The offset in the
// `std::vector<std::unique_ptr<VarHandle>>` is the version of varaibles.
X
Xin Pan 已提交
39 40 41
typedef std::vector<
    std::unordered_map<std::string, std::vector<std::unique_ptr<VarHandle>>>>
    GraphVars;
X
Xin Pan 已提交
42
const char kGraphVars[] = "vars";
X
clean  
Xin Pan 已提交
43 44

// aux variables to represent dependency. Useful to resolve data hazard.
X
Xin Pan 已提交
45
typedef std::unordered_set<std::unique_ptr<VarHandleBase>> GraphDepVars;
X
Xin Pan 已提交
46
const char kGraphDepVars[] = "dep_vars";
X
clean  
Xin Pan 已提交
47 48 49

// all operators. NOTE that even we use a vector here, the operators is
// unordered.
X
Xin Pan 已提交
50
typedef std::vector<std::unique_ptr<OpHandleBase>> GraphOps;
X
Xin Pan 已提交
51
const char kGraphOps[] = "ops";
X
Xin Pan 已提交
52

X
Xin Pan 已提交
53
typedef std::unordered_map<std::string, int> ShardedVarDevice;
X
Xin Pan 已提交
54
const char kShardedVarDevice[] = "sharded_var_device";
Y
Yu Yang 已提交
55 56 57
}  // namespace details
}  // namespace framework
}  // namespace paddle