nccl_gpu_common.h 1.3 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
D
Dong Zhihong 已提交
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
D
Dong Zhihong 已提交
6

L
Luo Tao 已提交
7
    http://www.apache.org/licenses/LICENSE-2.0
D
Dong Zhihong 已提交
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. */
D
Dong Zhihong 已提交
14

D
dongzhihong 已提交
15 16
#pragma once

D
Dong Zhihong 已提交
17
#include <algorithm>
18
#include <condition_variable>  // NOLINT
D
dzhwinter 已提交
19
#include <memory>
20
#include <mutex>  // NOLINT
D
Dong Zhihong 已提交
21
#include <string>
D
dzhwinter 已提交
22
#include <unordered_map>
D
Dong Zhihong 已提交
23
#include <vector>
D
dzhwinter 已提交
24

Y
Yi Wang 已提交
25
#include "paddle/fluid/platform/device_context.h"
26 27 28
#ifdef PADDLE_WITH_RCCL
#include "paddle/fluid/platform/dynload/rccl.h"
#else
Y
Yi Wang 已提交
29
#include "paddle/fluid/platform/dynload/nccl.h"
30
#endif
Y
Yi Wang 已提交
31 32
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/macros.h"
D
dongzhihong 已提交
33 34 35

namespace paddle {
namespace platform {
D
Dong Zhihong 已提交
36 37
constexpr int kInvalidGPUId = -1;

D
Dong Zhihong 已提交
38
struct Communicator {
D
fix ci  
Dong Zhihong 已提交
39 40
  Communicator() {}

X
Xin Pan 已提交
41
  int GetCommId(int device_id) const;
D
Dong Zhihong 已提交
42

X
Xin Pan 已提交
43
  void InitAll(const std::vector<int>& gpus);
D
Dong Zhihong 已提交
44

X
Xin Pan 已提交
45
  const std::vector<ncclComm_t>& comms() const;
D
Dong Zhihong 已提交
46
};
D
dzhwinter 已提交
47

D
Dong Zhihong 已提交
48
}  // namespace platform
D
dzhwinter 已提交
49
}  // namespace paddle