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 42 : Stream *GetMaster() const
35 : {
36 42 : return master.get();
37 : }
38 :
39 : Stream *GetOrCreateSlave();
40 :
41 16 : void ResetIndex(u32 index)
42 : {
43 16 : slaveIndex = index;
44 16 : }
45 :
46 5 : u32 GetSlaveIndex() const
47 : {
48 5 : return slaveIndex;
49 : }
50 :
51 : Stream *GetSlave(u32 index) const;
52 :
53 : private:
54 : void ReplaceMaster(std::unique_ptr<Stream> stream);
55 :
56 : CommunicatorImpl *comm{nullptr};
57 : std::unique_ptr<Stream> master{nullptr};
58 : std::vector<std::unique_ptr<Stream>> slaves;
59 : u32 slaveIndex{0};
60 : };
61 :
62 : } // namespace Hccl
63 :
64 : #endif // HCCLV2_OPBASE_STREAM_MANAGER_H
|