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 URMA_ENDPOINT_H
12 : #define URMA_ENDPOINT_H
13 :
14 : #include <memory>
15 : #include <vector>
16 : #include <string>
17 : #include "endpoint.h"
18 : #include "ccu_channel_ctx_pool.h"
19 : #include "socket/socket.h"
20 : #include "externalinput_pub.h"
21 : #include "proc_reged_mem_mgr_cache.h"
22 : #include <mutex>
23 :
24 : namespace hcomm {
25 : /**
26 : * @note 职责:Host CPU通信引擎+RoCE协议的通信设备Endpoint,管理通信设备上下文,以及设备上的注册内存。
27 : */
28 : class UrmaEndpoint : public Endpoint {
29 : public:
30 : explicit UrmaEndpoint(const EndpointDesc& endpointDesc);
31 : ~UrmaEndpoint() noexcept override;
32 :
33 : HcclResult Init() override;
34 :
35 : HcclResult ServerSocketListen(const uint32_t port) override;
36 : HcclResult ServerSocketStopListen(const uint32_t port) override;
37 : inline HcclResult ServerSocketStopListenImpl(const uint32_t port);
38 : HcclResult ServerSocketGetListenPort(uint32_t* port) override;
39 :
40 0 : std::shared_ptr<RegedMemMgr> GetRegedMemMgr() override { return regedMemMgr_; }
41 :
42 : CcuChannelCtxPool* GetCcuChannelCtxPool();
43 :
44 : HcclResult RegisterMemory(HcommMem mem, const char* memTag, void** memHandle) override;
45 : HcclResult UnregisterMemory(void* memHandle) override;
46 : HcclResult MemoryExport(void* memHandle, void** memDesc, uint32_t* memDescLen) override;
47 : HcclResult MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem) override;
48 : HcclResult MemoryUnimport(const void* memDesc, uint32_t descLen) override;
49 : HcclResult GetAllMemHandles(void** memHandles, uint32_t* memHandleNum) override;
50 : HcclResult GetAsyncEvents(uint32_t devPhyId, struct AsyncEvent events[], uint32_t& num) override;
51 :
52 : private:
53 : std::mutex portMutex_;
54 : u32 dynamicPort_{HCCL_INVALID_PORT};
55 : std::unique_ptr<CcuChannelCtxPool> ccuChannelCtxPool_{nullptr};
56 : MemMgrCacheKey cacheKey_{};
57 : };
58 : } // namespace hcomm
59 :
60 : #endif // URMA_ENDPOINT_H
|