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 CPU_URMA_ENDPOINT_H
11 : #define CPU_URMA_ENDPOINT_H
12 :
13 : #include <cstdint>
14 : #include <memory>
15 : #include <mutex>
16 : #include <string>
17 : #include <unordered_map>
18 :
19 : #include "endpoint.h"
20 : #include "ccu_channel_ctx_pool.h"
21 : #include "proc_reged_mem_mgr_cache.h"
22 : #include "externalinput_pub.h"
23 :
24 : namespace hcomm {
25 : class CpuUrmaEndpoint : public Endpoint {
26 : public:
27 : explicit CpuUrmaEndpoint(const EndpointDesc& endpointDesc);
28 : ~CpuUrmaEndpoint() noexcept override;
29 :
30 : HcclResult Init() override;
31 :
32 : HcclResult ServerSocketListen(const uint32_t port) override;
33 : HcclResult ServerSocketStopListen(const uint32_t port) override;
34 : inline HcclResult ServerSocketStopListenImpl(const uint32_t port);
35 : HcclResult ServerSocketGetListenPort(uint32_t* port) override;
36 :
37 : static std::unordered_map<Hccl::PortData, std::unique_ptr<Hccl::Socket>>& GetServerSocketMap();
38 :
39 0 : std::shared_ptr<RegedMemMgr> GetRegedMemMgr() override { return regedMemMgr_; }
40 :
41 : HcclResult RegisterMemory(HcommMem mem, const char* memTag, void** memHandle) override;
42 : HcclResult UnregisterMemory(void* memHandle) override;
43 : HcclResult MemoryExport(void* memHandle, void** memDesc, uint32_t* memDescLen) override;
44 : HcclResult MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem) override;
45 : HcclResult MemoryUnimport(const void* memDesc, uint32_t descLen) override;
46 : HcclResult GetAllMemHandles(void** memHandles, uint32_t* memHandleNum) override;
47 :
48 : private:
49 : std::mutex portMutex_;
50 : u32 dynamicPort_{HCCL_INVALID_PORT};
51 : MemMgrCacheKey cacheKey_{};
52 : };
53 : } // namespace hcomm
54 :
55 : #endif // CPU_URMA_ENDPOINT_H
|