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