/
gloo_operations.h
137 lines (100 loc) · 4.34 KB
/
gloo_operations.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2019 Uber Technologies, Inc. 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.
// =============================================================================
#ifndef HOROVOD_GLOO_OPERATIONS_H
#define HOROVOD_GLOO_OPERATIONS_H
#include <stdint.h>
#include <vector>
#include "collective_operations.h"
#include "../gloo/gloo_context.h"
namespace horovod {
namespace common {
class IGlooAlgorithms {
public:
virtual void Allreduce(void* buffer_data, int num_elements) = 0;
virtual void Allgather(void* buffer_data, void* buffer_out, int* recvcounts,
int* displcmnts) = 0;
virtual void Broadcast(void* buffer_data, int num_elements,
int root_rank) = 0;
virtual void Alltoall(void* buffer_data, void* buffer_out,
std::vector<int64_t>& sendcounts,
std::vector<int64_t>& recvcounts) = 0;
virtual void Reducescatter(void* buffer_data,
std::vector<int>& recvcounts) = 0;
virtual int ElementSize() const = 0;
virtual ~IGlooAlgorithms() = default;
};
template <typename T> class GlooAlgorithms : public IGlooAlgorithms {
public:
explicit GlooAlgorithms(GlooContext* gloo_context);
void Allreduce(void* buffer_data, int num_elements) override;
void Allgather(void* buffer_data, void* buffer_out, int* recvcounts,
int* displcmnts) override;
void Broadcast(void* buffer_data, int num_elements, int root_rank) override;
void Alltoall(void* buffer_data, void* buffer_out,
std::vector<int64_t>& sendcounts,
std::vector<int64_t>& recvcounts) override;
void Reducescatter(void* buffer_data, std::vector<int>& recvcounts) override;
int ElementSize() const override;
private:
GlooContext* gloo_context_;
};
class GlooAllreduce : public AllreduceOp {
public:
explicit GlooAllreduce(HorovodGlobalState* global_state);
Status Execute(std::vector<TensorTableEntry>& entries,
const Response& response) override;
bool Enabled(const ParameterManager& param_manager,
const std::vector<TensorTableEntry>& entries,
const Response& response) const override;
};
class GlooAllgather : public AllgatherOp {
public:
explicit GlooAllgather(HorovodGlobalState* global_state);
Status Execute(std::vector<TensorTableEntry>& entries,
const Response& response) override;
bool Enabled(const ParameterManager& param_manager,
const std::vector<TensorTableEntry>& entries,
const Response& response) const override;
};
class GlooBroadcast : public BroadcastOp {
public:
explicit GlooBroadcast(HorovodGlobalState* global_state);
Status Execute(std::vector<TensorTableEntry>& entries,
const Response& response) override;
bool Enabled(const ParameterManager& param_manager,
const std::vector<TensorTableEntry>& entries,
const Response& response) const override;
};
class GlooAlltoall : public AlltoallOp {
public:
explicit GlooAlltoall(HorovodGlobalState* global_state);
Status Execute(std::vector<TensorTableEntry>& entries,
const Response& response) override;
bool Enabled(const ParameterManager& param_manager,
const std::vector<TensorTableEntry>& entries,
const Response& response) const override;
};
class GlooReducescatter : public ReducescatterOp {
public:
explicit GlooReducescatter(HorovodGlobalState* global_state);
Status Execute(std::vector<TensorTableEntry>& entries,
const Response& response) override;
bool Enabled(const ParameterManager& param_manager,
const std::vector<TensorTableEntry>& entries,
const Response& response) const override;
};
} // namespace common
} // namespace horovod
#endif // HOROVOD_GLOO_OPERATIONS_H