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 ENDPOINT_MGR_H
12 : #define ENDPOINT_MGR_H
13 :
14 : #include <memory>
15 : #include <unordered_map>
16 : #include <vector>
17 : #include <mutex>
18 : #include "endpoint.h"
19 : #include "../endpoint_pairs/endpoint_pair.h"
20 : #include "hccl_mem_defs.h"
21 :
22 : namespace hcomm {
23 : /**
24 : * @note 职责:Endpoint管理器,支持不同类型的Endpoint的创建和销毁管理。
25 : */
26 : class EndpointMgr {
27 : public:
28 104 : EndpointMgr() {};
29 : ~EndpointMgr();
30 :
31 : // 获取端点
32 : HcclResult Get(EndpointDesc epDesc, EndpointHandle &handle);
33 :
34 : // 注册内存到端点
35 : HcclResult RegisterMemory(EndpointHandle epHandle, const std::vector<std::string>& memTag,
36 : const std::vector<HcclMem>& memVec, std::vector<MemHandle>& memHandleVec);
37 :
38 : // 获取所有注册的内存信息
39 : HcclResult GetAllRegisteredMemory(EndpointHandle epHandle, std::vector<MemHandle>& memHandleVec);
40 :
41 : private:
42 : HcclResult AddMemHandle(EndpointHandle endpointHandle, const std::vector<MemHandle>& memHandleVec);
43 : bool IsMemExist(EndpointHandle epHandle);
44 : bool IsDescExist(EndpointDesc epDesc);
45 :
46 : private:
47 : std::unordered_map<EndpointDesc, EndpointHandle> endpointMap_{};
48 : std::unordered_map<EndpointHandle, std::vector<MemHandle>> endpointMemMap_{};
49 : std::mutex mutex_{};
50 : };
51 :
52 : } // namespace hcomm
53 :
54 : #endif // ENDPOINT_MGR_H
|