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 :
11 : #ifndef HCCLV2_OPBASE_STREAM_MANAGER_H
12 : #define HCCLV2_OPBASE_STREAM_MANAGER_H
13 :
14 : #include <vector>
15 : #include <memory>
16 : #include <unordered_map>
17 : #include "hccl/base.h"
18 : #include "stream/stream.h"
19 :
20 : namespace Hccl {
21 : class CommunicatorImpl;
22 :
23 : class OpbaseStreamManager {
24 : public:
25 465 : explicit OpbaseStreamManager(CommunicatorImpl* comm) : comm(comm)
26 : {
27 465 : CHECK_NULLPTR(comm, "[OpbaseStreamManager]comm is nullptr!");
28 465 : }
29 : ~OpbaseStreamManager();
30 :
31 : void RegisterMaster(std::unique_ptr<Stream> stream);
32 :
33 : void Clear();
34 :
35 37 : Stream* GetMaster() const { return master.get(); }
36 :
37 : Stream* GetOrCreateSlave();
38 :
39 11 : void ResetIndex(u32 index) { slaveIndex = index; }
40 :
41 5 : u32 GetSlaveIndex() const { return slaveIndex; }
42 :
43 : Stream* GetSlave(u32 index) const;
44 :
45 : private:
46 : void ReplaceMaster(std::unique_ptr<Stream> stream);
47 :
48 : CommunicatorImpl* comm{nullptr};
49 : std::unique_ptr<Stream> master{nullptr};
50 : std::vector<std::unique_ptr<Stream>> slaves;
51 : u32 slaveIndex{0};
52 : };
53 :
54 : } // namespace Hccl
55 :
56 : #endif // HCCLV2_OPBASE_STREAM_MANAGER_H
|