1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. |
---|---|
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_RING_REDUCER_H_ |
16 | #define TENSORFLOW_CORE_COMMON_RUNTIME_RING_REDUCER_H_ |
17 | |
18 | #include <deque> |
19 | #include <memory> |
20 | #include <string> |
21 | #include <vector> |
22 | |
23 | #include "tensorflow/core/common_runtime/base_collective_executor.h" |
24 | #include "tensorflow/core/common_runtime/ring_alg.h" |
25 | #include "tensorflow/core/framework/collective.h" |
26 | |
27 | namespace tensorflow { |
28 | class Device; |
29 | |
30 | // Ring-algorithm implementation of collective all-reduce. |
31 | class RingReducer : public RingAlg { |
32 | public: |
33 | RingReducer() : RingAlg(REDUCTION_COLLECTIVE, "Reduce") {} |
34 | ~RingReducer() override; |
35 | |
36 | // Begins async execution of the ring reduce algorithm. |
37 | // Must be called in a blockable thread. |
38 | // TODO(b/80529858): remove the previous warning when we have a dedicated |
39 | // collective threadpool. |
40 | void Run(StatusCallback done) override; |
41 | |
42 | Status InitializeCollectiveParams(CollectiveParams* col_params) override; |
43 | |
44 | protected: |
45 | void InitRingField(RingField* rf, int chunk_idx, int subdiv_idx, |
46 | int field_idx) override; |
47 | |
48 | private: |
49 | void ContinueAfterInputCopy(); |
50 | bool RunAsyncParts(); |
51 | |
52 | Tensor group_size_tensor_; |
53 | Notification group_size_tensor_ready_; |
54 | |
55 | friend class RingReducerTest; |
56 | friend class RingReducerInitParamsTest; |
57 | }; |
58 | |
59 | } // namespace tensorflow |
60 | #endif // TENSORFLOW_CORE_COMMON_RUNTIME_RING_REDUCER_H_ |
61 |