Merged
[feat]: ccu res alloc dynamic #1998
zhongyuAdd on Jul 15
[feat]: ccu res alloc dynamic #1998
Merged
Merged fromzhongyu1/hccl-ccuccu_resintocann/hcclmaster
Total: 8 files changed+720-68
| @@ -0,0 +1,55 @@ | |||
| 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 PROGRAM 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 CCU_RES_DEFS_DL_H | ||
| 12 | +#define CCU_RES_DEFS_DL_H | ||
| 13 | + | ||
| 14 | +#include <stdint.h> | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif // __cplusplus | ||
| 19 | + | ||
| 20 | +/* | ||
| 21 | + * CCU 资源类型与描述符句柄的本地定义。 | ||
| 22 | + * | ||
| 23 | + * 背景:hcomm 包从某个 9.1.0 修订版开始才提供 ccu_res_defs.h,但同一个 9.1.0 版本号的 | ||
| 24 | + * 旧 hcomm 包并不包含该文件,编译期 CANN_VERSION_NUM 无法区分这两种 9.1.0 包。 | ||
| 25 | + * 因此 HCCL 不再依赖 hcomm 的 ccu_res_defs.h,统一用本地定义。 | ||
| 26 | + * | ||
| 27 | + * ABI 安全性:本文件中的 HcommCcuResDescHandle(uint64_t)与 HcommCcuResType(enum) | ||
| 28 | + * 的二进制布局与 hcomm 包内定义完全一致,运行时通过 dlsym 调用 hcomm 库函数时 | ||
| 29 | + * 参数传递 ABI 兼容。若未来 hcomm 侧调整枚举值或类型大小,需同步更新此处。 | ||
| 30 | + */ | ||
| 31 | + | ||
| 32 | +/** | ||
| 33 | + * @brief CCU资源描述符句柄类型 | ||
| 34 | + */ | ||
| 35 | +typedef uint64_t HcommCcuResDescHandle; | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | + * @brief CCU资源类型枚举 | ||
| 39 | + */ | ||
| 40 | +typedef enum { | ||
| 41 | + HCOMM_CCU_RES_TYPE_INVALID = -1, ///< 无效资源类型 | ||
| 42 | + HCOMM_CCU_RES_TYPE_LOOP = 0, ///< Loop资源 | ||
| 43 | + HCOMM_CCU_RES_TYPE_CCU_BUF = 1, ///< CCU Buffer资源 | ||
| 44 | + HCOMM_CCU_RES_TYPE_VARIABLE = 2, ///< Variable资源 | ||
| 45 | + HCOMM_CCU_RES_TYPE_ADDRESS = 3, ///< Address资源 | ||
| 46 | + HCOMM_CCU_RES_TYPE_EVENT = 4, ///< Event资源 | ||
| 47 | + HCOMM_CCU_RES_TYPE_CCU_THREAD = 5, ///< CCU Thread资源 | ||
| 48 | + HCOMM_CCU_RES_TYPE_INSTRUCTION = 6 ///< Instruction资源 | ||
| 49 | +} HcommCcuResType; | ||
| 50 | + | ||
| 51 | +#ifdef __cplusplus | ||
| 52 | +} | ||
| 53 | +#endif // __cplusplus | ||
| 54 | + | ||
| 55 | +#endif // CCU_RES_DEFS_DL_H | ||
| @@ -16,7 +16,31 @@ | |||
| 16 | 16 | ||
| 17 | DEFINE_WEAK_FUNC(CcuResult, HcommCcuGetMemToken, uint64_t srcVa, uint64_t size, uint64_t *tokenInfo); | 17 | DEFINE_WEAK_FUNC(CcuResult, HcommCcuGetMemToken, uint64_t srcVa, uint64_t size, uint64_t *tokenInfo); |
| 18 | 18 | ||
| 19 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsResDescCreate, uint32_t dieId, HcommCcuResDescHandle *resDesc); | ||
| 20 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsResDescDestroy, HcommCcuResDescHandle resDesc); | ||
| 21 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsResDescSetNum, | ||
| 22 | + HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t resNum); | ||
| 23 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsResDescQueryNum, | ||
| 24 | + HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t *resNum); | ||
| 25 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsCreate, | ||
| 26 | + const HcommCcuResDescHandle *resDescs, uint32_t resDescNum, CcuInsHandle *ccuInsHandle); | ||
| 27 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsDestroy, CcuInsHandle ccuInsHandle); | ||
| 28 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuInsQueryResDesc, | ||
| 29 | + CcuInsHandle ccuInsHandle, HcommCcuResDescHandle resDesc); | ||
| 30 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuQueryRemainResDesc, HcommCcuResDescHandle resDesc); | ||
| 31 | +DEFINE_WEAK_FUNC(CcuResult, HcommCcuKernelQueryResReq, | ||
| 32 | + const void *kernelFunc, const void **kernelArgs, uint32_t argNum, HcommCcuResDescHandle resDesc); | ||
| 33 | + | ||
| 19 | // 初始化 | 34 | // 初始化 |
| 20 | void CcuResDlInit(void* libHcommHandle) { | 35 | void CcuResDlInit(void* libHcommHandle) { |
| 21 | INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuGetMemToken); | 36 | INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuGetMemToken); |
| 37 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsResDescCreate); | ||
| 38 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsResDescDestroy); | ||
| 39 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsResDescSetNum); | ||
| 40 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsResDescQueryNum); | ||
| 41 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsCreate); | ||
| 42 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsDestroy); | ||
| 43 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuInsQueryResDesc); | ||
| 44 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuQueryRemainResDesc); | ||
| 45 | + INIT_SUPPORT_FLAG(libHcommHandle, HcommCcuKernelQueryResReq); | ||
| 22 | } | 46 | } |
| @@ -13,6 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | #include "dlsym_common.h" | 14 | #include "dlsym_common.h" |
| 15 | #include "ccu_types_dl.h" | 15 | #include "ccu_types_dl.h" |
| 16 | +#include "ccu_res_defs_dl.h" | ||
| 16 | 17 | ||
| 17 | #ifdef __cplusplus | 18 | #ifdef __cplusplus |
| 18 | extern "C" { | 19 | extern "C" { |
| @@ -20,6 +21,32 @@ extern "C" { | |||
| 20 | 21 | ||
| 21 | DECL_WEAK_FUNC(CcuResult, HcommCcuGetMemToken, uint64_t srcVa, uint64_t size, uint64_t *tokenInfo); | 22 | DECL_WEAK_FUNC(CcuResult, HcommCcuGetMemToken, uint64_t srcVa, uint64_t size, uint64_t *tokenInfo); |
| 22 | 23 | ||
| 24 | +/* 动态资源申请相关接口(9.1.0+新接口),旧hcomm包不存在时返回CCU_E_NOT_SUPPORT */ | ||
| 25 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsResDescCreate, uint32_t dieId, HcommCcuResDescHandle *resDesc); | ||
| 26 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsResDescDestroy, HcommCcuResDescHandle resDesc); | ||
| 27 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsResDescSetNum, | ||
| 28 | + HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t resNum); | ||
| 29 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsResDescQueryNum, | ||
| 30 | + HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t *resNum); | ||
| 31 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsCreate, | ||
| 32 | + const HcommCcuResDescHandle *resDescs, uint32_t resDescNum, CcuInsHandle *ccuInsHandle); | ||
| 33 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsDestroy, CcuInsHandle ccuInsHandle); | ||
| 34 | +DECL_WEAK_FUNC(CcuResult, HcommCcuInsQueryResDesc, | ||
| 35 | + CcuInsHandle ccuInsHandle, HcommCcuResDescHandle resDesc); | ||
| 36 | +DECL_WEAK_FUNC(CcuResult, HcommCcuQueryRemainResDesc, HcommCcuResDescHandle resDesc); | ||
| 37 | +DECL_WEAK_FUNC(CcuResult, HcommCcuKernelQueryResReq, | ||
| 38 | + const void *kernelFunc, const void **kernelArgs, uint32_t argNum, HcommCcuResDescHandle resDesc); | ||
| 39 | + | ||
| 40 | +DECL_SUPPORT_FLAG(HcommCcuInsResDescCreate); | ||
| 41 | +DECL_SUPPORT_FLAG(HcommCcuInsResDescDestroy); | ||
| 42 | +DECL_SUPPORT_FLAG(HcommCcuInsResDescSetNum); | ||
| 43 | +DECL_SUPPORT_FLAG(HcommCcuInsResDescQueryNum); | ||
| 44 | +DECL_SUPPORT_FLAG(HcommCcuInsCreate); | ||
| 45 | +DECL_SUPPORT_FLAG(HcommCcuInsDestroy); | ||
| 46 | +DECL_SUPPORT_FLAG(HcommCcuInsQueryResDesc); | ||
| 47 | +DECL_SUPPORT_FLAG(HcommCcuQueryRemainResDesc); | ||
| 48 | +DECL_SUPPORT_FLAG(HcommCcuKernelQueryResReq); | ||
| 49 | + | ||
| 23 | void CcuResDlInit(void* libHcommHandle); | 50 | void CcuResDlInit(void* libHcommHandle); |
| 24 | 51 | ||
| 25 | #ifdef __cplusplus | 52 | #ifdef __cplusplus |
| @@ -14,8 +14,10 @@ | |||
| 14 | #include <stdlib.h> | 14 | #include <stdlib.h> |
| 15 | 15 | ||
| 16 | DEFINE_WEAK_FUNC(HcclResult, HcclCommQueryCcuIns, HcclComm comm, CcuInsHandle *insHandles, uint32_t *insNum); | 16 | DEFINE_WEAK_FUNC(HcclResult, HcclCommQueryCcuIns, HcclComm comm, CcuInsHandle *insHandles, uint32_t *insNum); |
| 17 | +DEFINE_WEAK_FUNC(HcclResult, HcclCommAssignCcuIns, HcclComm comm, CcuInsHandle insHandle); | ||
| 17 | 18 | ||
| 18 | // 初始化 | 19 | // 初始化 |
| 19 | void HcclCcuResDlInit(void* libHcommHandle) { | 20 | void HcclCcuResDlInit(void* libHcommHandle) { |
| 20 | INIT_SUPPORT_FLAG(libHcommHandle, HcclCommQueryCcuIns); | 21 | INIT_SUPPORT_FLAG(libHcommHandle, HcclCommQueryCcuIns); |
| 22 | + INIT_SUPPORT_FLAG(libHcommHandle, HcclCommAssignCcuIns); | ||
| 21 | } | 23 | } |
| @@ -20,6 +20,10 @@ extern "C" { | |||
| 20 | #endif | 20 | #endif |
| 21 | 21 | ||
| 22 | DECL_WEAK_FUNC(HcclResult, HcclCommQueryCcuIns, HcclComm comm, CcuInsHandle *insHandles, uint32_t *insNum); | 22 | DECL_WEAK_FUNC(HcclResult, HcclCommQueryCcuIns, HcclComm comm, CcuInsHandle *insHandles, uint32_t *insNum); |
| 23 | +DECL_WEAK_FUNC(HcclResult, HcclCommAssignCcuIns, HcclComm comm, CcuInsHandle insHandle); | ||
| 24 | + | ||
| 25 | +DECL_SUPPORT_FLAG(HcclCommQueryCcuIns); | ||
| 26 | +DECL_SUPPORT_FLAG(HcclCommAssignCcuIns); | ||
| 23 | 27 | ||
| 24 | void HcclCcuResDlInit(void* libHcommHandle); | 28 | void HcclCcuResDlInit(void* libHcommHandle); |
| 25 | 29 | ||
| @@ -291,6 +291,8 @@ struct CcuKernelArgBase { | |||
| 291 | struct CcuKernelInfo { | 291 | struct CcuKernelInfo { |
| 292 | // kernel资源组序号,group号不同时,资源复用 | 292 | // kernel资源组序号,group号不同时,资源复用 |
| 293 | u32 resGroup = 0; | 293 | u32 resGroup = 0; |
| 294 | + // kernel所属dieId,从channel所在die获取,由各算法在CalcRes中填充;单die算法默认为0 | ||
| 295 | + u32 dieId = 0; | ||
| 294 | // kernel名 string? | 296 | // kernel名 string? |
| 295 | char kernelFuncName[64]; | 297 | char kernelFuncName[64]; |
| 296 | // kernel函数 | 298 | // kernel函数 |
| @@ -82,7 +82,8 @@ HcclResult HcclGetChannelImpl(const u32 level, HcclComm comm, const OpParam &par | |||
| 82 | const CommEngine commEngine, AlgResourceCtxSerializable* resCtxHost, MemRegInfo &memRegInfo); | 82 | const CommEngine commEngine, AlgResourceCtxSerializable* resCtxHost, MemRegInfo &memRegInfo); |
| 83 | HcclResult RegGraphModeBuffers(HcclComm comm, const OpParam ¶m, char* inputBuffTag, char* outputBuffTag, std::vector<HcclMemHandle>& memHandles); | 83 | HcclResult RegGraphModeBuffers(HcclComm comm, const OpParam ¶m, char* inputBuffTag, char* outputBuffTag, std::vector<HcclMemHandle>& memHandles); |
| 84 | HcclResult GetGraphModeBuffers(HcclComm comm, ChannelHandle channelHandle, const char* inputBuffTag, const char* outputBuffTag, ChannelInfo& channel); | 84 | HcclResult GetGraphModeBuffers(HcclComm comm, ChannelHandle channelHandle, const char* inputBuffTag, const char* outputBuffTag, ChannelInfo& channel); |
| 85 | -HcclResult HcclGetCcuKernel(HcclComm comm, AlgResourceRequest &resRequest, | 85 | +// opMode 用于区分 CCU_MS / CCU_SCHED 等模式,影响默认资源阈值(如 LOOP/CCU_BUF 默认值) |
| 86 | +HcclResult HcclGetCcuKernel(HcclComm comm, OpExecuteConfig opMode, AlgResourceRequest &resRequest, | ||
| 86 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost); | 87 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost); |
| 87 | 88 | ||
| 88 | HcclResult HcclGetChannelForCcu(HcclComm comm, const OpParam ¶m, AlgResourceRequest &resRequest); | 89 | HcclResult HcclGetChannelForCcu(HcclComm comm, const OpParam ¶m, AlgResourceRequest &resRequest); |