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 HCCL_CCU_CTX_MGR_H
12 : #define HCCL_CCU_CTX_MGR_H
13 :
14 : #include <vector>
15 : #include "ccu_ctx_arg.h"
16 : #include "ccu_ctx.h"
17 : #include "ccu_res_pack_legacy.h"
18 : #include "ccu_task_arg.h"
19 :
20 : namespace Hccl {
21 :
22 : struct CcuCtxGroup {
23 : std::vector<std::unique_ptr<CcuContext>> ctxs;
24 :
25 : // 默认构造函数
26 28 : CcuCtxGroup() = default;
27 : // 移动构造函数
28 : CcuCtxGroup(CcuCtxGroup&& other) : ctxs(std::move(other.ctxs)) {}
29 : // 移动赋值操作符
30 11 : CcuCtxGroup& operator=(CcuCtxGroup&& other)
31 : {
32 11 : if (this == &other) {
33 0 : return *this;
34 : }
35 :
36 : // 清理当前的ctxs
37 11 : for (auto& ctx : ctxs) {
38 0 : ctx.reset();
39 : }
40 11 : ctxs.clear();
41 :
42 : // 将other的ctxs移动到当前对象
43 11 : ctxs.reserve(other.ctxs.size());
44 28 : for (auto& ctx : other.ctxs) {
45 17 : ctxs.push_back(std::move(ctx));
46 : }
47 :
48 11 : return *this;
49 : }
50 :
51 : CcuCtxSignature GetCtxSignature();
52 : };
53 :
54 : class CcuCtxMgr {
55 : public:
56 : CcuCtxMgr();
57 : ~CcuCtxMgr();
58 :
59 : /**
60 : * @brief 分配资源
61 : *
62 : * @param deviceLogicId device逻辑ID
63 : * @param ctxGroup CCU上下文组
64 : * @param resPack 资源包
65 : *
66 : * @return 返回HcclResult,表示分配资源是否成功
67 : * @note 此函数用于分配资源
68 : */
69 : static HcclResult AllocRes(s32 deviceLogicId, CcuCtxGroup& ctxGroup, CcuResPack& resPack);
70 :
71 : /**
72 : * @brief 释放资源
73 : *
74 : * @param deviceLogicId device逻辑ID
75 : * @param ctxGroup CCU上下文组
76 : *
77 : * @return 返回HcclResult,表示释放资源是否成功
78 : *
79 : * @note 此函数用于释放指定device逻辑ID的CCU上下文组的资源
80 : */
81 : static HcclResult ReleaseRes(s32 deviceLogicId, CcuCtxGroup& ctxGroup);
82 :
83 : /**
84 : * @brief 获取任务参数
85 : *
86 : * @param deviceLogicId device逻辑ID
87 : * @param ccuTaskArg CCU 任务参数
88 : * @param executorId 执行器ID
89 : * @param taskParam 任务参数
90 : *
91 : * @return HcclResult 获取参数结果
92 : * @note 无
93 : */
94 : static HcclResult GetTaskParam(
95 : s32 deviceLogicId, CcuTaskArg& ccuTaskArg, const uint64_t executorId,
96 : std::vector<std::vector<CcuTaskParam>>& taskParam);
97 :
98 : /**
99 : * @brief 获取任务Profiling信息
100 : *
101 : * @param deviceLogicId device逻辑ID
102 : * @param ccuTaskArg CCU 任务参数
103 : * @param entityId 执行器ID
104 : * @param profilingInfo 任务profiling信息
105 : *
106 : * @return HcclResult 获取profiling结果
107 : * @note 无
108 : */
109 : static HcclResult GetProfilingInfo(
110 : s32 deviceLogicId, CcuTaskArg& ccuTaskArg, uint64_t entityId,
111 : std::vector<std::vector<CcuProfilingInfo>>& profilingInfo);
112 :
113 : private:
114 : };
115 : }; // namespace Hccl
116 :
117 : #endif // HCCL_CCU_CTX_MGR_H
|