Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HCCL_DPU_MANAGER_H
11 : #define HCCL_DPU_MANAGER_H
12 :
13 : #include "acl/acl_rt.h"
14 : #include "hccl/hccl_types.h"
15 : #include <memory>
16 : #include <string>
17 : #include <unordered_map>
18 : #include "config_log.h"
19 : #include "../../../unified_platform/resource/buffer/dev_buffer.h"
20 :
21 : namespace hccl {
22 :
23 : constexpr u32 SHARE_HBM_MEMORY_SIZE = 100 * 1024 * 1024; // 100MB
24 : constexpr char DPUTAG[] = "DPUTAG";
25 :
26 : class DpuManager {
27 : public:
28 : DpuManager();
29 : ~DpuManager();
30 :
31 : HcclResult Init(const std::string& commId, u32 deviceLogicId);
32 : HcclResult InitDpuKernel();
33 : HcclResult DeInitDpuKernel();
34 :
35 1 : bool IsDpuKernelLaunched() const { return isDpuKernelLaunched_; }
36 :
37 : HcclResult CreateWorkspaceBuf(const char* memTag, uint64_t* size, bool* newCreated);
38 : std::shared_ptr<Hccl::DevBuffer> GetKFCWorkSpace(const char* memTag);
39 : HcclResult GetDevMemWorkSpace(const std::string& memTag, uint64_t* size, void** addr, bool* newCreated);
40 : HcclResult GetKFCWorkSpaceVA(const std::string& memTag, uint64_t* size, void** addr, bool* newCreated);
41 : HcclResult AllocAndRegKFCWorkSpace(uint64_t size);
42 : HcclResult DestroyKFCWorkSpaceVA();
43 : HcclResult DestroyDpuKernelResource();
44 :
45 : private:
46 : HcclResult InitAndLaunchDpuKernel();
47 : HcclResult PrepareDpuKernelResource(aclrtFuncHandle& funcHandle);
48 : HcclResult LaunchDpuKernel(aclrtFuncHandle& funcHandle);
49 : HcclResult WaitDpuKernelThreadTerminate();
50 :
51 : std::string commId_;
52 : u32 devLogicId_{0};
53 : void* hostShareBuf_{nullptr};
54 : void* va_{nullptr};
55 : void* accessVA_{nullptr};
56 : std::unordered_map<std::string, std::shared_ptr<Hccl::DevBuffer>> tagWorkspaceVAMap_;
57 : aclrtStream dpuStream_{nullptr};
58 : aclrtContext dpuContext_{nullptr};
59 : aclrtContext npuContext_{nullptr};
60 : bool isDpuKernelLaunched_{false};
61 : u32 waitTransportReadyTimeoutMs_{200 * 1000}; // 默认200秒
62 :
63 : std::unordered_map<std::string, std::shared_ptr<Hccl::DevBuffer>> tagWorkspaceMap_;
64 : };
65 : } // namespace hccl
66 :
67 : #endif // HCCL_DPU_MANAGER_H
|