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 INDEPENDENT_OP_RESOURCE_MANAGER_H
12 : #define INDEPENDENT_OP_RESOURCE_MANAGER_H
13 :
14 : #include <memory>
15 : #include <string>
16 : #include <unordered_set>
17 : #include <atomic>
18 : #include "hccl/hccl_res.h"
19 : #include "hccl_independent_common.h"
20 : #include "comm_mem_manager.h"
21 : #include "comm_engine_res_manager.h"
22 : #include "rank_graph.h"
23 : #include "comm_config_pub.h"
24 : #include "independent_op_context_manager.h"
25 : #include "channel_manager.h"
26 : #include "aicpu_init_param.h"
27 :
28 : namespace hccl {
29 : constexpr int32_t HCCL_COMM_ENGINE_CONFIG_NOT_SET = -1;
30 : constexpr uint32_t HCCL_COMM_THREADNUM_CONFIG_NOT_SET = 0xffffffff;
31 : constexpr uint32_t HCCL_COMM_NOTIFY_NUM_PER_THREAD_CONFIG_NOT_SET = 0xffffffff;
32 :
33 : class IndependentOp {
34 : public:
35 : IndependentOp();
36 604 : ~IndependentOp() = default;
37 :
38 : // 初始化资源管理器
39 : HcclResult SetIndependentOpConfig(const CommConfig &commConfig, const RankTable_t &rankTable,
40 : const HcclTopoAttr &topoAttr, const aclrtBinHandle binHandle, HDCommunicateParams &kfcControlTransferH2DParams,
41 : HDCommunicateParams &kfcStatusTransferD2HParams, CCLBufferManager &bufferManager);
42 : HcclResult SetChannelCallbacks(const ChannelManagerCallbacks& channelCallbacks);
43 :
44 : // 获取配置信息
45 : u32 GetThreadNum() const { return threadNum_; }
46 : u32 GetNotifyNumPerThread() const { return notifyNumPerThread_; }
47 :
48 : bool GetAicpuCommState(); // 是否线程安全
49 : void SetAicpuCommState(bool aicpuCommState);
50 :
51 7 : inline CommMemMgr& GetCommMemMgr() {
52 7 : return commMemMgr_;
53 : }
54 :
55 22 : inline CommEngineResMgr& GetCommEngineResMgr() {
56 22 : return engineResMgr_;
57 : }
58 :
59 52 : inline ContextManager& GetContextManager() {
60 52 : return contextMgr_;
61 : }
62 :
63 402 : inline ChannelManager& GetChannelManager() {
64 402 : return channelMgr_;
65 : }
66 :
67 : // 自定义算子Aicpu通信域公共初始化
68 : HcclResult KernelLaunchAicpuCommInit();
69 :
70 : private:
71 : // config内容
72 : int32_t commEngine_ = -1;
73 : u32 threadNum_ = 0;
74 : u32 notifyNumPerThread_ = 0;
75 : u64 cclBufferSize_ = 0;
76 : std::string commId_;
77 : aclrtBinHandle binHandle_ = nullptr;
78 :
79 : // 管理器
80 : CommMemMgr commMemMgr_;
81 : CommEngineResMgr engineResMgr_;
82 : ContextManager contextMgr_;
83 : ChannelManager channelMgr_;
84 :
85 : bool isAicpuCommInit_ = false;
86 : CommAicpuParam commAicpuParam_{};
87 : };
88 :
89 : } // namespace hccl
90 : #endif
|