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