Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef HCCLV2_OPBASE_STREAM_MANAGER_H
11 : #define HCCLV2_OPBASE_STREAM_MANAGER_H
12 :
13 : #include <vector>
14 : #include <memory>
15 : #include <unordered_map>
16 : #include "hccl/base.h"
17 : #include "stream/stream.h"
18 :
19 : namespace Hccl {
20 : class CommunicatorImpl;
21 :
22 : class OpbaseStreamManager {
23 : public:
24 465 : explicit OpbaseStreamManager(CommunicatorImpl* comm) : comm(comm)
25 : {
26 465 : CHECK_NULLPTR(comm, "[OpbaseStreamManager]comm is nullptr!");
27 465 : }
28 : ~OpbaseStreamManager();
29 :
30 : void RegisterMaster(std::unique_ptr<Stream> stream);
31 :
32 : void Clear();
33 :
34 37 : Stream* GetMaster() const { return master.get(); }
35 :
36 : Stream* GetOrCreateSlave();
37 :
38 11 : void ResetIndex(u32 index) { slaveIndex = index; }
39 :
40 5 : u32 GetSlaveIndex() const { return slaveIndex; }
41 :
42 : Stream* GetSlave(u32 index) const;
43 :
44 : private:
45 : void ReplaceMaster(std::unique_ptr<Stream> stream);
46 :
47 : CommunicatorImpl* comm{nullptr};
48 : std::unique_ptr<Stream> master{nullptr};
49 : std::vector<std::unique_ptr<Stream>> slaves;
50 : u32 slaveIndex{0};
51 : };
52 :
53 : } // namespace Hccl
54 :
55 : #endif // HCCLV2_OPBASE_STREAM_MANAGER_H
|