| @@ -5,6 +5,7 @@ | |||
| 5 | - [拓扑信息查询<a name="sub_menu"></a>](./control_plane_api/topo_info_query/README.md) | 5 | - [拓扑信息查询<a name="sub_menu"></a>](./control_plane_api/topo_info_query/README.md) |
| 6 | - [通信域资源管理<a name="sub_menu"></a>](./control_plane_api/comms_domain_resource_mgmt/README.md) | 6 | - [通信域资源管理<a name="sub_menu"></a>](./control_plane_api/comms_domain_resource_mgmt/README.md) |
| 7 | - [基础资源管理<a name="sub_menu"></a>](./control_plane_api/basic_resource_mgmt/README.md) | 7 | - [基础资源管理<a name="sub_menu"></a>](./control_plane_api/basic_resource_mgmt/README.md) |
| 8 | + - [CCU 资源管理<a name="sub_menu"></a>](./control_plane_api/ccu_resource_mgmt/README.md) | ||
| 8 | - [CCU Kernel生命周期与内存Token管理<a name="sub_menu"></a>](./control_plane_api/ccu_kernel_launch_execution/index.md) | 9 | - [CCU Kernel生命周期与内存Token管理<a name="sub_menu"></a>](./control_plane_api/ccu_kernel_launch_execution/index.md) |
| 9 | - [数据面接口](./_dump_node_data.md) | 10 | - [数据面接口](./_dump_node_data.md) |
| 10 | - [CPU-CPU_TS-AICPU_TS<a name="sub_menu"></a>](./data_plane_api/cpu-cpu_ts-aicpu_ts/README.md) | 11 | - [CPU-CPU_TS-AICPU_TS<a name="sub_menu"></a>](./data_plane_api/cpu-cpu_ts-aicpu_ts/README.md) |
| @@ -7,4 +7,5 @@ | |||
| 7 | - [拓扑信息查询](./control_plane_api/topo_info_query/README.md) | 7 | - [拓扑信息查询](./control_plane_api/topo_info_query/README.md) |
| 8 | - [通信域资源管理](./control_plane_api/comms_domain_resource_mgmt/README.md) | 8 | - [通信域资源管理](./control_plane_api/comms_domain_resource_mgmt/README.md) |
| 9 | - [基础资源管理](./control_plane_api/basic_resource_mgmt/README.md) | 9 | - [基础资源管理](./control_plane_api/basic_resource_mgmt/README.md) |
| 10 | +- [CCU 资源管理](./control_plane_api/ccu_resource_mgmt/README.md) | ||
| 10 | - [CCU Kernel生命周期与内存Token管理](./control_plane_api/ccu_kernel_launch_execution/index.md) | 11 | - [CCU Kernel生命周期与内存Token管理](./control_plane_api/ccu_kernel_launch_execution/index.md) |
| @@ -2,29 +2,33 @@ | |||
| 2 | 2 | ||
| 3 | 本节包含CCU Kernel Host侧生命周期管理接口及内存Token查询接口。 | 3 | 本节包含CCU Kernel Host侧生命周期管理接口及内存Token查询接口。 |
| 4 | 4 | ||
| 5 | -通过这些接口,用户可以完成CCU实例的创建与销毁、Kernel的注册与翻译、Kernel的启动执行,以及进程虚拟地址到CCU访问Token的转换。 | 5 | +通过这些接口,用户可以完成Kernel的注册、翻译与启动执行,以及将进程虚拟地址转换为CCU访问Token。 |
| 6 | 6 | ||
| 7 | ## 前置条件 | 7 | ## 前置条件 |
| 8 | 8 | ||
| 9 | -本节接口需要传入 `CcuInsHandle`(CCU 实例句柄),获取步骤如下: | 9 | +Kernel注册和启动接口需要传入`CcuInsHandle`(CCU实例句柄)。当前仅支持集合通信场景,调用前须完成HCCL通信域初始化、CCU建链和CCU实例绑定。 |
| 10 | 10 | ||
| 11 | 1. **创建 HcclComm 通信域**:参见 [HcclCommInitClusterInfo](../../../comm_mgr_c/HcclCommInitClusterInfo.md) | 11 | 1. **创建 HcclComm 通信域**:参见 [HcclCommInitClusterInfo](../../../comm_mgr_c/HcclCommInitClusterInfo.md) |
| 12 | 或 [HcclCommInitRootInfo](../../../comm_mgr_c/HcclCommInitRootInfo.md)。 | 12 | 或 [HcclCommInitRootInfo](../../../comm_mgr_c/HcclCommInitRootInfo.md)。 |
| 13 | 13 | ||
| 14 | -2. **从通信域查询 CCU 实例句柄**:调用 `HcclCommQueryCcuIns`(声明于 `include/hccl/hccl_ccu_res.h`): | 14 | +2. **规划资源并创建CCU实例**: |
| 15 | 15 | ||
| 16 | - ```c | 16 | + - 调用[HcommCcuInsResDescCreate](../ccu_resource_mgmt/HcommCcuInsResDescCreate.md)为目标IO Die创建资源描述符。 |
| 17 | - extern HcclResult HcclCommQueryCcuIns(HcclComm comm, | 17 | + - 调用[HcommCcuKernelQueryResReq](../ccu_resource_mgmt/HcommCcuKernelQueryResReq.md)统计Kernel资源诉求。 |
| 18 | - CcuInsHandle *insHandles, uint32_t *insNum); | 18 | + - 调用[HcommCcuInsCreate](../ccu_resource_mgmt/HcommCcuInsCreate.md)创建CCU实例。 |
| 19 | - ``` | ||
| 20 | 19 | ||
| 21 | - 典型用法: | 20 | +3. **绑定CCU实例**: |
| 21 | + | ||
| 22 | + - 调用[HcclCommAssignCcuIns](../comms_domain_resource_mgmt/HcclCommAssignCcuIns.md)将实例绑定到通信域。绑定成功后,实例所有权和销毁责任转移给通信域。 | ||
| 23 | + - 创建实例的调用方可继续使用`HcommCcuInsCreate`返回的句柄注册和启动Kernel,但不得再自行销毁实例。仅持有通信域句柄时,可调用[HcclCommQueryCcuIns](../comms_domain_resource_mgmt/HcclCommQueryCcuIns.md)获取已绑定的实例句柄。 | ||
| 24 | + | ||
| 25 | + 通过通信域查询实例句柄的典型用法: | ||
| 22 | 26 | ||
| 23 | ```c | 27 | ```c |
| 24 | CcuInsHandle insHandle = 0; | 28 | CcuInsHandle insHandle = 0; |
| 25 | uint32_t insNum = 0; | 29 | uint32_t insNum = 0; |
| 26 | HcclResult ret = HcclCommQueryCcuIns(comm, &insHandle, &insNum); | 30 | HcclResult ret = HcclCommQueryCcuIns(comm, &insHandle, &insNum); |
| 27 | - // 当前实现固定返回 1 个 CCU 实例,insNum != 1 视为失败 | 31 | + // 当前一个通信域最多绑定1个CCU实例,查询成功时insNum为1。 |
| 28 | if (ret != HCCL_SUCCESS || insNum != 1) { | 32 | if (ret != HCCL_SUCCESS || insNum != 1) { |
| 29 | // 错误处理 | 33 | // 错误处理 |
| 30 | } | 34 | } |
| @@ -32,10 +36,11 @@ | |||
| 32 | 36 | ||
| 33 | > 该接口属于Hccl层(不在`Hcomm*`/`Ccu*`系列内),暂未提供独立API参考页面, | 37 | > 该接口属于Hccl层(不在`Hcomm*`/`Ccu*`系列内),暂未提供独立API参考页面, |
| 34 | > 完整签名以头文件`include/hccl/hccl_ccu_res.h`为准。 | 38 | > 完整签名以头文件`include/hccl/hccl_ccu_res.h`为准。 |
| 39 | +> 如果通信域未绑定CCU实例,`HcclCommQueryCcuIns`返回`HCCL_E_UNAVAIL`。 | ||
| 35 | 40 | ||
| 36 | ## 接口调用顺序 | 41 | ## 接口调用顺序 |
| 37 | 42 | ||
| 38 | -接口调用的标准顺序如下: | 43 | +Kernel注册与启动接口的标准顺序如下: |
| 39 | 44 | ||
| 40 | 1. [HcommCcuKernelRegisterStart](HcommCcuKernelRegisterStart.md):开始一轮Kernel注册。 | 45 | 1. [HcommCcuKernelRegisterStart](HcommCcuKernelRegisterStart.md):开始一轮Kernel注册。 |
| 41 | 2. [HcommCcuKernelRegister](HcommCcuKernelRegister.md):注册Kernel函数,记录其操作序列。 | 46 | 2. [HcommCcuKernelRegister](HcommCcuKernelRegister.md):注册Kernel函数,记录其操作序列。 |
| @@ -0,0 +1,97 @@ | |||
| 1 | +# HcommCcuInsCreate | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +根据一个或多个CCU资源描述符创建CCU实例,并返回实例句柄。每个资源描述符对应一个IO Die,用于指定该Die上各类CCU资源的申请数量。 | ||
| 24 | + | ||
| 25 | +底层按资源对齐粒度连续分配资源。当申请数量不是对齐粒度的整数倍时,实际分配数量可能向上取整。可通过[HcommCcuInsQueryResDesc](HcommCcuInsQueryResDesc.md)查询实例实际占用的资源数量。 | ||
| 26 | + | ||
| 27 | +本接口不读取资源描述符中`HCOMM_CCU_RES_TYPE_INSTRUCTION`对应的资源数量,也不申请Instruction资源。Instruction资源在注册CCU Kernel期间,根据Kernel实际指令数量申请。 | ||
| 28 | + | ||
| 29 | +`HCOMM_CCU_RES_TYPE_CCU_THREAD`对应的Mission资源按融合多Die模式申请:取各资源描述符中Mission申请数量的最大值,在当前Device的所有已使能IO Die上申请相同数量且ID范围相同的Mission资源;仅一个IO Die使能时只在该Die上申请。 | ||
| 30 | + | ||
| 31 | +## 函数原型 | ||
| 32 | + | ||
| 33 | +// ccu_res.h | ||
| 34 | + | ||
| 35 | +```c | ||
| 36 | +CcuResult HcommCcuInsCreate(const HcommCcuResDescHandle *resDescs, | ||
| 37 | + uint32_t resDescNum, CcuInsHandle *ccuInsHandle); | ||
| 38 | +``` | ||
| 39 | + | ||
| 40 | +## 参数说明 | ||
| 41 | + | ||
| 42 | +| 参数名 | 输入/输出 | 描述 | | ||
| 43 | +| --- | --- | --- | | ||
| 44 | +| resDescs | 输入 | 资源描述符句柄数组,不能为空指针。数组中的句柄须由[HcommCcuInsResDescCreate](HcommCcuInsResDescCreate.md)在当前Device上创建,每个句柄对应一个不同的IO Die。 | | ||
| 45 | +| resDescNum | 输入 | `resDescs`中的句柄数量,取值范围为`(0, CCU_MAX_IODIE_NUM]`,当前最大值为2。 | | ||
| 46 | +| ccuInsHandle | 输出 | 创建成功后返回的CCU实例句柄,不能为空指针。类型定义可参见[CcuInsHandle](../../datatype_definition/CcuInsHandle.md)。 | | ||
| 47 | + | ||
| 48 | +## 返回值 | ||
| 49 | + | ||
| 50 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回`CCU_SUCCESS`,其他值表示失败。 | ||
| 51 | + | ||
| 52 | +| 返回值 | 说明 | | ||
| 53 | +| --- | --- | | ||
| 54 | +| `CCU_SUCCESS` | 创建成功,`*ccuInsHandle`为有效的CCU实例句柄。 | | ||
| 55 | +| `CCU_E_PTR` | `resDescs`或`ccuInsHandle`为空指针,或数组中的资源描述符句柄不属于当前Device。 | | ||
| 56 | +| `CCU_E_PARA` | `resDescNum`超出合法范围,或多个资源描述符对应相同的IO Die。 | | ||
| 57 | +| `CCU_E_UNAVAIL` | 当前Device上的连续资源不足,无法满足资源描述符中的申请数量。 | | ||
| 58 | +| `CCU_E_DRV_BUSY` | 单卡多进程场景下,CCU驱动已被其他进程拉起。 | | ||
| 59 | +| `CCU_E_INTERNAL` | CCU实例创建、资源申请或内部登记失败。 | | ||
| 60 | +| 其他错误码 | 初始化CCU驱动或申请资源时产生的其他错误。 | | ||
| 61 | + | ||
| 62 | +## 约束说明 | ||
| 63 | + | ||
| 64 | +- 当前仅支持集合通信场景。调用本接口前须完成HCCL通信域初始化和CCU建链。 | ||
| 65 | +- 调用本接口的线程须通过AscendCL接口`aclrtSetDevice(int32_t deviceId)`绑定到目标NPU Device。`resDescs`中的所有描述符须在同一Device上创建。 | ||
| 66 | +- `resDescs`中的IO Die编号不能重复。 | ||
| 67 | +- 创建过程中,调用方不得并发修改或销毁`resDescs`中的资源描述符。创建成功后,CCU实例独立持有已申请的资源,原资源描述符可继续使用或销毁。 | ||
| 68 | +- 创建成功后,实例所有权归调用方。调用方应通过[HcommCcuInsDestroy](HcommCcuInsDestroy.md)销毁实例;若通过[HcclCommAssignCcuIns](../comms_domain_resource_mgmt/HcclCommAssignCcuIns.md)成功绑定到通信域,则所有权和销毁责任转移给通信域。 | ||
| 69 | +- 本接口只能在主机侧调用。 | ||
| 70 | + | ||
是否需要补充missionid是两个die一起申请 ![]() ![]() | |||
| 71 | +## 调用示例 | ||
| 72 | + | ||
| 73 | +```c | ||
| 74 | +HcommCcuResDescHandle resDesc = 0; | ||
| 75 | +CcuInsHandle insHandle = 0; | ||
| 76 | + | ||
| 77 | +CcuResult ret = HcommCcuInsResDescCreate(0, &resDesc); | ||
| 78 | +if (ret != CCU_SUCCESS) { | ||
| 79 | + return ret; | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +ret = HcommCcuInsResDescSetNum( | ||
| 83 | + resDesc, HCOMM_CCU_RES_TYPE_LOOP, 8); | ||
| 84 | +if (ret == CCU_SUCCESS) { | ||
| 85 | + ret = HcommCcuInsCreate(&resDesc, 1, &insHandle); | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 89 | +if (ret != CCU_SUCCESS) { | ||
| 90 | + return ret; | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +// 使用insHandle注册Kernel,或将其绑定到通信域。 | ||
| 94 | +// ... | ||
| 95 | + | ||
| 96 | +return HcommCcuInsDestroy(insHandle); | ||
| 97 | +``` | ||
| @@ -0,0 +1,83 @@ | |||
| 1 | +# HcommCcuInsCreateDefault | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +使用当前Device上所有已使能IO Die的全部CCU资源创建CCU实例,并返回实例句柄。 | ||
| 24 | + | ||
| 25 | +当前版本不读取`dieIds`和`dieNum`,调用方应分别传入`NULL`和`0`。需要按需申请资源时,请使用[HcommCcuInsCreate](HcommCcuInsCreate.md)。 | ||
| 26 | + | ||
| 27 | +## 函数原型 | ||
| 28 | + | ||
| 29 | +// ccu_res.h | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +CcuResult HcommCcuInsCreateDefault(const uint32_t *dieIds, | ||
| 33 | + uint32_t dieNum, CcuInsHandle *ccuInsHandle); | ||
| 34 | +``` | ||
| 35 | + | ||
| 36 | +## 参数说明 | ||
| 37 | + | ||
| 38 | +| 参数名 | 输入/输出 | 描述 | | ||
| 39 | +| --- | --- | --- | | ||
| 40 | +| dieIds | 输入 | 保留参数,当前版本不读取,应传入`NULL`。 | | ||
| 41 | +| dieNum | 输入 | 保留参数,当前版本不读取,应传入`0`。 | | ||
| 42 | +| ccuInsHandle | 输出 | 创建成功后返回的CCU实例句柄,不能为空指针。类型定义可参见[CcuInsHandle](../../datatype_definition/CcuInsHandle.md)。 | | ||
| 43 | + | ||
| 44 | +## 返回值 | ||
| 45 | + | ||
| 46 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回`CCU_SUCCESS`,其他值表示失败。 | ||
| 47 | + | ||
| 48 | +| 返回值 | 说明 | | ||
| 49 | +| --- | --- | | ||
| 50 | +| `CCU_SUCCESS` | 创建成功,`*ccuInsHandle`为有效的CCU实例句柄。 | | ||
| 51 | +| `CCU_E_PTR` | `ccuInsHandle`为空指针。 | | ||
| 52 | +| `CCU_E_UNAVAIL` | 当前Device上的资源不足,无法申请全部资源。 | | ||
| 53 | +| `CCU_E_DRV_BUSY` | 单卡多进程场景下,CCU驱动已被其他进程拉起。 | | ||
| 54 | +| `CCU_E_INTERNAL` | CCU实例创建、资源查询、资源申请或内部登记失败。 | | ||
| 55 | +| 其他错误码 | 初始化CCU驱动、查询IO Die状态或申请资源时产生的其他错误。 | | ||
| 56 | + | ||
| 57 | +## 约束说明 | ||
| 58 | + | ||
| 59 | +- 当前仅支持集合通信场景。调用本接口前须完成HCCL通信域初始化和CCU建链。 | ||
| 60 | +- 调用本接口的线程须通过AscendCL接口`aclrtSetDevice(int32_t deviceId)`绑定到目标NPU Device。 | ||
| 61 | +- 本接口申请当前Device上所有已使能IO Die的全部CCU资源。若需与其他CCU实例共享资源,应改用[HcommCcuInsCreate](HcommCcuInsCreate.md)按需申请。 | ||
| 62 | +- 创建成功后,实例所有权归调用方。调用方应通过[HcommCcuInsDestroy](HcommCcuInsDestroy.md)销毁实例;若通过[HcclCommAssignCcuIns](../comms_domain_resource_mgmt/HcclCommAssignCcuIns.md)成功绑定到通信域,则所有权和销毁责任转移给通信域。 | ||
| 63 | +- 本接口只能在主机侧调用。 | ||
| 64 | + | ||
| 65 | +## 调用示例 | ||
| 66 | + | ||
| 67 | +```c | ||
| 68 | +CcuInsHandle insHandle = 0; | ||
| 69 | +CcuResult ret = HcommCcuInsCreateDefault(NULL, 0, &insHandle); | ||
| 70 | +if (ret != CCU_SUCCESS) { | ||
| 71 | + return ret; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +HcclResult hcclRet = HcclCommAssignCcuIns(comm, insHandle); | ||
| 75 | +if (hcclRet != HCCL_SUCCESS) { | ||
| 76 | + // 绑定失败,实例所有权仍归调用方。 | ||
| 77 | + HcommCcuInsDestroy(insHandle); | ||
| 78 | + return CCU_E_INTERNAL; | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +// 绑定成功后由通信域管理实例生命周期。 | ||
| 82 | +return CCU_SUCCESS; | ||
| 83 | +``` | ||
| @@ -0,0 +1,71 @@ | |||
| 1 | +# HcommCcuInsDestroy | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +销毁调用方持有的CCU实例,注销该实例关联的Kernel并释放实例占用的CCU资源。销毁成功后,实例句柄失效。 | ||
| 24 | + | ||
| 25 | +## 函数原型 | ||
| 26 | + | ||
| 27 | +// ccu_res.h | ||
| 28 | + | ||
| 29 | +```c | ||
| 30 | +CcuResult HcommCcuInsDestroy(CcuInsHandle ccuInsHandle); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## 参数说明 | ||
| 34 | + | ||
| 35 | +| 参数名 | 输入/输出 | 描述 | | ||
| 36 | +| --- | --- | --- | | ||
| 37 | +| ccuInsHandle | 输入 | 待销毁的CCU实例句柄,须由[HcommCcuInsCreate](HcommCcuInsCreate.md)或[HcommCcuInsCreateDefault](HcommCcuInsCreateDefault.md)在当前Device上创建。 | | ||
| 38 | + | ||
| 39 | +## 返回值 | ||
| 40 | + | ||
| 41 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回`CCU_SUCCESS`,其他值表示失败。 | ||
| 42 | + | ||
| 43 | +| 返回值 | 说明 | | ||
| 44 | +| --- | --- | | ||
| 45 | +| `CCU_SUCCESS` | 销毁成功,CCU实例句柄失效。 | | ||
| 46 | +| `CCU_E_NOT_FOUND` | 当前Device上不存在`ccuInsHandle`对应的CCU实例,或该实例已被销毁。 | | ||
| 47 | + | ||
| 48 | +## 约束说明 | ||
| 49 | + | ||
| 50 | +- 调用本接口的线程须绑定到创建该实例时使用的同一NPU Device。 | ||
| 51 | +- 仅当实例所有权仍归调用方时才可调用本接口。 | ||
| 52 | +- 通过[HcclCommAssignCcuIns](../comms_domain_resource_mgmt/HcclCommAssignCcuIns.md)成功绑定到通信域后,实例所有权和销毁责任已转移给通信域,调用方不得再调用本接口。 | ||
| 53 | +- 销毁成功后不得继续使用`ccuInsHandle`。重复销毁返回`CCU_E_NOT_FOUND`。 | ||
| 54 | +- 调用方须保证没有其他线程正在使用该实例。 | ||
| 55 | +- 本接口只能在主机侧调用。 | ||
| 56 | + | ||
| 57 | +## 调用示例 | ||
| 58 | + | ||
| 59 | +```c | ||
| 60 | +CcuInsHandle insHandle = 0; | ||
| 61 | +CcuResult ret = HcommCcuInsCreateDefault(NULL, 0, &insHandle); | ||
| 62 | +if (ret != CCU_SUCCESS) { | ||
| 63 | + return ret; | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +// 使用insHandle注册和执行Kernel。 | ||
| 67 | +// ... | ||
| 68 | + | ||
| 69 | +ret = HcommCcuInsDestroy(insHandle); | ||
| 70 | +return ret; | ||
| 71 | +``` | ||
| @@ -0,0 +1,84 @@ | |||
| 1 | +# HcommCcuInsQueryResDesc | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +查询CCU实例在指定IO Die上实际占用的各类资源数量,并将结果写入调用方提供的资源描述符。 | ||
| 24 | + | ||
| 25 | +待查询的IO Die由创建`resDesc`时传入的`dieId`指定。接口返回成功后,可通过[HcommCcuInsResDescQueryNum](HcommCcuInsResDescQueryNum.md)逐类型读取查询结果。 | ||
| 26 | + | ||
| 27 | +## 函数原型 | ||
| 28 | + | ||
| 29 | +// ccu_res.h | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +CcuResult HcommCcuInsQueryResDesc(CcuInsHandle ccuInsHandle, | ||
| 33 | + HcommCcuResDescHandle resDesc); | ||
| 34 | +``` | ||
| 35 | + | ||
| 36 | +## 参数说明 | ||
| 37 | + | ||
| 38 | +| 参数名 | 输入/输出 | 描述 | | ||
| 39 | +| --- | --- | --- | | ||
| 40 | +| ccuInsHandle | 输入 | 待查询的CCU实例句柄,不能为`0`。 | | ||
| 41 | +| resDesc | 输入/输出 | 资源描述符句柄,不能为`0`。须通过[HcommCcuInsResDescCreate](HcommCcuInsResDescCreate.md)在当前Device上创建;创建时指定的`dieId`用于选择待查询的IO Die,查询结果覆盖描述符中原有的资源数量。 | | ||
| 42 | + | ||
| 43 | +## 返回值 | ||
| 44 | + | ||
| 45 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回`CCU_SUCCESS`,其他值表示失败。 | ||
| 46 | + | ||
| 47 | +| 返回值 | 说明 | | ||
| 48 | +| --- | --- | | ||
| 49 | +| `CCU_SUCCESS` | 查询成功,实例在指定IO Die上的资源占用量已写入`resDesc`。 | | ||
| 50 | +| `CCU_E_PARA` | `ccuInsHandle`或`resDesc`为`0`,或`resDesc`中的IO Die编号非法。 | | ||
| 51 | +| `CCU_E_NOT_FOUND` | 当前Device上不存在对应的CCU实例或资源描述符。 | | ||
| 52 | +| `CCU_E_INTERNAL` | 查询或写入资源数量时发生内部错误。 | | ||
| 53 | + | ||
| 54 | +## 约束说明 | ||
| 55 | + | ||
| 56 | +- 调用本接口前须通过[HcommCcuInsResDescCreate](HcommCcuInsResDescCreate.md)创建`resDesc`,并用其`dieId`指定待查询的IO Die。 | ||
| 57 | +- 调用本接口的线程须绑定到创建CCU实例和`resDesc`时使用的同一NPU Device。 | ||
| 58 | +- 查询结果覆盖`resDesc`中原有的各类资源数量,但不修改其IO Die编号。 | ||
| 59 | +- 对按对齐粒度分配的资源,本接口返回实例实际占用的数量,可能大于创建实例时请求的数量。 | ||
| 60 | +- 调用方须保证查询期间不并发销毁或修改`ccuInsHandle`和`resDesc`。 | ||
| 61 | +- 本接口只能在主机侧调用。 | ||
| 62 | + | ||
| 63 | +## 调用示例 | ||
| 64 | + | ||
| 65 | +```c | ||
| 66 | +HcommCcuResDescHandle queryDesc = 0; | ||
| 67 | +CcuResult ret = HcommCcuInsResDescCreate(0, &queryDesc); | ||
| 68 | +if (ret != CCU_SUCCESS) { | ||
| 69 | + return ret; | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +ret = HcommCcuInsQueryResDesc(insHandle, queryDesc); | ||
| 73 | +if (ret != CCU_SUCCESS) { | ||
| 74 | + HcommCcuInsResDescDestroy(queryDesc); | ||
| 75 | + return ret; | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +uint32_t loopNum = 0; | ||
| 79 | +ret = HcommCcuInsResDescQueryNum( | ||
| 80 | + queryDesc, HCOMM_CCU_RES_TYPE_LOOP, &loopNum); | ||
| 81 | + | ||
| 82 | +HcommCcuInsResDescDestroy(queryDesc); | ||
| 83 | +return ret; | ||
| 84 | +``` | ||
| @@ -0,0 +1,82 @@ | |||
| 1 | +# HcommCcuInsResDescCreate | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +创建空白 CCU 资源描述符。资源描述符用于描述 CCU 实例所需的各类资源(loop、buffer、variable、address、event、thread、instruction)的数量规格,不包含实际资源。 | ||
| 24 | + | ||
| 25 | +一个资源描述符对应一个 IO Die。创建后其内部各资源类型的数量初始化为 0,后续可通过 `HcommCcuInsResDescSetNum` 逐类型设置。 | ||
| 26 | + | ||
| 27 | +## 函数原型 | ||
| 28 | + | ||
| 29 | +// ccu_res.h | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +CcuResult HcommCcuInsResDescCreate(uint32_t dieId, HcommCcuResDescHandle *resDesc); | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +## 参数说明 | ||
| 36 | + | ||
| 37 | +| 参数名 | 输入/输出 | 描述 | | ||
| 38 | +| --- | --- | --- | | ||
| 39 | +| dieId | 输入 | 资源描述符归属的 IO Die 编号,取值范围 `[0, CCU_MAX_IODIE_NUM)`。 | | ||
| 40 | +| resDesc | 输出 | 创建成功后返回的资源描述符句柄,不能为空指针。调用方负责通过 `HcommCcuInsResDescDestroy` 销毁。 | | ||
| 41 | + | ||
| 42 | +## 返回值 | ||
| 43 | + | ||
| 44 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回 `CCU_SUCCESS`,其他值表示失败。 | ||
| 45 | + | ||
| 46 | +| 返回值 | 说明 | | ||
| 47 | +| --- | --- | | ||
| 48 | +| `CCU_SUCCESS` | 创建成功,`*resDesc` 为有效的资源描述符句柄。 | | ||
| 49 | +| `CCU_E_PARA` | `dieId` 超出合法范围(`>= CCU_MAX_IODIE_NUM`)。 | | ||
| 50 | +| `CCU_E_PTR` | `resDesc` 为空指针。 | | ||
| 51 | +| `CCU_E_INTERNAL` | 内存分配或内部注册失败。 | | ||
| 52 | + | ||
| 53 | +## 约束说明 | ||
| 54 | + | ||
| 55 | +- 调用本接口前须通过 AscendCL 接口 `aclrtSetDevice(int32_t deviceId)` 绑定当前线程到目标 NPU Device,本接口从当前线程获取设备上下文。 | ||
| 56 | +- 创建成功后,调用方须在不再使用时通过 `HcommCcuInsResDescDestroy` 销毁该描述符,避免资源泄漏。 | ||
| 57 | +- 资源描述符不能跨线程共享。调用方须保证同一描述符的访问串行执行。 | ||
| 58 | +- 本接口只能在主机侧调用。 | ||
| 59 | + | ||
| 60 | +## 依赖关系 | ||
| 61 | + | ||
| 62 | +- 依赖 `HcommCcuInsResDescDestroy` 销毁描述符。 | ||
| 63 | +- 依赖 `HcommCcuInsResDescSetNum` 设置资源数量。 | ||
| 64 | +- 依赖 `HcommCcuInsResDescQueryNum` / `HcommCcuInsResDescQueryDieId` / `HcommCcuQueryRemainResDesc` 查询描述符信息。 | ||
| 65 | + | ||
| 66 | +## 调用示例 | ||
| 67 | + | ||
| 68 | +```c | ||
| 69 | +uint32_t dieId = 0; | ||
| 70 | +HcommCcuResDescHandle resDesc = 0; | ||
| 71 | +CcuResult ret = HcommCcuInsResDescCreate(dieId, &resDesc); | ||
| 72 | +if (ret != CCU_SUCCESS) { | ||
| 73 | + // 错误处理 | ||
| 74 | + return ret; | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +// 使用 resDesc 设置资源规格、查询剩余资源等 ... | ||
| 78 | +// ... | ||
| 79 | + | ||
| 80 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 81 | +return CCU_SUCCESS; | ||
| 82 | +``` | ||
| @@ -0,0 +1,70 @@ | |||
| 1 | +# HcommCcuInsResDescDestroy | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +销毁由 `HcommCcuInsResDescCreate` 创建的 CCU 资源描述符,释放其占用的内存。销毁后该句柄失效,不应再使用。 | ||
| 24 | + | ||
| 25 | +## 函数原型 | ||
| 26 | + | ||
| 27 | +// ccu_res.h | ||
| 28 | + | ||
| 29 | +```c | ||
| 30 | +CcuResult HcommCcuInsResDescDestroy(HcommCcuResDescHandle resDesc); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## 参数说明 | ||
| 34 | + | ||
| 35 | +| 参数名 | 输入/输出 | 描述 | | ||
| 36 | +| --- | --- | --- | | ||
| 37 | +| resDesc | 输入 | 资源描述符句柄,由 `HcommCcuInsResDescCreate` 创建。 | | ||
| 38 | + | ||
| 39 | +## 返回值 | ||
| 40 | + | ||
| 41 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回 `CCU_SUCCESS`,其他值表示失败。 | ||
| 42 | + | ||
| 43 | +| 返回值 | 说明 | | ||
| 44 | +| --- | --- | | ||
| 45 | +| `CCU_SUCCESS` | 销毁成功。 | | ||
| 46 | +| `CCU_E_NOT_FOUND` | `resDesc` 未注册,或已被销毁。 | | ||
| 47 | + | ||
| 48 | +## 约束说明 | ||
| 49 | + | ||
| 50 | +- 销毁后该句柄永久失效,不可再用于任何接口。重复销毁将返回 `CCU_E_NOT_FOUND`。 | ||
| 51 | +- 本接口只能在主机侧调用。 | ||
| 52 | + | ||
| 53 | +## 依赖关系 | ||
| 54 | + | ||
| 55 | +- 依赖 `HcommCcuInsResDescCreate` 创建的资源描述符句柄。 | ||
| 56 | + | ||
| 57 | +## 调用示例 | ||
| 58 | + | ||
| 59 | +```c | ||
| 60 | +HcommCcuResDescHandle resDesc = 0; | ||
| 61 | +CcuResult ret = HcommCcuInsResDescCreate(0, &resDesc); | ||
| 62 | +if (ret != CCU_SUCCESS) { | ||
| 63 | + return ret; | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +// 使用 resDesc ... | ||
| 67 | + | ||
| 68 | +ret = HcommCcuInsResDescDestroy(resDesc); | ||
| 69 | +return ret; | ||
| 70 | +``` | ||
| @@ -0,0 +1,75 @@ | |||
| 1 | +# HcommCcuInsResDescQueryDieId | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +查询 CCU 资源描述符归属的 IO Die 编号。 | ||
| 24 | + | ||
| 25 | +## 函数原型 | ||
| 26 | + | ||
| 27 | +// ccu_res.h | ||
| 28 | + | ||
| 29 | +```c | ||
| 30 | +CcuResult HcommCcuInsResDescQueryDieId(HcommCcuResDescHandle resDesc, uint32_t *dieId); | ||
| 31 | +``` | ||
| 32 | + | ||
| 33 | +## 参数说明 | ||
| 34 | + | ||
| 35 | +| 参数名 | 输入/输出 | 描述 | | ||
| 36 | +| --- | --- | --- | | ||
| 37 | +| resDesc | 输入 | 资源描述符句柄,由 `HcommCcuInsResDescCreate` 创建。 | | ||
| 38 | +| dieId | 输出 | 查询成功后返回创建描述符时指定的 IO Die 编号,不能为空指针。 | | ||
| 39 | + | ||
| 40 | +## 返回值 | ||
| 41 | + | ||
| 42 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回 `CCU_SUCCESS`,其他值表示失败。 | ||
| 43 | + | ||
| 44 | +| 返回值 | 说明 | | ||
| 45 | +| --- | --- | | ||
| 46 | +| `CCU_SUCCESS` | 查询成功,`*dieId` 为描述符归属的 IO Die 编号。 | | ||
| 47 | +| `CCU_E_PTR` | `dieId` 为空指针。 | | ||
| 48 | +| `CCU_E_NOT_FOUND` | `resDesc` 未注册。 | | ||
| 49 | + | ||
| 50 | +## 约束说明 | ||
| 51 | + | ||
| 52 | +- 调用本接口前须通过 `HcommCcuInsResDescCreate` 创建资源描述符。 | ||
| 53 | +- 本接口只能在主机侧调用。 | ||
| 54 | + | ||
| 55 | +## 依赖关系 | ||
| 56 | + | ||
| 57 | +- 依赖 `HcommCcuInsResDescCreate` 创建的资源描述符句柄。 | ||
| 58 | +- 供 `HcommCcuQueryRemainResDesc` 内部获取 die ID 以查询对应 Die 的剩余资源。 | ||
| 59 | + | ||
| 60 | +## 调用示例 | ||
| 61 | + | ||
| 62 | +```c | ||
| 63 | +HcommCcuResDescHandle resDesc = 0; | ||
| 64 | +CcuResult ret = HcommCcuInsResDescCreate(1, &resDesc); | ||
| 65 | +if (ret != CCU_SUCCESS) { | ||
| 66 | + return ret; | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +uint32_t dieId = 0; | ||
| 70 | +ret = HcommCcuInsResDescQueryDieId(resDesc, &dieId); | ||
| 71 | +// dieId == 1 | ||
| 72 | + | ||
| 73 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 74 | +return ret; | ||
| 75 | +``` | ||
| @@ -0,0 +1,81 @@ | |||
| 1 | +# HcommCcuInsResDescQueryNum | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +按资源类型查询 CCU 资源描述符中已设置的资源数量。 | ||
| 24 | + | ||
| 25 | +## 函数原型 | ||
| 26 | + | ||
| 27 | +// ccu_res.h | ||
| 28 | + | ||
| 29 | +```c | ||
| 30 | +CcuResult HcommCcuInsResDescQueryNum(HcommCcuResDescHandle resDesc, | ||
| 31 | + HcommCcuResType resType, uint32_t *resNum); | ||
| 32 | +``` | ||
| 33 | + | ||
| 34 | +## 参数说明 | ||
| 35 | + | ||
| 36 | +| 参数名 | 输入/输出 | 描述 | | ||
| 37 | +| --- | --- | --- | | ||
| 38 | +| resDesc | 输入 | 资源描述符句柄,由 `HcommCcuInsResDescCreate` 创建。 | | ||
| 39 | +| resType | 输入 | 资源类型,取 `HcommCcuResType` 枚举值。 | | ||
| 40 | +| resNum | 输出 | 查询成功后返回该资源类型已设置的数量,不能为空指针。 | | ||
| 41 | + | ||
| 42 | +## 返回值 | ||
| 43 | + | ||
| 44 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回 `CCU_SUCCESS`,其他值表示失败。 | ||
| 45 | + | ||
| 46 | +| 返回值 | 说明 | | ||
| 47 | +| --- | --- | | ||
| 48 | +| `CCU_SUCCESS` | 查询成功,`*resNum` 为已设置的资源数量。 | | ||
| 49 | +| `CCU_E_PARA` | `resType` 超出合法范围。 | | ||
| 50 | +| `CCU_E_PTR` | `resNum` 为空指针。 | | ||
| 51 | +| `CCU_E_NOT_FOUND` | `resDesc` 未注册。 | | ||
| 52 | + | ||
| 53 | +## 约束说明 | ||
| 54 | + | ||
| 55 | +- 调用本接口前须通过 `HcommCcuInsResDescCreate` 创建资源描述符。 | ||
| 56 | +- 若从未调用 `HcommCcuInsResDescSetNum` 设置该资源类型,则查询结果为 0。 | ||
| 57 | +- 本接口只能在主机侧调用。 | ||
| 58 | + | ||
| 59 | +## 依赖关系 | ||
| 60 | + | ||
| 61 | +- 依赖 `HcommCcuInsResDescCreate` 创建的资源描述符句柄。 | ||
| 62 | +- 依赖 `HcommCcuInsResDescSetNum` 设置资源数量。 | ||
| 63 | + | ||
| 64 | +## 调用示例 | ||
| 65 | + | ||
| 66 | +```c | ||
| 67 | +HcommCcuResDescHandle resDesc = 0; | ||
| 68 | +CcuResult ret = HcommCcuInsResDescCreate(0, &resDesc); | ||
| 69 | +if (ret != CCU_SUCCESS) { | ||
| 70 | + return ret; | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +HcommCcuInsResDescSetNum(resDesc, HCOMM_CCU_RES_TYPE_LOOP, 8); | ||
| 74 | + | ||
| 75 | +uint32_t loopNum = 0; | ||
| 76 | +ret = HcommCcuInsResDescQueryNum(resDesc, HCOMM_CCU_RES_TYPE_LOOP, &loopNum); | ||
| 77 | +// loopNum == 8 | ||
| 78 | + | ||
| 79 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 80 | +return ret; | ||
| 81 | +``` | ||
| @@ -0,0 +1,83 @@ | |||
| 1 | +# HcommCcuInsResDescSetNum | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +按资源类型设置 CCU 资源描述符中的资源数量。可多次调用逐类型设置期望值。设置为 0 表示不申请该类型资源。 | ||
| 24 | + | ||
| 25 | +## 函数原型 | ||
| 26 | + | ||
| 27 | +// ccu_res.h | ||
| 28 | + | ||
| 29 | +```c | ||
| 30 | +CcuResult HcommCcuInsResDescSetNum(HcommCcuResDescHandle resDesc, | ||
| 31 | + HcommCcuResType resType, uint32_t resNum); | ||
| 32 | +``` | ||
| 33 | + | ||
| 34 | +## 参数说明 | ||
| 35 | + | ||
| 36 | +| 参数名 | 输入/输出 | 描述 | | ||
| 37 | +| --- | --- | --- | | ||
| 38 | +| resDesc | 输入/输出 | 资源描述符句柄,由 `HcommCcuInsResDescCreate` 创建。设置成功后,指定资源类型的数量更新为`resNum`。 | | ||
| 39 | +| resType | 输入 | 资源类型,取 `HcommCcuResType` 枚举值。合法值:`HCOMM_CCU_RES_TYPE_LOOP`、`HCOMM_CCU_RES_TYPE_CCU_BUF`、`HCOMM_CCU_RES_TYPE_VARIABLE`、`HCOMM_CCU_RES_TYPE_ADDRESS`、`HCOMM_CCU_RES_TYPE_EVENT`、`HCOMM_CCU_RES_TYPE_CCU_THREAD`、`HCOMM_CCU_RES_TYPE_INSTRUCTION`。 | | ||
| 40 | +| resNum | 输入 | 期望的资源数量。设置为 0 表示不申请该类型资源。 | | ||
| 41 | + | ||
| 42 | +## 返回值 | ||
| 43 | + | ||
| 44 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回 `CCU_SUCCESS`,其他值表示失败。 | ||
| 45 | + | ||
| 46 | +| 返回值 | 说明 | | ||
| 47 | +| --- | --- | | ||
| 48 | +| `CCU_SUCCESS` | 设置成功。 | | ||
| 49 | +| `CCU_E_PARA` | `resType` 超出合法范围。 | | ||
| 50 | +| `CCU_E_NOT_FOUND` | `resDesc` 未注册。 | | ||
| 51 | + | ||
| 52 | +## 约束说明 | ||
| 53 | + | ||
| 54 | +- 调用本接口前须通过 `HcommCcuInsResDescCreate` 创建资源描述符。 | ||
| 55 | +- 多次调用本接口对同一资源类型进行设置,后一次的值覆盖前一次的值。 | ||
| 56 | +- 本接口为纯数据写入操作,不校验 `resNum` 是否超过硬件容量上限。容量校验在使用描述符创建 CCU 实例或查询剩余资源时进行。 | ||
| 57 | +- 本接口只能在主机侧调用。 | ||
| 58 | + | ||
| 59 | +## 依赖关系 | ||
| 60 | + | ||
| 61 | +- 依赖 `HcommCcuInsResDescCreate` 创建的资源描述符句柄。 | ||
| 62 | +- 依赖 `HcommCcuInsResDescQueryNum` 查询已设置的资源数量。 | ||
| 63 | +- 配合 `HcommCcuQueryRemainResDesc` 使用:先查询剩余资源,再按需调整描述符中的资源数量。 | ||
| 64 | + | ||
| 65 | +## 调用示例 | ||
| 66 | + | ||
| 67 | +```c | ||
| 68 | +HcommCcuResDescHandle resDesc = 0; | ||
| 69 | +CcuResult ret = HcommCcuInsResDescCreate(0, &resDesc); | ||
| 70 | +if (ret != CCU_SUCCESS) { | ||
| 71 | + return ret; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +ret = HcommCcuInsResDescSetNum(resDesc, HCOMM_CCU_RES_TYPE_LOOP, 8); | ||
| 75 | +if (ret != CCU_SUCCESS) { | ||
| 76 | + HcommCcuInsResDescDestroy(resDesc); | ||
| 77 | + return ret; | ||
| 78 | +} | ||
| 79 | +ret = HcommCcuInsResDescSetNum(resDesc, HCOMM_CCU_RES_TYPE_CCU_BUF, 16); | ||
| 80 | + | ||
| 81 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 82 | +return ret; | ||
| 83 | +``` | ||
| @@ -0,0 +1,110 @@ | |||
| 1 | +# HcommCcuKernelQueryResReq | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +在创建CCU实例前查询指定CCU Kernel的资源诉求。接口在主机侧对`kernelFunc`执行一次dry-run,将统计得到的各类资源数量写入调用方预先创建的资源描述符`resDesc`。 | ||
| 24 | + | ||
| 25 | +查询过程会执行Kernel函数及其既有的Channel检查和选die逻辑,但不会注册Kernel、申请CCU实例资源、生成Kernel句柄、翻译指令或下发任务。 | ||
| 26 | + | ||
| 27 | +## 函数原型 | ||
| 28 | + | ||
| 29 | +// ccu_res.h | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +CcuResult HcommCcuKernelQueryResReq(const void *kernelFunc, | ||
| 33 | + const void **kernelArgs, uint32_t argNum, HcommCcuResDescHandle resDesc); | ||
| 34 | +``` | ||
| 35 | + | ||
| 36 | +## 参数说明 | ||
| 37 | + | ||
| 38 | +| 参数名 | 输入/输出 | 描述 | | ||
| 39 | +| --- | --- | --- | | ||
| 40 | +| kernelFunc | 输入 | CCU Kernel函数指针,不能为空指针。`argNum`为`0`时,函数签名须与无入参Kernel一致;`argNum`为`1`时,函数签名须与单入参Kernel一致。 | | ||
| 41 | +| kernelArgs | 输入 | Kernel函数入参指针数组。`argNum`为`0`时该参数被忽略,可传入空指针;`argNum`为`1`时不能为空指针,且`kernelArgs[0]`也不能为空指针。 | | ||
| 42 | +| argNum | 输入 | Kernel函数入参个数。当前仅支持`0`或`1`。 | | ||
| 43 | +| resDesc | 输入/输出 | CCU资源描述符句柄。须由`HcommCcuInsResDescCreate`预先创建,不能为`0`。查询成功后,接口将本次统计的资源数量写入该描述符,并保留创建描述符时设置的die ID。 | | ||
| 44 | + | ||
| 45 | +## 返回值 | ||
| 46 | + | ||
| 47 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回`CCU_SUCCESS`,其他值表示失败。 | ||
| 48 | + | ||
| 49 | +| 返回值 | 说明 | | ||
| 50 | +| --- | --- | | ||
| 51 | +| `CCU_SUCCESS` | 查询成功,Kernel资源诉求已写入`resDesc`。 | | ||
| 52 | +| `CCU_E_PTR` | `kernelFunc`为空指针;或`argNum`为`1`时,`kernelArgs`或`kernelArgs[0]`为空指针。 | | ||
| 53 | +| `CCU_E_PARA` | `argNum`大于`1`、`resDesc`为`0`、描述符中的die ID非法,或Kernel根据Channel选择的die与描述符中的die ID不一致。 | | ||
| 54 | +| `CCU_E_NOT_FOUND` | 未找到`resDesc`对应的资源描述符,或Kernel使用的Channel不存在。 | | ||
| 55 | +| `CCU_E_INTERNAL` | Kernel dry-run或资源数量写入过程中发生内部错误。 | | ||
| 56 | +| 其他错误码 | Kernel执行、Channel检查或选die过程中产生的其他错误。 | | ||
| 57 | + | ||
| 58 | +## 约束说明 | ||
| 59 | + | ||
| 60 | +- 调用本接口前,须通过`HcommCcuInsResDescCreate`创建`resDesc`。调用结束后,调用方负责通过`HcommCcuInsResDescDestroy`销毁该描述符。 | ||
| 61 | +- 如果Kernel使用Channel,须提前通过[HcclChannelAcquire](../comms_domain_resource_mgmt/HcclChannelAcquire.md)获取`COMM_ENGINE_CCU`类型的Channel,并保证Channel在查询期间有效。 | ||
| 62 | +- 调用`HcommCcuInsResDescCreate`创建`resDesc`与调用本接口时,当前线程须绑定同一NPU Device,即两次调用获取到的`deviceLogicId`必须一致。调用方可在相应线程中调用AscendCL接口`aclrtSetDevice(int32_t deviceId)`指定该线程使用的Device。本接口从当前线程获取`deviceLogicId`,不从`resDesc`推导设备信息,不支持跨Device使用资源描述符。Kernel使用的Channel必须位于同一die,且选出的die须与创建`resDesc`时指定的die ID一致。 | ||
| 63 | +- 本接口不支持多线程并发调用。调用方须保证不同线程对本接口的调用串行执行。 | ||
| 64 | +- 查询成功时,本次统计结果覆盖`resDesc`中已有的资源数量,不修改其die ID。 | ||
| 65 | +- Kernel dry-run失败时不会写入资源数量。写入资源数量的过程中如果发生错误,接口立即返回,已经写入的资源类型不会回滚。 | ||
| 66 | +- 本接口只能在主机侧调用,不能在Kernel函数体内调用。 | ||
| 67 | + | ||
| 68 | +## 调用示例 | ||
| 69 | + | ||
| 70 | +```c | ||
| 71 | +typedef struct { | ||
| 72 | + ChannelHandle channel; | ||
| 73 | + uint32_t loopCount; | ||
| 74 | +} MyKernelArg; | ||
| 75 | + | ||
| 76 | +CcuResult MyKernel(CcuKernelArg arg) | ||
| 77 | +{ | ||
| 78 | + MyKernelArg *kernelArg = (MyKernelArg *)arg; | ||
| 79 | + // 使用kernelArg->channel和CCU数据面接口描述Kernel操作序列。 | ||
| 80 | + // ... | ||
| 81 | + return CCU_SUCCESS; | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +uint32_t dieId = 0; | ||
| 85 | +HcommCcuResDescHandle resDesc = 0; | ||
| 86 | +CcuResult ret = HcommCcuInsResDescCreate(dieId, &resDesc); | ||
| 87 | +if (ret != CCU_SUCCESS) { | ||
| 88 | + return ret; | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +// channel须提前通过HcclChannelAcquire获取,并与dieId对应。 | ||
| 92 | +ChannelHandle channel = 0; | ||
| 93 | +// ... 此处省略HcclChannelAcquire调用 ... | ||
| 94 | + | ||
| 95 | +MyKernelArg kernelArg = { .channel = channel, .loopCount = 10 }; | ||
| 96 | +const void *kernelArgs[] = { &kernelArg }; | ||
| 97 | +ret = HcommCcuKernelQueryResReq( | ||
| 98 | + (const void *)MyKernel, kernelArgs, 1, resDesc); | ||
| 99 | +if (ret != CCU_SUCCESS) { | ||
| 100 | + HcommCcuInsResDescDestroy(resDesc); | ||
| 101 | + return ret; | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +uint32_t instructionNum = 0; | ||
| 105 | +ret = HcommCcuInsResDescQueryNum( | ||
| 106 | + resDesc, HCOMM_CCU_RES_TYPE_INSTRUCTION, &instructionNum); | ||
| 107 | + | ||
| 108 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 109 | +return ret; | ||
| 110 | +``` | ||
| @@ -0,0 +1,94 @@ | |||
| 1 | +# HcommCcuQueryRemainResDesc | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +查询CCU资源描述符对应IO Die上的最大连续剩余资源数量,并将各类资源的查询结果写入该描述符。 | ||
| 24 | + | ||
| 25 | +调用后可通过`HcommCcuInsResDescQueryNum`查询各类资源的剩余数量,也可在查询结果的基础上调整申请数量并创建CCU实例。 | ||
| 26 | + | ||
| 27 | +## 函数原型 | ||
| 28 | + | ||
| 29 | +// ccu_res.h | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +CcuResult HcommCcuQueryRemainResDesc(HcommCcuResDescHandle resDesc); | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +## 参数说明 | ||
| 36 | + | ||
| 37 | +| 参数名 | 输入/输出 | 描述 | | ||
| 38 | +| --- | --- | --- | | ||
| 39 | +| resDesc | 输入/输出 | 资源描述符句柄,由`HcommCcuInsResDescCreate`创建。创建时指定的`dieId`用于选择待查询的IO Die,查询结果覆盖描述符中原有的资源数量。 | | ||
| 40 | + | ||
| 41 | +## 返回值 | ||
| 42 | + | ||
| 43 | +[CcuResult](../../datatype_definition/CcuResult.md):接口成功返回 `CCU_SUCCESS`,其他值表示失败。 | ||
| 44 | + | ||
| 45 | +| 返回值 | 说明 | | ||
| 46 | +| --- | --- | | ||
| 47 | +| `CCU_SUCCESS` | 查询成功,各类资源的最大连续剩余数量已写入`resDesc`。 | | ||
| 48 | +| `CCU_E_PARA` | `resDesc`对应的描述符中IO Die编号超出合法范围。 | | ||
| 49 | +| `CCU_E_NOT_FOUND` | `resDesc`未注册。 | | ||
| 50 | +| `CCU_E_UNAVAIL` | 指定的 IO Die 未使能。 | | ||
| 51 | +| `CCU_E_INTERNAL` | 查询过程中发生内部错误(如资源规格查询失败)。 | | ||
| 52 | + | ||
| 53 | +## 约束说明 | ||
| 54 | + | ||
| 55 | +- 调用本接口前须通过`HcommCcuInsResDescCreate`创建资源描述符。 | ||
| 56 | +- 创建`resDesc`与调用本接口时,当前线程须绑定到同一NPU Device。 | ||
| 57 | +- 调用方须保证查询期间不并发修改或销毁`resDesc`。 | ||
| 58 | +- 查询结果覆盖描述符中已有的资源数量。如需保留原始设置值,调用方应在调用前自行备份。 | ||
| 59 | +- 本接口只能在主机侧调用,不能在Kernel函数体内调用。 | ||
| 60 | + | ||
| 61 | +## 依赖关系 | ||
| 62 | + | ||
| 63 | +- 依赖`HcommCcuInsResDescCreate`创建的资源描述符句柄。 | ||
| 64 | +- 配合`HcommCcuInsResDescQueryNum`使用:查询返回后通过QueryNum读取各资源类型的剩余数量。 | ||
| 65 | + | ||
| 66 | +## 调用示例 | ||
| 67 | + | ||
| 68 | +```c | ||
| 69 | +uint32_t dieId = 0; | ||
| 70 | +HcommCcuResDescHandle resDesc = 0; | ||
| 71 | +CcuResult ret = HcommCcuInsResDescCreate(dieId, &resDesc); | ||
| 72 | +if (ret != CCU_SUCCESS) { | ||
| 73 | + return ret; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +// 查询 dieId 对应 IO Die 上的剩余资源 | ||
| 77 | +ret = HcommCcuQueryRemainResDesc(resDesc); | ||
| 78 | +if (ret != CCU_SUCCESS) { | ||
| 79 | + HcommCcuInsResDescDestroy(resDesc); | ||
| 80 | + return ret; | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +// 读取各资源类型的剩余数量 | ||
| 84 | +uint32_t loopRemain = 0; | ||
| 85 | +HcommCcuInsResDescQueryNum(resDesc, HCOMM_CCU_RES_TYPE_LOOP, &loopRemain); | ||
| 86 | + | ||
| 87 | +// 如需设置特定的资源规格,可在剩余量基础上调整 | ||
| 88 | +HcommCcuInsResDescSetNum(resDesc, HCOMM_CCU_RES_TYPE_LOOP, loopRemain / 2); | ||
| 89 | + | ||
| 90 | +// 基于调整后的描述符创建 CCU 实例(略) | ||
| 91 | + | ||
| 92 | +HcommCcuInsResDescDestroy(resDesc); | ||
| 93 | +return ret; | ||
| 94 | +``` | ||
| @@ -0,0 +1,28 @@ | |||
| 1 | +# CCU 资源管理 | ||
| 2 | + | ||
| 3 | +CCU资源管理接口用于查询和描述CCU资源诉求、按需创建CCU实例、查询实例资源占用,以及销毁调用方持有的实例。 | ||
| 4 | + | ||
| 5 | +## 资源描述符 | ||
| 6 | + | ||
| 7 | +- [HcommCcuInsResDescCreate](HcommCcuInsResDescCreate.md) | ||
| 8 | +- [HcommCcuInsResDescDestroy](HcommCcuInsResDescDestroy.md) | ||
| 9 | +- [HcommCcuInsResDescSetNum](HcommCcuInsResDescSetNum.md) | ||
| 10 | +- [HcommCcuInsResDescQueryNum](HcommCcuInsResDescQueryNum.md) | ||
| 11 | +- [HcommCcuInsResDescQueryDieId](HcommCcuInsResDescQueryDieId.md) | ||
| 12 | +- [HcommCcuKernelQueryResReq](HcommCcuKernelQueryResReq.md) | ||
| 13 | +- [HcommCcuQueryRemainResDesc](HcommCcuQueryRemainResDesc.md) | ||
| 14 | + | ||
| 15 | +## CCU实例 | ||
| 16 | + | ||
| 17 | +- [HcommCcuInsCreate](HcommCcuInsCreate.md) | ||
| 18 | +- [HcommCcuInsCreateDefault](HcommCcuInsCreateDefault.md) | ||
| 19 | +- [HcommCcuInsQueryResDesc](HcommCcuInsQueryResDesc.md) | ||
| 20 | +- [HcommCcuInsDestroy](HcommCcuInsDestroy.md) | ||
| 21 | + | ||
| 22 | +按需创建CCU实例的典型流程如下: | ||
| 23 | + | ||
| 24 | +1. 调用[HcommCcuInsResDescCreate](HcommCcuInsResDescCreate.md)为目标IO Die创建资源描述符。 | ||
| 25 | +2. 调用[HcommCcuKernelQueryResReq](HcommCcuKernelQueryResReq.md)统计Kernel资源诉求,或调用[HcommCcuInsResDescSetNum](HcommCcuInsResDescSetNum.md)直接设置资源数量。 | ||
| 26 | +3. 调用[HcommCcuInsCreate](HcommCcuInsCreate.md)创建CCU实例。 | ||
| 27 | +4. 可调用[HcommCcuInsQueryResDesc](HcommCcuInsQueryResDesc.md)查询实例实际占用的资源数量。 | ||
| 28 | +5. 不再使用实例时,调用[HcommCcuInsDestroy](HcommCcuInsDestroy.md)销毁;若通过[HcclCommAssignCcuIns](../comms_domain_resource_mgmt/HcclCommAssignCcuIns.md)成功绑定到通信域,则由通信域管理实例生命周期。 | ||
| @@ -0,0 +1,93 @@ | |||
| 1 | +# HcclCommAssignCcuIns | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- Ascend 950PR/Ascend 950DT:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="910" id4 --> | ||
| 15 | +- Atlas 训练系列产品:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- Atlas 推理系列产品:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | + | ||
| 21 | +## 功能说明 | ||
| 22 | + | ||
| 23 | +将调用方已创建的CCU实例绑定到指定HCCL通信域。绑定成功后,通信域保存该实例句柄,并接管CCU实例的所有权和销毁责任;后续可通过`HcclCommQueryCcuIns`查询该实例。 | ||
| 24 | + | ||
| 25 | +每个通信域只能绑定一个CCU实例。通信域已有绑定实例时,本接口不会覆盖原实例。 | ||
| 26 | + | ||
| 27 | +## 函数原型 | ||
| 28 | + | ||
| 29 | +// hccl_ccu_res.h | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +HcclResult HcclCommAssignCcuIns(HcclComm comm, CcuInsHandle insHandle); | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +## 参数说明 | ||
| 36 | + | ||
| 37 | +| 参数名 | 输入/输出 | 描述 | | ||
| 38 | +| --- | --- | --- | | ||
| 39 | +| comm | 输入 | HCCL通信域句柄,不能为空指针。HcclComm类型的定义可参见[HcclComm](../../../comm_mgr_c/data_type_definition/HcclComm.md)。 | | ||
| 40 | +| insHandle | 输入 | 待绑定的CCU实例句柄,不能为`0`。实例须由`HcommCcuInsCreate`或`HcommCcuInsCreateDefault`在当前Device上创建。CcuInsHandle类型的定义可参见[CcuInsHandle](../../datatype_definition/CcuInsHandle.md)。 | | ||
| 41 | + | ||
| 42 | +## 返回值 | ||
| 43 | + | ||
| 44 | +[HcclResult](../../../comm_mgr_c/data_type_definition/HcclResult.md):接口成功返回`HCCL_SUCCESS`,其他值表示失败。 | ||
| 45 | + | ||
| 46 | +| 返回值 | 说明 | | ||
| 47 | +| --- | --- | | ||
| 48 | +| `HCCL_SUCCESS` | 绑定成功,`insHandle`的所有权和销毁责任转移给通信域。 | | ||
| 49 | +| `HCCL_E_PTR` | `comm`为空指针,或通信域内部对象为空。 | | ||
| 50 | +| `HCCL_E_PARA` | `insHandle`为`0`,或通信域已经绑定CCU实例。 | | ||
| 51 | +| `HCCL_E_NOT_SUPPORT` | 通信域代际不支持CCU(早于Ascend 950PR/Ascend 950DT)。 | | ||
| 52 | +| `HCCL_E_NOT_FOUND` | 当前Device上不存在`insHandle`对应的CCU实例。 | | ||
| 53 | +| `HCCL_E_INTERNAL` | 发生其他内部错误。 | | ||
| 54 | + | ||
| 55 | +## 约束说明 | ||
| 56 | + | ||
| 57 | +- 绑定成功后,调用方不得再调用`HcommCcuInsDestroy`销毁`insHandle`。通信域销毁时会销毁已绑定的CCU实例。 | ||
| 58 | +- 绑定失败时,`insHandle`的所有权仍归调用方,调用方负责继续使用或销毁该实例。 | ||
| 59 | +- 同一个`insHandle`只能绑定到一个通信域,不得重复绑定到其他通信域。 | ||
| 60 | +- 同一个通信域不支持重复绑定。无论新旧句柄是否相同,再次调用本接口均返回`HCCL_E_PARA`,原绑定关系保持不变。 | ||
| 61 | +- 本接口只保证多个`HcclCommAssignCcuIns`调用之间的并发安全。调用方须保证本接口不与`HcclCommQueryCcuIns`或`HcclCommDestroy`并发执行。 | ||
| 62 | +- `insHandle`须在`comm`所在的当前Device上创建。 | ||
| 63 | + | ||
| 64 | +## 调用示例 | ||
| 65 | + | ||
| 66 | +```c | ||
| 67 | +CcuInsHandle insHandle = 0; | ||
| 68 | +// dieIds和dieNum为保留参数,当前版本分别传入NULL和0。 | ||
| 69 | +CcuResult ccuRet = HcommCcuInsCreateDefault(NULL, 0, &insHandle); | ||
| 70 | +if (ccuRet != CCU_SUCCESS) { | ||
| 71 | + return ccuRet; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +HcclResult hcclRet = HcclCommAssignCcuIns(comm, insHandle); | ||
| 75 | +if (hcclRet != HCCL_SUCCESS) { | ||
| 76 | + // 绑定失败,实例所有权仍归调用方。 | ||
| 77 | + HcommCcuInsDestroy(insHandle); | ||
| 78 | + return hcclRet; | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +// 绑定成功,实例所有权已转移给通信域,调用方不再销毁insHandle。 | ||
| 82 | +CcuInsHandle queriedInsHandle = 0; | ||
| 83 | +uint32_t insNum = 0; | ||
| 84 | +hcclRet = HcclCommQueryCcuIns(comm, &queriedInsHandle, &insNum); | ||
| 85 | +if (hcclRet != HCCL_SUCCESS || insNum != 1 || | ||
| 86 | + queriedInsHandle != insHandle) { | ||
| 87 | + HcclCommDestroy(comm); | ||
| 88 | + return HCCL_E_INTERNAL; | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +// 销毁通信域时,由通信域销毁已绑定的CCU实例。 | ||
| 92 | +return HcclCommDestroy(comm); | ||
| 93 | +``` | ||
| @@ -17,4 +17,5 @@ | |||
| 17 | - [HcclEngineCtxCopy](HcclEngineCtxCopy.md) | 17 | - [HcclEngineCtxCopy](HcclEngineCtxCopy.md) |
| 18 | - [HcclEngineCtxDestroy](HcclEngineCtxDestroy.md) | 18 | - [HcclEngineCtxDestroy](HcclEngineCtxDestroy.md) |
| 19 | - [HcclCommMemReg](HcclCommMemReg.md) | 19 | - [HcclCommMemReg](HcclCommMemReg.md) |
| 20 | +- [HcclCommAssignCcuIns](HcclCommAssignCcuIns.md) | ||
| 20 | - [HcclCommQueryCcuIns](HcclCommQueryCcuIns.md) | 21 | - [HcclCommQueryCcuIns](HcclCommQueryCcuIns.md) |
| @@ -19,44 +19,55 @@ extern "C" { | |||
| 19 | #endif // __cplusplus | 19 | #endif // __cplusplus |
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | - * @brief 创建空白 CCU 资源描述符。 | 22 | + * @brief 创建 CCU 实例资源描述符 |
| 23 | - * @param[in] dieId CCU 资源描述符归属的 ioDie ID。 | 23 | + * @param[in] dieId IO Die 编号,取值范围 [0, CCU_MAX_IODIE_NUM) |
| 24 | - * @param[out] resDesc 创建成功后返回的资源描述符句柄,不可为 nullptr。 | 24 | + * @param[out] resDesc 输出指针,成功时写入 HcommCcuResDescHandle 句柄;调用方负责通过 |
| 25 | - * @return CcuResult。 | 25 | + * HcommCcuInsResDescDestroy 释放 |
| 26 | + * @return CCU_SUCCESS 创建成功 | ||
| 27 | + * CCU_E_PARA dieId 超出合法范围 | ||
| 28 | + * CCU_E_PTR resDesc 为 nullptr | ||
| 29 | + * CCU_E_INTERNAL 内部资源描述符创建或登记失败 | ||
| 26 | */ | 30 | */ |
| 27 | extern CcuResult HcommCcuInsResDescCreate(uint32_t dieId, HcommCcuResDescHandle *resDesc); | 31 | extern CcuResult HcommCcuInsResDescCreate(uint32_t dieId, HcommCcuResDescHandle *resDesc); |
| 28 | 32 | ||
| 29 | /** | 33 | /** |
| 30 | - * @brief 销毁 CCU 资源描述符。 | 34 | + * @brief 销毁 CCU 实例资源描述符 |
| 31 | - * @param[in] resDesc 资源描述符句柄。 | 35 | + * @param[in] resDesc 资源描述符句柄,由 HcommCcuInsResDescCreate 创建 |
| 32 | - * @return CcuResult。 | 36 | + * @return CCU_SUCCESS 销毁成功 |
| 37 | + * CCU_E_NOT_FOUND resDesc 未注册 | ||
| 33 | */ | 38 | */ |
| 34 | extern CcuResult HcommCcuInsResDescDestroy(HcommCcuResDescHandle resDesc); | 39 | extern CcuResult HcommCcuInsResDescDestroy(HcommCcuResDescHandle resDesc); |
| 35 | 40 | ||
| 36 | /** | 41 | /** |
| 37 | - * @brief 查询 CCU 资源描述符归属的 ioDie ID。 | 42 | + * @brief 查询 CCU 资源描述符中已设置的 Die ID |
| 38 | - * @param[in] resDesc 资源描述符句柄。 | 43 | + * @param[in] resDesc 资源描述符句柄 |
| 39 | - * @param[out] dieId 查询成功后返回 ioDie ID,不可为 nullptr。 | 44 | + * @param[out] dieId 输出指针,接收已设置的 Die ID |
| 40 | - * @return CcuResult。 | 45 | + * @return CCU_SUCCESS 查询成功 |
| 46 | + * CCU_E_PTR dieId 为 nullptr | ||
| 47 | + * CCU_E_NOT_FOUND resDesc 未注册 | ||
| 41 | */ | 48 | */ |
| 42 | extern CcuResult HcommCcuInsResDescQueryDieId(HcommCcuResDescHandle resDesc, uint32_t *dieId); | 49 | extern CcuResult HcommCcuInsResDescQueryDieId(HcommCcuResDescHandle resDesc, uint32_t *dieId); |
| 43 | 50 | ||
| 44 | /** | 51 | /** |
| 45 | - * @brief 设置指定 CCU 资源描述符内指定资源类型的资源数量。 | 52 | + * @brief 按资源类型设置 CCU 资源描述符中的资源数量 |
| 46 | - * @param[in] resDesc 资源描述符句柄。 | 53 | + * @param[in,out] resDesc 由 HcommCcuInsResDescCreate 创建的资源描述符句柄,成功时更新指定资源类型的资源数量 |
| 47 | - * @param[in] resType 资源类型。 | 54 | + * @param[in] resType 资源类型,取 HcommCcuResType 枚举值 |
| 48 | - * @param[in] resNum 资源数量。 | 55 | + * @param[in] resNum 期望的资源数量;设置为 0 表示不申请该类型资源 |
| 49 | - * @return CcuResult。 | 56 | + * @return CCU_SUCCESS 设置成功 |
| 57 | + * CCU_E_PARA resType 不是合法的 HcommCcuResType 枚举值 | ||
| 58 | + * CCU_E_NOT_FOUND resDesc 未注册 | ||
| 50 | */ | 59 | */ |
| 51 | -extern CcuResult HcommCcuInsResDescSetNum( | 60 | +extern CcuResult HcommCcuInsResDescSetNum(HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t resNum); |
| 52 | - HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t resNum); | ||
| 53 | 61 | ||
| 54 | /** | 62 | /** |
| 55 | - * @brief 查询指定 CCU 资源描述符内指定资源类型的资源数量。 | 63 | + * @brief 按资源类型查询 CCU 资源描述符中已设置的资源数量 |
| 56 | - * @param[in] resDesc 资源描述符句柄。 | 64 | + * @param[in] resDesc 资源描述符句柄 |
| 57 | - * @param[in] resType 资源类型。 | 65 | + * @param[in] resType 资源类型,取 HcommCcuResType 枚举值 |
| 58 | - * @param[out] resNum 查询成功后返回资源数量,不可为 nullptr。 | 66 | + * @param[out] resNum 输出指针,接收已设置的资源数量 |
| 59 | - * @return CcuResult。 | 67 | + * @return CCU_SUCCESS 查询成功 |
| 68 | + * CCU_E_PARA resType 超出合法范围 | ||
| 69 | + * CCU_E_PTR resNum 为 nullptr | ||
| 70 | + * CCU_E_NOT_FOUND resDesc 未注册 | ||
| 60 | */ | 71 | */ |
| 61 | extern CcuResult HcommCcuInsResDescQueryNum( | 72 | extern CcuResult HcommCcuInsResDescQueryNum( |
| 62 | HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t *resNum); | 73 | HcommCcuResDescHandle resDesc, HcommCcuResType resType, uint32_t *resNum); |
| @@ -66,17 +77,22 @@ extern CcuResult HcommCcuInsResDescQueryNum( | |||
| 66 | * @param[in] resDescs 资源描述符句柄数组。 | 77 | * @param[in] resDescs 资源描述符句柄数组。 |
| 67 | * @param[in] resDescNum 资源描述符数量。 | 78 | * @param[in] resDescNum 资源描述符数量。 |
| 68 | * @param[out] ccuInsHandle 创建成功后返回的 CCU 实例句柄,不可为 nullptr。 | 79 | * @param[out] ccuInsHandle 创建成功后返回的 CCU 实例句柄,不可为 nullptr。 |
| 69 | - * @return CcuResult。 | 80 | + * @return CCU_SUCCESS 创建成功 |
| 81 | + * CCU_E_PTR resDescs 或 ccuInsHandle 为 nullptr,或内部资源包分配失败 | ||
| 82 | + * CCU_E_PARA resDescNum 超出合法范围,或资源描述符中的 ioDie ID 重复 | ||
| 83 | + * CCU_E_INTERNAL 内部 CCU 实例创建或登记失败 | ||
| 70 | */ | 84 | */ |
| 71 | extern CcuResult HcommCcuInsCreate( | 85 | extern CcuResult HcommCcuInsCreate( |
[严重][BUILD-04][确定] 这里新增了公开接口声明,但仓内未检索到该签名的 ![]() ![]() | |||
| 72 | const HcommCcuResDescHandle *resDescs, uint32_t resDescNum, CcuInsHandle *ccuInsHandle); | 86 | const HcommCcuResDescHandle *resDescs, uint32_t resDescNum, CcuInsHandle *ccuInsHandle); |
| 73 | 87 | ||
| 74 | /** | 88 | /** |
| 75 | - * @brief 使用指定 ioDie 上的默认资源创建 CCU 实例。 | 89 | + * @brief 使用当前 Device 上所有已使能 ioDie 的全部资源创建 CCU 实例。 |
| 76 | - * @param[in] dieIds ioDie ID 数组。 | 90 | + * @param[in] dieIds 保留参数,当前版本不读取,调用方应传入 nullptr。 |
| 77 | - * @param[in] dieNum ioDie 数量。 | 91 | + * @param[in] dieNum 保留参数,当前版本不读取,调用方应传入 0。 |
| 78 | * @param[out] ccuInsHandle 创建成功后返回的 CCU 实例句柄,不可为 nullptr。 | 92 | * @param[out] ccuInsHandle 创建成功后返回的 CCU 实例句柄,不可为 nullptr。 |
| 79 | - * @return CcuResult。 | 93 | + * @return CCU_SUCCESS 创建成功 |
| 94 | + * CCU_E_PTR ccuInsHandle 为 nullptr,或内部资源包分配失败 | ||
| 95 | + * CCU_E_INTERNAL 内部 CCU 实例创建或登记失败 | ||
| 80 | */ | 96 | */ |
| 81 | extern CcuResult HcommCcuInsCreateDefault( | 97 | extern CcuResult HcommCcuInsCreateDefault( |
| 82 | const uint32_t *dieIds, uint32_t dieNum, CcuInsHandle *ccuInsHandle); | 98 | const uint32_t *dieIds, uint32_t dieNum, CcuInsHandle *ccuInsHandle); |
| @@ -91,15 +107,21 @@ extern CcuResult HcommCcuInsDestroy(CcuInsHandle ccuInsHandle); | |||
| 91 | /** | 107 | /** |
| 92 | * @brief 查询 CCU 实例在资源描述符所属 ioDie 上占用的资源。 | 108 | * @brief 查询 CCU 实例在资源描述符所属 ioDie 上占用的资源。 |
| 93 | * @param[in] ccuInsHandle CCU 实例句柄。 | 109 | * @param[in] ccuInsHandle CCU 实例句柄。 |
| 94 | - * @param[in,out] resDesc 调用方基于待查询 ioDie 创建的资源描述符句柄,查询成功后写入该 ioDie 上的占用资源数量。 | 110 | + * @param[in,out] resDesc 由 HcommCcuInsResDescCreate 创建的资源描述符句柄;接口读取创建 resDesc 时设置的 |
| 111 | + * dieId 作为待查询 ioDie,查询成功后写入该 ioDie 上的占用资源数量。 | ||
| 95 | * @return CcuResult。 | 112 | * @return CcuResult。 |
| 96 | */ | 113 | */ |
| 97 | extern CcuResult HcommCcuInsQueryResDesc(CcuInsHandle ccuInsHandle, HcommCcuResDescHandle resDesc); | 114 | extern CcuResult HcommCcuInsQueryResDesc(CcuInsHandle ccuInsHandle, HcommCcuResDescHandle resDesc); |
| 98 | 115 | ||
| 99 | /** | 116 | /** |
| 100 | - * @brief 查询资源描述符所属 ioDie 上的剩余 CCU 资源。 | 117 | + * @brief 查询指定 Die 上的剩余 CCU 资源(查询最大连续资源) |
| 101 | - * @param[in,out] resDesc 调用方基于待查询 ioDie 创建的资源描述符句柄,查询成功后写入该 ioDie 上的剩余资源数量。 | 118 | + * @param[in,out] resDesc 由 HcommCcuInsResDescCreate 创建的资源描述符句柄;接口读取创建 resDesc 时设置的 |
| 102 | - * @return CcuResult。 | 119 | + * dieId 作为待查询 ioDie,查询成功后写入各资源类型的最大连续剩余数量 |
| 120 | + * @return CCU_SUCCESS 查询成功 | ||
| 121 | + * CCU_E_NOT_FOUND resDesc 未注册 | ||
| 122 | + * CCU_E_PARA dieId 超出合法范围 | ||
| 123 | + * CCU_E_UNAVAIL 指定的 Die 未使能 | ||
| 124 | + * CCU_E_INTERNAL 底层资源查询失败 | ||
| 103 | */ | 125 | */ |
| 104 | extern CcuResult HcommCcuQueryRemainResDesc(HcommCcuResDescHandle resDesc); | 126 | extern CcuResult HcommCcuQueryRemainResDesc(HcommCcuResDescHandle resDesc); |
| 105 | 127 | ||
| @@ -108,7 +130,8 @@ extern CcuResult HcommCcuQueryRemainResDesc(HcommCcuResDescHandle resDesc); | |||
| 108 | * @param[in] kernelFunc CCU Kernel 函数指针,不可为 nullptr。 | 130 | * @param[in] kernelFunc CCU Kernel 函数指针,不可为 nullptr。 |
| 109 | * @param[in] kernelArgs CCU Kernel 参数数组;argNum 为 0 时可为 nullptr。 | 131 | * @param[in] kernelArgs CCU Kernel 参数数组;argNum 为 0 时可为 nullptr。 |
| 110 | * @param[in] argNum CCU Kernel 参数数量。 | 132 | * @param[in] argNum CCU Kernel 参数数量。 |
| 111 | - * @param[in,out] resDesc 调用方创建的资源描述符句柄,查询成功后写入资源诉求。 | 133 | + * @param[in,out] resDesc 由 HcommCcuInsResDescCreate 创建的资源描述符句柄;接口读取创建 resDesc 时设置的 |
| 134 | + * dieId 作为资源统计的目标 ioDie,查询成功后写入资源诉求。 | ||
| 112 | * @return CcuResult。 | 135 | * @return CcuResult。 |
| 113 | */ | 136 | */ |
| 114 | extern CcuResult HcommCcuKernelQueryResReq( | 137 | extern CcuResult HcommCcuKernelQueryResReq( |
| @@ -139,4 +139,4 @@ static inline void CcuLoopGroupCfgInit(CcuLoopGroupCfg *cfg) | |||
| 139 | } | 139 | } |
| 140 | #endif // __cplusplus | 140 | #endif // __cplusplus |
| 141 | 141 | ||
| 142 | -#endif // CCU_TYPES_H | 142 | +#endif // CCU_TYPES_H |
| @@ -24,8 +24,10 @@ extern "C" { | |||
| 24 | * @param[in] insHandle CCU 实例句柄。 | 24 | * @param[in] insHandle CCU 实例句柄。 |
| 25 | * @return HcclResult。 | 25 | * @return HcclResult。 |
| 26 | * @note 一个通信域最多绑定一个 CCU 实例。重复绑定相同或不同实例均返回 HCCL_E_PARA,且不修改原绑定。 | 26 | * @note 一个通信域最多绑定一个 CCU 实例。重复绑定相同或不同实例均返回 HCCL_E_PARA,且不修改原绑定。 |
| 27 | - * @note 绑定成功后,实例所有权转移给通信域;调用方不得销毁该实例,也不得将同一实例绑定到其他通信域。 | 27 | + * @note 绑定成功后,insHandle 的所有权和销毁责任转移给通信域,调用方不得再调用 |
| 28 | - * 绑定失败时,实例所有权仍归调用方。 | 28 | + * HcommCcuInsDestroy,也不得将同一 insHandle 绑定到其他通信域;绑定失败时所有权仍归调用方。 |
| 29 | + * @note 本接口仅保证多个 HcclCommAssignCcuIns 调用之间的并发安全。调用方必须保证本接口不与 | ||
| 30 | + * HcclCommQueryCcuIns 或 HcclCommDestroy 并发执行。 | ||
| 29 | */ | 31 | */ |
| 30 | extern HcclResult HcclCommAssignCcuIns(HcclComm comm, CcuInsHandle insHandle); | 32 | extern HcclResult HcclCommAssignCcuIns(HcclComm comm, CcuInsHandle insHandle); |
[严重][BIZ-05][确定] 该接口成功后会把 ![]() ![]() | |||
| 31 | 33 | ||
| @@ -35,8 +37,8 @@ extern HcclResult HcclCommAssignCcuIns(HcclComm comm, CcuInsHandle insHandle); | |||
| 35 | * @param[out] insHandles 查询成功后返回 CCU 实例句柄数组,不可为 nullptr。 | 37 | * @param[out] insHandles 查询成功后返回 CCU 实例句柄数组,不可为 nullptr。 |
| 36 | * @param[out] insNum 查询成功后返回 CCU 实例数量,不可为 nullptr。 | 38 | * @param[out] insNum 查询成功后返回 CCU 实例数量,不可为 nullptr。 |
| 37 | * @return HcclResult。 | 39 | * @return HcclResult。 |
| 38 | - * @note 当前一个通信域最多返回一个 CCU 实例。查询成功时,insHandles[0] 为已绑定实例句柄,*insNum 为 1。 | 40 | + * @note 返回的 CCU 实例句柄仅供借用,不转移所有权,调用方不得销毁该句柄。 |
| 39 | - * 查询结果仅供借用,不转移实例所有权。 | 41 | + * @note 调用方必须保证本接口不与 HcclCommAssignCcuIns 或 HcclCommDestroy 并发执行。 |
| 40 | */ | 42 | */ |
| 41 | extern HcclResult HcclCommQueryCcuIns(HcclComm comm, | 43 | extern HcclResult HcclCommQueryCcuIns(HcclComm comm, |
| 42 | CcuInsHandle *insHandles, uint32_t *insNum); | 44 | CcuInsHandle *insHandles, uint32_t *insNum); |
| @@ -9,15 +9,17 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | #include "ccu_launch.h" | 11 | #include "ccu_launch.h" |
| 12 | + | ||
| 13 | +#include <algorithm> | ||
| 14 | +#include <iterator> | ||
| 15 | +#include <memory> | ||
| 16 | +#include <utility> | ||
| 17 | +#include <vector> | ||
| 18 | + | ||
| 12 | #include "adapter_rts_common.h" | 19 | #include "adapter_rts_common.h" |
| 13 | #include "ccu_res.h" | 20 | #include "ccu_res.h" |
| 14 | 21 | ||
| 15 | -#include <vector> | ||
| 16 | - | ||
| 17 | -#include "ccu_device_res.h" | ||
| 18 | - | ||
| 19 | #include "ccu_log.h" | 22 | #include "ccu_log.h" |
| 20 | -#include "ccu_types.h" | ||
| 21 | 23 | ||
| 22 | #include "hcom_common.h" | 24 | #include "hcom_common.h" |
| 23 | 25 | ||
| @@ -28,7 +30,6 @@ | |||
| 28 | 30 | ||
| 29 | #include "env_config/env_config.h" // 暂时引用orion的环境变量处理模块 | 31 | #include "env_config/env_config.h" // 暂时引用orion的环境变量处理模块 |
| 30 | 32 | ||
| 31 | - | ||
| 32 | #include "hcomm_adapter_rts.h" | 33 | #include "hcomm_adapter_rts.h" |
| 33 | 34 | ||
| 34 | #include "task_param.h" | 35 | #include "task_param.h" |
| @@ -38,81 +39,6 @@ | |||
| 38 | #include "unified_platform/pub_inc/config_plf_log.h" | 39 | #include "unified_platform/pub_inc/config_plf_log.h" |
| 39 | using Hccl::PLF_TASK; | 40 | using Hccl::PLF_TASK; |
| 40 | 41 | ||
| 41 | -CcuResult HcommCcuInsCreateLegacy(const void *resDesc, uint32_t descNum, CcuInsHandle *insHandle) | ||
| 42 | -{ | ||
| 43 | - CCU_CHK_PTR_NULL(resDesc); | ||
| 44 | - CCU_CHK_PTR_NULL(insHandle); | ||
| 45 | - if (descNum != 1) { | ||
| 46 | - HCCL_ERROR("[%s] failed, desc num[%u] is more than expected[1].", | ||
| 47 | - __func__, descNum); | ||
| 48 | - return CcuResult::CCU_E_PARA; | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - auto *resDescPtr = static_cast<const CcuResDesc *>(resDesc); | ||
| 52 | - if (resDescPtr->dieId != hcomm::CCU_MAX_IODIE_NUM) { | ||
| 53 | - HCCL_ERROR("[%s] failed, ccu instance cannot be created with die id now.", __func__); | ||
| 54 | - return CcuResult::CCU_E_PARA; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - const uint32_t devLogicId = HcclGetThreadDeviceId(); | ||
| 58 | - CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).Create(resDescPtr->insType, *insHandle)); | ||
| 59 | - | ||
| 60 | - return CcuResult::CCU_SUCCESS; | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -CcuResult HcommCcuInsCreate(const HcommCcuResDescHandle *, uint32_t, CcuInsHandle *) | ||
| 64 | -{ | ||
| 65 | - return CcuResult::CCU_E_NOT_SUPPORT; | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -CcuResult HcommCcuInsCreateDefault(const uint32_t *, uint32_t, CcuInsHandle *) | ||
| 69 | -{ | ||
| 70 | - return CcuResult::CCU_E_NOT_SUPPORT; | ||
| 71 | -} | ||
| 72 | - | ||
| 73 | -CcuResult HcommCcuInsDestroy(CcuInsHandle) | ||
| 74 | -{ | ||
| 75 | - return CcuResult::CCU_E_NOT_SUPPORT; | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -CcuResult HcommCcuInsQueryResDesc(CcuInsHandle, HcommCcuResDescHandle) | ||
| 79 | -{ | ||
| 80 | - return CcuResult::CCU_E_NOT_SUPPORT; | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -/** | ||
| 84 | - * @brief 关闭CCU特性,解初始化CCU平台层 | ||
| 85 | - * | ||
| 86 | - * @param insHandle CCU实例句柄 | ||
| 87 | - * @param curDeviceLogicId 当前设备逻辑ID | ||
| 88 | - * @return CcuResult 执行结果状态码,CCU_SUCCESS表示成功,其他值表示失败 | ||
| 89 | - */ | ||
| 90 | -CcuResult HcommCcuInsDestroyLegacy(CcuInsHandle insHandle, int32_t curDeviceLogicId) | ||
| 91 | -{ | ||
| 92 | - // 获取当前线程的 DeviceId(线程变量) | ||
| 93 | - const int32_t threadDevId = HcclGetThreadDeviceId(); | ||
| 94 | - HCCL_INFO("[%s] curDeviceLogicId[%d], threadDevId[%d]", __func__, curDeviceLogicId, threadDevId); | ||
| 95 | - | ||
| 96 | - // 先切换为目标 curDeviceLogicId | ||
| 97 | - bool isDiffDevId = false; | ||
| 98 | - if (curDeviceLogicId != threadDevId) { | ||
| 99 | - CCU_CHK_RET(hrtSetDevice(curDeviceLogicId)); | ||
| 100 | - isDiffDevId = true; | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - // 销毁 CcuInstance | ||
| 104 | - CcuResult ret = hcomm::CcuInstanceMgr::GetInstance(curDeviceLogicId).Destroy(insHandle); | ||
| 105 | - if (ret != CCU_SUCCESS) { | ||
| 106 | - HCCL_ERROR("[%s] Destroy CcuInstance failed, ret[%d]", __func__, ret); | ||
| 107 | - } | ||
| 108 | - | ||
| 109 | - /// 切换回原来的 DeviceId | ||
| 110 | - if (isDiffDevId) { | ||
| 111 | - CCU_CHK_RET(hrtSetDevice(threadDevId)); | ||
| 112 | - } | ||
| 113 | - return ret; | ||
| 114 | -} | ||
| 115 | - | ||
| 116 | CcuResult HcommCcuKernelRegisterStart(CcuInsHandle insHandle) | 42 | CcuResult HcommCcuKernelRegisterStart(CcuInsHandle insHandle) |
| 117 | { | 43 | { |
| 118 | const uint32_t devLogicId = HcclGetThreadDeviceId(); | 44 | const uint32_t devLogicId = HcclGetThreadDeviceId(); |
| @@ -131,12 +57,12 @@ CcuResult HcommCcuKernelRegisterStart(CcuInsHandle insHandle) | |||
| 131 | } | 57 | } |
| 132 | 58 | ||
| 133 | static CcuResult CcuKernelTryRegister(hcomm::CcuInstance *ccuIns, hcomm::CcuResPack *resPack, | 59 | static CcuResult CcuKernelTryRegister(hcomm::CcuInstance *ccuIns, hcomm::CcuResPack *resPack, |
| 134 | - uint32_t devLogicId, const char *kernelFuncName, const void *kernelFunc, | 60 | + uint32_t devLogicId, uint32_t dieId, const char *kernelFuncName, const void *kernelFunc, |
| 135 | const void **kernelArgs, uint32_t argNum, CcuKernelHandle &newHandle) | 61 | const void **kernelArgs, uint32_t argNum, CcuKernelHandle &newHandle) |
| 136 | { | 62 | { |
| 137 | CCU_EXCEPTION_HANDLE_BEGIN | 63 | CCU_EXCEPTION_HANDLE_BEGIN |
| 138 | auto &kernelMgr = hcomm::CcuKernelMgr::GetInstance(devLogicId); | 64 | auto &kernelMgr = hcomm::CcuKernelMgr::GetInstance(devLogicId); |
| 139 | - CCU_CHK_RET(kernelMgr.Register(*resPack, kernelFuncName, | 65 | + CCU_CHK_RET(kernelMgr.Register(*resPack, dieId, kernelFuncName, |
| 140 | kernelFunc, kernelArgs, argNum, newHandle)); | 66 | kernelFunc, kernelArgs, argNum, newHandle)); |
| 141 | CCU_CHK_RET(ccuIns->SaveKernel(newHandle)); | 67 | CCU_CHK_RET(ccuIns->SaveKernel(newHandle)); |
| 142 | CCU_EXCEPTION_HANDLE_END | 68 | CCU_EXCEPTION_HANDLE_END |
| @@ -158,8 +84,6 @@ CcuResult HcommCcuKernelRegister(CcuInsHandle insHandle, uint32_t dieId, | |||
| 158 | CCU_CHK_PTR_NULL(kernelArgs); | 84 | CCU_CHK_PTR_NULL(kernelArgs); |
| 159 | } | 85 | } |
| 160 | 86 | ||
| 161 | - (void)dieId; // dieId 当前预留不使用 | ||
| 162 | - | ||
| 163 | const uint32_t devLogicId = HcclGetThreadDeviceId(); | 87 | const uint32_t devLogicId = HcclGetThreadDeviceId(); |
| 164 | auto *ccuIns = hcomm::CcuInstanceMgr::GetInstance(devLogicId).Get(insHandle); | 88 | auto *ccuIns = hcomm::CcuInstanceMgr::GetInstance(devLogicId).Get(insHandle); |
| 165 | CCU_CHK_PTR_NULL(ccuIns); | 89 | CCU_CHK_PTR_NULL(ccuIns); |
| @@ -170,7 +94,7 @@ CcuResult HcommCcuKernelRegister(CcuInsHandle insHandle, uint32_t dieId, | |||
| 170 | CCU_CHK_PTR_NULL(resPack); | 94 | CCU_CHK_PTR_NULL(resPack); |
| 171 | 95 | ||
| 172 | CcuKernelHandle newHandle{0}; | 96 | CcuKernelHandle newHandle{0}; |
| 173 | - CcuResult ret = CcuKernelTryRegister(ccuIns, resPack, devLogicId, kernelFuncName, | 97 | + CcuResult ret = CcuKernelTryRegister(ccuIns, resPack, devLogicId, dieId, kernelFuncName, |
| 174 | kernelFunc, kernelArgs, argNum, newHandle); | 98 | kernelFunc, kernelArgs, argNum, newHandle); |
| 175 | if (ret != CcuResult::CCU_SUCCESS) { | 99 | if (ret != CcuResult::CCU_SUCCESS) { |
| 176 | ccuIns->AbortRegister(); | 100 | ccuIns->AbortRegister(); |
| @@ -10,37 +10,276 @@ | |||
| 10 | 10 | ||
| 11 | #include "ccu_res.h" | 11 | #include "ccu_res.h" |
| 12 | 12 | ||
| 13 | -CcuResult HcommCcuInsResDescCreate(uint32_t, HcommCcuResDescHandle *) | 13 | +#include <array> |
| 14 | + | ||
| 15 | +#include "ccu_device_res.h" | ||
| 16 | +#include "ccu_device_pub.h" | ||
| 17 | + | ||
| 18 | +#include "ccu_log.h" | ||
| 19 | + | ||
| 20 | +#include "hcom_common.h" | ||
| 21 | +#include "op_base.h" | ||
| 22 | + | ||
| 23 | +#include "ccu_kernel_mgr.h" | ||
| 24 | +#include "ccu_instance_mgr.h" | ||
| 25 | +#include "ccu_res_desc.h" | ||
| 26 | +#include "ccu_res_desc_mgr.h" | ||
| 27 | +#include "ccu_res_type_converter.h" | ||
| 28 | + | ||
| 29 | +CcuResult HcommCcuInsResDescCreate(uint32_t dieId, HcommCcuResDescHandle *handle) | ||
| 14 | { | 30 | { |
| 15 | - return CcuResult::CCU_E_NOT_SUPPORT; | 31 | + if (dieId >= hcomm::CCU_MAX_IODIE_NUM) { |
| 32 | + HCCL_ERROR("[%s] dieId[%u] is invalid, dieId should in [0, %u).", __func__, dieId, hcomm::CCU_MAX_IODIE_NUM); | ||
| 33 | + return CcuResult::CCU_E_PARA; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + CCU_CHK_PTR_NULL(handle); | ||
| 37 | + | ||
| 38 | + int32_t devLogicId = INVALID_INT; | ||
| 39 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
换成hrtGetDeviceRefresh,kernel那边也要换(不阻塞上库,当前先不改 ![]() ![]() | |||
| 40 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr().Create(dieId, *handle)); | ||
| 41 | + HCCL_INFO("[%s] success, handle[0x%llx] dieId[%u]", __func__, *handle, dieId); | ||
| 42 | + return CcuResult::CCU_SUCCESS; | ||
| 16 | } | 43 | } |
| 17 | 44 | ||
| 18 | -CcuResult HcommCcuInsResDescDestroy(HcommCcuResDescHandle) | 45 | +CcuResult HcommCcuInsResDescDestroy(HcommCcuResDescHandle handle) |
| 19 | { | 46 | { |
| 20 | - return CcuResult::CCU_E_NOT_SUPPORT; | 47 | + int32_t devLogicId = INVALID_INT; |
| 48 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 49 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr().Destroy(handle)); | ||
| 50 | + HCCL_INFO("[%s] success, handle[0x%llx]", __func__, handle); | ||
| 51 | + return CcuResult::CCU_SUCCESS; | ||
| 21 | } | 52 | } |
| 22 | 53 | ||
| 23 | -CcuResult HcommCcuInsResDescQueryDieId(HcommCcuResDescHandle, uint32_t *) | 54 | +CcuResult HcommCcuInsResDescSetNum(HcommCcuResDescHandle handle, HcommCcuResType resType, uint32_t resNum) |
| 24 | { | 55 | { |
| 25 | - return CcuResult::CCU_E_NOT_SUPPORT; | 56 | + hcomm::ResType ccuResType{hcomm::ResType::INVALID}; |
| 57 | + CCU_CHK_RET(hcomm::ConvertHcommCcuResTypeToHcclResType(resType, ccuResType)); | ||
| 58 | + | ||
| 59 | + int32_t devLogicId = INVALID_INT; | ||
| 60 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 61 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr().SetResNum(handle, ccuResType, resNum)); | ||
| 62 | + HCCL_INFO("[%s] success, handle[0x%llx] resType[%d] resNum[%u]", __func__, handle, resType, resNum); | ||
| 63 | + return CcuResult::CCU_SUCCESS; | ||
| 26 | } | 64 | } |
| 27 | 65 | ||
| 28 | -CcuResult HcommCcuInsResDescSetNum(HcommCcuResDescHandle, HcommCcuResType, uint32_t) | 66 | +CcuResult HcommCcuInsResDescQueryNum(HcommCcuResDescHandle handle, HcommCcuResType resType, uint32_t *num) |
| 29 | { | 67 | { |
| 30 | - return CcuResult::CCU_E_NOT_SUPPORT; | 68 | + CCU_CHK_PTR_NULL(num); |
| 69 | + hcomm::ResType ccuResType{hcomm::ResType::INVALID}; | ||
| 70 | + CCU_CHK_RET(hcomm::ConvertHcommCcuResTypeToHcclResType(resType, ccuResType)); | ||
| 71 | + | ||
| 72 | + int32_t devLogicId = INVALID_INT; | ||
| 73 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 74 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr().QueryResNum(handle, ccuResType, *num)); | ||
| 75 | + HCCL_INFO("[%s] success, handle[0x%llx] resType[%d] resNum[%u]", __func__, handle, resType, *num); | ||
| 76 | + return CcuResult::CCU_SUCCESS; | ||
| 31 | } | 77 | } |
| 32 | 78 | ||
| 33 | -CcuResult HcommCcuInsResDescQueryNum(HcommCcuResDescHandle, HcommCcuResType, uint32_t *) | 79 | +CcuResult HcommCcuInsResDescQueryDieId(HcommCcuResDescHandle handle, uint32_t *dieId) |
| 34 | { | 80 | { |
| 35 | - return CcuResult::CCU_E_NOT_SUPPORT; | 81 | + CCU_CHK_PTR_NULL(dieId); |
| 82 | + int32_t devLogicId = INVALID_INT; | ||
| 83 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 84 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr().QueryDieId(handle, *dieId)); | ||
| 85 | + HCCL_INFO("[%s] success, handle[0x%llx] dieId[%u]", __func__, handle, *dieId); | ||
| 86 | + return CcuResult::CCU_SUCCESS; | ||
| 36 | } | 87 | } |
| 37 | 88 | ||
| 38 | -CcuResult HcommCcuQueryRemainResDesc(HcommCcuResDescHandle) | 89 | +CcuResult HcommCcuQueryRemainResDesc(HcommCcuResDescHandle handle) |
| 39 | { | 90 | { |
| 40 | - return CcuResult::CCU_E_NOT_SUPPORT; | 91 | + int32_t devLogicId = INVALID_INT; |
| 92 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 93 | + | ||
| 94 | + // CCU 驱动未拉起时无法查询硬件资源, 提前返回 | ||
| 95 | + if (!hcomm::CcuIsInited(devLogicId)) { | ||
| 96 | + HCCL_WARNING("[%s] failed, CCU feature is not inited, devLogicId[%d].", | ||
| 97 | + __func__, devLogicId); | ||
| 98 | + return CcuResult::CCU_E_UNAVAIL; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + auto &resDescMgr = hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr(); | ||
| 102 | + | ||
| 103 | + // die 合法性前置校验 | ||
| 104 | + uint32_t dieId = 0; | ||
| 105 | + CCU_CHK_RET(resDescMgr.QueryDieId(handle, dieId)); | ||
| 106 | + bool enableFlag = false; | ||
| 107 | + // CcuGetDieEnableInfo 中会做dieId合法性校验以及查询是否使能 | ||
| 108 | + CCU_CHK_RET(hcomm::CcuGetDieEnableInfo(devLogicId, static_cast<uint8_t>(dieId), enableFlag)); | ||
| 109 | + if (!enableFlag) { | ||
| 110 | + HCCL_WARNING("[%s] failed, dieId[%u] is not enabled.", __func__, dieId); | ||
| 111 | + return CcuResult::CCU_E_UNAVAIL; | ||
不打印error ![]() ![]() | |||
| 112 | + } | ||
| 113 | + | ||
| 114 | + // 委托 CcuResDescMgr 在锁内查询剩余资源,防止 Get→Destroy 的 use-after-free | ||
| 115 | + CCU_CHK_RET(resDescMgr.QueryRemainRes(handle, devLogicId)); | ||
| 116 | + | ||
| 117 | + HCCL_INFO("[%s] success, handle[0x%llx] dieId[%u]", __func__, handle, dieId); | ||
| 118 | + return CcuResult::CCU_SUCCESS; | ||
| 41 | } | 119 | } |
| 42 | 120 | ||
| 43 | -CcuResult HcommCcuKernelQueryResReq(const void *, const void **, uint32_t, HcommCcuResDescHandle) | 121 | +static CcuResult ConvertCcuResReqToResDesc(hcomm::CcuResDescMgr &resDescMgr, |
| 122 | + HcommCcuResDescHandle resDesc, const hcomm::CcuResReq &resReq, uint32_t instrCount, uint32_t selectedDie) | ||
| 44 | { | 123 | { |
| 45 | - return CcuResult::CCU_E_NOT_SUPPORT; | 124 | + const uint32_t loopNum = resReq.loopEngineReq[selectedDie] + resReq.blockLoopEngineReq[selectedDie]; |
| 125 | + const uint32_t msNum = resReq.msReq[selectedDie] + resReq.blockMsReq[selectedDie]; | ||
| 126 | + const uint32_t xnNum = resReq.xnReq[selectedDie] + resReq.blockXnReq[selectedDie]; | ||
| 127 | + const uint32_t gsaNum = resReq.gsaReq[selectedDie] + resReq.blockGsaReq[selectedDie]; | ||
| 128 | + const uint32_t ckeNum = resReq.ckeReq[selectedDie] + resReq.blockCkeReq[selectedDie]; | ||
| 129 | + const uint32_t missionNum = resReq.missionReq.req[selectedDie]; | ||
| 130 | + | ||
| 131 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::LOOP, loopNum)); | ||
| 132 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::MS, msNum)); | ||
| 133 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::XN, xnNum)); | ||
| 134 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::GSA, gsaNum)); | ||
| 135 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::CKE, ckeNum)); | ||
| 136 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::MISSION, missionNum)); | ||
| 137 | + CCU_CHK_RET(resDescMgr.SetResNum(resDesc, hcomm::ResType::INS, instrCount)); | ||
| 138 | + | ||
| 139 | + HCCL_INFO("[HcommCcuKernelQueryResReq] success, aggregated resource request, not allocated resource, " | ||
| 140 | + "resDesc[0x%llx], dieId[%u], loop[%u], ms[%u], xn[%u], gsa[%u], cke[%u], mission[%u], ins[%u].", | ||
| 141 | + static_cast<unsigned long long>(resDesc), selectedDie, loopNum, msNum, xnNum, gsaNum, ckeNum, missionNum, | ||
| 142 | + instrCount); | ||
| 143 | + return CcuResult::CCU_SUCCESS; | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +CcuResult HcommCcuKernelQueryResReq(const void *kernelFunc, const void **kernelArgs, | ||
| 147 | + uint32_t argNum, HcommCcuResDescHandle resDesc) | ||
| 148 | +{ | ||
| 149 | + HCCL_INFO("[%s] begin, argNum[%u], resDesc[0x%llx], kernelFunc[%p].", | ||
| 150 | + __func__, argNum, static_cast<unsigned long long>(resDesc), kernelFunc); | ||
| 151 | + CCU_CHK_PTR_NULL(kernelFunc); | ||
| 152 | + if (resDesc == 0 || argNum > 1) { | ||
| 153 | + HCCL_ERROR("[%s] failed, resDesc[0x%llx], argNum[%u].", | ||
| 154 | + __func__, static_cast<unsigned long long>(resDesc), argNum); | ||
| 155 | + return CcuResult::CCU_E_PARA; | ||
| 156 | + } | ||
| 157 | + if (argNum == 1) { | ||
| 158 | + CHK_PRT_RET(kernelArgs == nullptr, | ||
| 159 | + HCCL_ERROR("[%s] failed, kernelArgs is nullptr while argNum[%u].", __func__, argNum), | ||
| 160 | + CcuResult::CCU_E_PTR); | ||
| 161 | + CHK_PRT_RET(kernelArgs[0] == nullptr, | ||
| 162 | + HCCL_ERROR("[%s] failed, kernelArgs[0] is nullptr while argNum[%u].", __func__, argNum), | ||
| 163 | + CcuResult::CCU_E_PTR); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + int32_t devLogicId = INVALID_INT; | ||
| 167 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 168 | + auto &resDescMgr = hcomm::CcuInstanceMgr::GetInstance(devLogicId).GetResDescMgr(); | ||
| 169 | + uint32_t descriptorDieId = hcomm::CCU_MAX_IODIE_NUM; | ||
| 170 | + CCU_CHK_RET(resDescMgr.QueryDieId(resDesc, descriptorDieId)); | ||
| 171 | + HCCL_INFO("[%s] descriptor queried, resDesc[0x%llx], descriptorDieId[%u].", | ||
| 172 | + __func__, static_cast<unsigned long long>(resDesc), descriptorDieId); | ||
| 173 | + if (descriptorDieId >= hcomm::CCU_MAX_IODIE_NUM) { | ||
| 174 | + HCCL_ERROR("[%s] failed, descriptor dieId[%u] is invalid.", __func__, descriptorDieId); | ||
| 175 | + return CcuResult::CCU_E_PARA; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + CCU_EXCEPTION_HANDLE_BEGIN | ||
| 179 | + hcomm::CcuResReq resReq{}; | ||
| 180 | + uint32_t instrCount = 0; | ||
| 181 | + auto &kernelMgr = hcomm::CcuKernelMgr::GetInstance(devLogicId); | ||
| 182 | + CCU_CHK_RET(kernelMgr.GetKernelResourceRequest( | ||
| 183 | + descriptorDieId, "KernelForHcommCcuKernelQueryResReq", | ||
| 184 | + kernelFunc, kernelArgs, argNum, resReq, instrCount)); | ||
| 185 | + CCU_CHK_RET(ConvertCcuResReqToResDesc( | ||
| 186 | + resDescMgr, resDesc, resReq, instrCount, descriptorDieId)); | ||
| 187 | + CCU_EXCEPTION_HANDLE_END | ||
| 188 | + | ||
| 189 | + return CcuResult::CCU_SUCCESS; | ||
| 190 | +} | ||
| 191 | + | ||
| 192 | +// Deprecated: legacy internal CCU instance creation path. | ||
| 193 | +CcuResult HcommCcuInsCreateLegacy(const CcuInstanceType insType, CcuInsHandle *ccuInsHandle) | ||
| 194 | +{ | ||
| 195 | + CCU_CHK_PTR_NULL(ccuInsHandle); | ||
| 196 | + | ||
| 197 | + int32_t devLogicId = INVALID_INT; | ||
| 198 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 199 | + auto &insMgr = hcomm::CcuInstanceMgr::GetInstance(devLogicId); | ||
| 200 | + | ||
| 201 | + CCU_CHK_RET(insMgr.CreateByInsType(insType, *ccuInsHandle)); | ||
| 202 | + | ||
| 203 | + return CcuResult::CCU_SUCCESS; | ||
| 204 | +} | ||
| 205 | + | ||
| 206 | +CcuResult HcommCcuInsCreate( | ||
| 207 | + const HcommCcuResDescHandle *resDescs, uint32_t resDescNum, CcuInsHandle *ccuInsHandle) | ||
| 208 | +{ | ||
| 209 | + CCU_CHK_PTR_NULL(resDescs); | ||
| 210 | + CCU_CHK_PTR_NULL(ccuInsHandle); | ||
| 211 | + if (resDescNum == 0 || resDescNum > hcomm::CCU_MAX_IODIE_NUM) { | ||
| 212 | + HCCL_ERROR("[%s] failed, resDescNum[%u] is invalid, should be in (0, %u].", | ||
| 213 | + __func__, resDescNum, hcomm::CCU_MAX_IODIE_NUM); | ||
| 214 | + return CcuResult::CCU_E_PARA; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + int32_t devLogicId = INVALID_INT; | ||
| 218 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 219 | + auto &insMgr = hcomm::CcuInstanceMgr::GetInstance(devLogicId); | ||
| 220 | + | ||
| 221 | + // 从 CcuResDescMgr 中用 resDesc 数组里的 Handle Get 获得 CcuResDesc,构造指针数组 | ||
| 222 | + std::array<const hcomm::CcuResDesc *, hcomm::CCU_MAX_IODIE_NUM> descPtrs{}; | ||
| 223 | + for (uint32_t i = 0; i < resDescNum; i++) { | ||
| 224 | + descPtrs[i] = insMgr.GetResDescMgr().Get(resDescs[i]); | ||
| 225 | + CCU_CHK_PTR_NULL(descPtrs[i]); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + // 如果入参为 2 个 resDesc,里面的 dieId 不能重复 | ||
| 229 | + if (resDescNum == 2 && descPtrs[0]->dieId == descPtrs[1]->dieId) { | ||
| 230 | + HCCL_ERROR("[%s] failed, dieId[%u] duplicated in resDescs.", __func__, descPtrs[0]->dieId); | ||
| 231 | + return CcuResult::CCU_E_PARA; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + CCU_CHK_RET(insMgr.CreateByResDescs(descPtrs.data(), resDescNum, *ccuInsHandle)); | ||
| 235 | + return CcuResult::CCU_SUCCESS; | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +CcuResult HcommCcuInsCreateDefault( | ||
| 239 | + const uint32_t *dieIds, uint32_t dieNum, CcuInsHandle *ccuInsHandle) | ||
| 240 | +{ | ||
| 241 | + (void)dieIds; | ||
| 242 | + (void)dieNum; | ||
| 243 | + // dieIds/dieNum 为保留参数,当前版本申请当前 Device 上所有已使能 ioDie 的全部资源 | ||
| 244 | + CCU_CHK_PTR_NULL(ccuInsHandle); | ||
| 245 | + | ||
| 246 | + int32_t devLogicId = INVALID_INT; | ||
| 247 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 248 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).CreateByAllRes(*ccuInsHandle)); | ||
| 249 | + return CcuResult::CCU_SUCCESS; | ||
| 250 | +} | ||
| 251 | + | ||
| 252 | +CcuResult HcommCcuInsQueryResDesc(CcuInsHandle ccuInsHandle, HcommCcuResDescHandle resDesc) | ||
| 253 | +{ | ||
| 254 | + if (ccuInsHandle == 0 || resDesc == 0) { | ||
| 255 | + HCCL_ERROR("[%s] failed, invalid ccuInsHandle[%llu] resDesc[%llu].", | ||
| 256 | + __func__, ccuInsHandle, resDesc); | ||
| 257 | + return CcuResult::CCU_E_PARA; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + int32_t devLogicId = INVALID_INT; | ||
| 261 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 262 | + auto &insMgr = hcomm::CcuInstanceMgr::GetInstance(devLogicId); | ||
| 263 | + | ||
| 264 | + auto &resDescMgr = insMgr.GetResDescMgr(); | ||
| 265 | + uint32_t descriptorDieId = hcomm::CCU_MAX_IODIE_NUM; | ||
| 266 | + CCU_CHK_RET(resDescMgr.QueryDieId(resDesc, descriptorDieId)); | ||
| 267 | + const uint8_t dieId = static_cast<uint8_t>(descriptorDieId); | ||
| 268 | + if (dieId >= hcomm::CCU_MAX_IODIE_NUM) { | ||
| 269 | + HCCL_ERROR("[%s] failed, dieId[%u] is invalid.", __func__, dieId); | ||
| 270 | + return CcuResult::CCU_E_PARA; | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + CCU_CHK_RET(insMgr.QueryInsResDesc(ccuInsHandle, dieId, resDesc)); | ||
| 274 | + | ||
| 275 | + return CcuResult::CCU_SUCCESS; | ||
| 276 | +} | ||
| 277 | + | ||
| 278 | +CcuResult HcommCcuInsDestroy(CcuInsHandle insHandle) | ||
| 279 | +{ | ||
| 280 | + int32_t devLogicId = INVALID_INT; | ||
| 281 | + CCU_CHK_RET(HcclDeviceRefresh(devLogicId)); | ||
| 282 | + CCU_CHK_RET(hcomm::CcuInstanceMgr::GetInstance(devLogicId).Destroy(insHandle)); | ||
| 283 | + | ||
| 284 | + return CcuResult::CCU_SUCCESS; | ||
| 46 | } | 285 | } |
| @@ -0,0 +1,65 @@ | |||
| 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 | + | ||
| 11 | +#ifndef HCOMM_CCU_RES_TYPE_CONVERTER_H | ||
| 12 | +#define HCOMM_CCU_RES_TYPE_CONVERTER_H | ||
| 13 | + | ||
| 14 | +#include <array> | ||
| 15 | +#include <cstddef> | ||
| 16 | + | ||
| 17 | +#include "ccu_res_defs.h" | ||
| 18 | +#include "ccu_types.h" | ||
| 19 | +#include "unified_platform/ccu/ccu_device/ccu_device_manager.h" | ||
| 20 | + | ||
| 21 | +namespace hcomm { | ||
| 22 | + | ||
| 23 | +inline CcuResult ConvertHcommCcuResTypeToHcclResType(HcommCcuResType ccuResType, ResType &hcclResType) | ||
| 24 | +{ | ||
| 25 | + static constexpr auto RES_TYPE_MAP = std::array{ | ||
| 26 | + ResType::LOOP, // <- HCOMM_CCU_RES_TYPE_LOOP | ||
| 27 | + ResType::MS, // <- HCOMM_CCU_RES_TYPE_CCU_BUF | ||
| 28 | + ResType::XN, // <- HCOMM_CCU_RES_TYPE_VARIABLE | ||
| 29 | + ResType::GSA, // <- HCOMM_CCU_RES_TYPE_ADDRESS | ||
| 30 | + ResType::CKE, // <- HCOMM_CCU_RES_TYPE_EVENT | ||
| 31 | + ResType::MISSION, // <- HCOMM_CCU_RES_TYPE_CCU_THREAD | ||
| 32 | + ResType::INS // <- HCOMM_CCU_RES_TYPE_INSTRUCTION | ||
| 33 | + }; | ||
| 34 | + const int32_t resTypeIndex = static_cast<int32_t>(ccuResType); | ||
| 35 | + if ((resTypeIndex < 0) || (static_cast<std::size_t>(resTypeIndex) >= RES_TYPE_MAP.size())) { | ||
| 36 | + return CcuResult::CCU_E_PARA; | ||
| 37 | + } | ||
| 38 | + hcclResType = RES_TYPE_MAP[static_cast<std::size_t>(resTypeIndex)]; | ||
| 39 | + return CcuResult::CCU_SUCCESS; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +inline CcuResult ConvertHcclResTypeToHcommCcuResType(ResType hcclResType, HcommCcuResType &ccuResType) | ||
| 43 | +{ | ||
| 44 | + static constexpr std::array<HcommCcuResType, static_cast<std::size_t>(ResType::__COUNT__)> | ||
| 45 | + RES_TYPE_MAP = { | ||
| 46 | + HCOMM_CCU_RES_TYPE_LOOP, // <- ResType::LOOP | ||
| 47 | + HCOMM_CCU_RES_TYPE_CCU_BUF, // <- ResType::MS | ||
| 48 | + HCOMM_CCU_RES_TYPE_EVENT, // <- ResType::CKE | ||
| 49 | + HCOMM_CCU_RES_TYPE_VARIABLE, // <- ResType::XN | ||
| 50 | + HCOMM_CCU_RES_TYPE_INVALID, // <- ResType::COUNT_XN | ||
| 51 | + HCOMM_CCU_RES_TYPE_ADDRESS, // <- ResType::GSA | ||
| 52 | + HCOMM_CCU_RES_TYPE_INSTRUCTION, // <- ResType::INS | ||
| 53 | + HCOMM_CCU_RES_TYPE_CCU_THREAD // <- ResType::MISSION | ||
| 54 | + }; | ||
| 55 | + const auto resTypeIndex = static_cast<std::size_t>(static_cast<ResType::Value>(hcclResType)); | ||
| 56 | + if ((resTypeIndex >= RES_TYPE_MAP.size()) || (RES_TYPE_MAP[resTypeIndex] == HCOMM_CCU_RES_TYPE_INVALID)) { | ||
| 57 | + return CcuResult::CCU_E_PARA; | ||
| 58 | + } | ||
| 59 | + ccuResType = RES_TYPE_MAP[resTypeIndex]; | ||
| 60 | + return CcuResult::CCU_SUCCESS; | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +} // namespace hcomm | ||
| 64 | + | ||
| 65 | +#endif // HCOMM_CCU_RES_TYPE_CONVERTER_H | ||
| @@ -15,6 +15,7 @@ set(src_list | |||
| 15 | ccu_res_batch_allocator.cc | 15 | ccu_res_batch_allocator.cc |
| 16 | ccu_dev_mgr_imp.cc | 16 | ccu_dev_mgr_imp.cc |
| 17 | ccu_drv_handle.cc | 17 | ccu_drv_handle.cc |
| 18 | + ccu_res_desc.cc | ||
| 18 | ) | 19 | ) |
| 19 | 20 | ||
| 20 | if(TARGET hcomm) | 21 | if(TARGET hcomm) |
| @@ -24,4 +25,4 @@ if(TARGET hcomm) | |||
| 24 | target_include_directories(hcomm PRIVATE | 25 | target_include_directories(hcomm PRIVATE |
| 25 | ${CMAKE_CURRENT_SOURCE_DIR} | 26 | ${CMAKE_CURRENT_SOURCE_DIR} |
| 26 | ) | 27 | ) |
| 27 | -endif() | 28 | +endif() |
| @@ -813,6 +813,13 @@ HcclResult CcuComponent::ReleaseRes(const uint8_t dieId, const ResType resType, | |||
| 813 | return HcclResult::HCCL_SUCCESS; | 813 | return HcclResult::HCCL_SUCCESS; |
| 814 | } | 814 | } |
| 815 | 815 | ||
| 816 | +uint32_t CcuComponent::GetInsConsecutiveRemainSize(const uint8_t dieId) const | ||
| 817 | +{ | ||
| 818 | + CHK_RET(CheckDieValid(__func__, devLogicId_, dieId, dieEnableFlags_)); | ||
| 819 | + if (resAllocators_[dieId] == nullptr) return 0; | ||
要确保不会越界 ![]() ![]() | |||
| 820 | + return resAllocators_[dieId]->GetConsecutiveRemainSize(ResType::INS); | ||
| 821 | +} | ||
| 822 | + | ||
| 816 | HcclResult CcuComponent::AllocIns(const uint8_t dieId, const uint32_t num, ResInfo &insInfo) | 823 | HcclResult CcuComponent::AllocIns(const uint8_t dieId, const uint32_t num, ResInfo &insInfo) |
| 817 | { | 824 | { |
| 818 | CHK_RET(CheckDieValid(__func__, devLogicId_, dieId, dieEnableFlags_)); | 825 | CHK_RET(CheckDieValid(__func__, devLogicId_, dieId, dieEnableFlags_)); |
| @@ -58,11 +58,12 @@ public: | |||
| 58 | 58 | ||
| 59 | HcclResult AllocIns(const uint8_t dieId, const uint32_t num, ResInfo &insInfo); | 59 | HcclResult AllocIns(const uint8_t dieId, const uint32_t num, ResInfo &insInfo); |
| 60 | HcclResult ReleaseIns(const uint8_t dieId, const ResInfo &insInfo); | 60 | HcclResult ReleaseIns(const uint8_t dieId, const ResInfo &insInfo); |
| 61 | + uint32_t GetInsConsecutiveRemainSize(const uint8_t dieId) const; | ||
| 61 | HcclResult AllocCke(const uint8_t dieId, const uint32_t num, std::vector<ResInfo> &ckeInfos); | 62 | HcclResult AllocCke(const uint8_t dieId, const uint32_t num, std::vector<ResInfo> &ckeInfos); |
| 62 | HcclResult ReleaseCke(const uint8_t dieId, const std::vector<ResInfo> &ckeInfos); | 63 | HcclResult ReleaseCke(const uint8_t dieId, const std::vector<ResInfo> &ckeInfos); |
| 63 | HcclResult AllocXn(const uint8_t dieId, const uint32_t num, std::vector<ResInfo> &xnInfos); | 64 | HcclResult AllocXn(const uint8_t dieId, const uint32_t num, std::vector<ResInfo> &xnInfos); |
| 64 | HcclResult ReleaseXn(const uint8_t dieId, const std::vector<ResInfo> &xnInfos); | 65 | HcclResult ReleaseXn(const uint8_t dieId, const std::vector<ResInfo> &xnInfos); |
| 65 | - | 66 | + |
| 66 | // 0.5rtt专用接口 | 67 | // 0.5rtt专用接口 |
| 67 | HcclResult AllocWishCntXn(const uint8_t dieId, | 68 | HcclResult AllocWishCntXn(const uint8_t dieId, |
| 68 | const std::string &resGroupTag, uint32_t &wishCntXn); | 69 | const std::string &resGroupTag, uint32_t &wishCntXn); |
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | #include "ccu_res_allocator.h" | 11 | #include "ccu_res_allocator.h" |
| 12 | 12 | ||
| 13 | +#include <algorithm> | ||
| 13 | #include <climits> | 14 | #include <climits> |
| 14 | 15 | ||
| 15 | #include "ccu_res_specs.h" | 16 | #include "ccu_res_specs.h" |
| @@ -250,19 +251,42 @@ HcclResult CcuResAllocator::Release(const ResType resType, const uint32_t startI | |||
| 250 | return resTypeIter->second->Release(startId, num); | 251 | return resTypeIter->second->Release(startId, num); |
| 251 | } | 252 | } |
| 252 | 253 | ||
| 254 | +uint32_t CcuResIdAllocator::GetConsecutiveRemainSize() const | ||
| 255 | +{ | ||
| 256 | + // 扫描 resInfos_ 找最大连续空闲区 (类似 QueryRemainRes 的 gap scan) | ||
| 257 | + uint32_t cursor = 0; | ||
| 258 | + uint32_t maxGap = 0; | ||
| 259 | + for (const auto &r : resInfos_) { | ||
| 260 | + if (r.startId > cursor) { | ||
| 261 | + maxGap = std::max(maxGap, r.startId - cursor); | ||
| 262 | + } | ||
| 263 | + cursor = r.startId + r.num; | ||
| 264 | + } | ||
| 265 | + if (capacity_ > cursor) { | ||
| 266 | + maxGap = std::max(maxGap, capacity_ - cursor); | ||
| 267 | + } | ||
| 268 | + return maxGap; | ||
| 269 | +} | ||
| 270 | + | ||
| 253 | std::string CcuResIdAllocator::Describe() const | 271 | std::string CcuResIdAllocator::Describe() const |
| 254 | { | 272 | { |
| 255 | return Hccl::StringFormat("CcuResIdAllocator[capacity=%u, allocatedSize=%u, " | 273 | return Hccl::StringFormat("CcuResIdAllocator[capacity=%u, allocatedSize=%u, " |
| 256 | "resInfos_size=%u]", capacity_, allocatedSize_, resInfos_.size()); | 274 | "resInfos_size=%u]", capacity_, allocatedSize_, resInfos_.size()); |
| 257 | } | 275 | } |
| 258 | 276 | ||
| 277 | +uint32_t CcuResAllocator::GetConsecutiveRemainSize(const ResType resType) const | ||
| 278 | +{ | ||
| 279 | + auto it = idAllocatorMap_.find(static_cast<uint8_t>(resType)); | ||
| 280 | + if (it == idAllocatorMap_.end()) return 0; | ||
| 281 | + return it->second->GetConsecutiveRemainSize(); | ||
| 282 | +} | ||
| 283 | + | ||
| 259 | std::string CcuResAllocator::Describe() const | 284 | std::string CcuResAllocator::Describe() const |
| 260 | { | 285 | { |
| 261 | return Hccl::StringFormat("CcuResAllocator[devLogicId=%u, dieId=%u, " | 286 | return Hccl::StringFormat("CcuResAllocator[devLogicId=%u, dieId=%u, " |
| 262 | "idAllocatorSize=[%u]]", devLogicId_, dieId_, idAllocatorMap_.size()); | 287 | "idAllocatorSize=[%u]]", devLogicId_, dieId_, idAllocatorMap_.size()); |
| 263 | } | 288 | } |
| 264 | 289 | ||
| 265 | - | ||
| 266 | HcclResult CcuResAllocator::AllocCountXn(const uint32_t num, ResInfo &resInfo) | 290 | HcclResult CcuResAllocator::AllocCountXn(const uint32_t num, ResInfo &resInfo) |
| 267 | { | 291 | { |
| 268 | constexpr ResType resType = ResType::COUNT_XN; | 292 | constexpr ResType resType = ResType::COUNT_XN; |
| @@ -29,6 +29,7 @@ public: | |||
| 29 | HcclResult Alloc(const uint32_t num, const bool consecutive, | 29 | HcclResult Alloc(const uint32_t num, const bool consecutive, |
| 30 | std::vector<ResInfo> &allocatedResInfos, const std::string &dfxInfo = ""); | 30 | std::vector<ResInfo> &allocatedResInfos, const std::string &dfxInfo = ""); |
| 31 | HcclResult Release(const uint32_t startId, const uint32_t num); | 31 | HcclResult Release(const uint32_t startId, const uint32_t num); |
| 32 | + uint32_t GetConsecutiveRemainSize() const; | ||
| 32 | 33 | ||
| 33 | std::string Describe() const; | 34 | std::string Describe() const; |
| 34 | 35 | ||
| @@ -53,6 +54,7 @@ public: | |||
| 53 | HcclResult Alloc(const ResType resType, const uint32_t num, const bool consecutive, | 54 | HcclResult Alloc(const ResType resType, const uint32_t num, const bool consecutive, |
| 54 | std::vector<ResInfo>& resInfos); | 55 | std::vector<ResInfo>& resInfos); |
| 55 | HcclResult Release(const ResType resType, const uint32_t startId, const uint32_t num); | 56 | HcclResult Release(const ResType resType, const uint32_t startId, const uint32_t num); |
| 57 | + uint32_t GetConsecutiveRemainSize(const ResType resType) const; | ||
| 56 | 58 | ||
| 57 | // 0.5rtt专用 | 59 | // 0.5rtt专用 |
| 58 | HcclResult AllocCountXn(const uint32_t num, ResInfo &resInfo); | 60 | HcclResult AllocCountXn(const uint32_t num, ResInfo &resInfo); |
| @@ -38,6 +38,7 @@ | |||
| 38 | 38 | ||
| 39 | #include "ccu_types.h" | 39 | #include "ccu_types.h" |
| 40 | #include "ccu_log.h" | 40 | #include "ccu_log.h" |
| 41 | +#include "ccu_res_desc.h" | ||
| 41 | 42 | ||
| 42 | #include "dev_type.h" | 43 | #include "dev_type.h" |
| 43 | 44 | ||
| @@ -137,11 +138,163 @@ CcuResult CcuGetDieEnableInfo(int32_t deviceLogicId, uint8_t dieId, bool &enable | |||
| 137 | return CcuResult::CCU_SUCCESS; | 138 | return CcuResult::CCU_SUCCESS; |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 141 | +// 查询指定 die 上各资源类型可分配的总量 | ||
| 142 | +CcuResult CcuGetLoopEngineNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 143 | +{ | ||
| 144 | + CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxLoopEngineNum(deviceLogicId, dieId, num)); | ||
| 145 | + return CcuResult::CCU_SUCCESS; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +CcuResult CcuGetMsNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 149 | +{ | ||
| 150 | + CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxMsNum(deviceLogicId, dieId, num)); | ||
| 151 | + return CcuResult::CCU_SUCCESS; | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +CcuResult CcuGetCkeNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 155 | +{ | ||
| 156 | + CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxCkeNum(deviceLogicId, dieId, num)); | ||
| 157 | + return CcuResult::CCU_SUCCESS; | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +CcuResult CcuGetXnNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 161 | +{ | ||
| 162 | + CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxXnNum(deviceLogicId, dieId, num)); | ||
| 163 | + return CcuResult::CCU_SUCCESS; | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +CcuResult CcuGetGsaNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 167 | +{ | ||
| 168 | + CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxGsaNum(deviceLogicId, dieId, num)); | ||
| 169 | + return CcuResult::CCU_SUCCESS; | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +CcuResult CcuGetInstructionNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 173 | +{ | ||
| 174 | + CCU_CHK_RET(CcuDevMgrImp::GetResSpecsInstructionNum(deviceLogicId, dieId, num)); | ||
| 175 | + return CcuResult::CCU_SUCCESS; | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +CcuResult CcuGetMissionNum(int32_t deviceLogicId, uint8_t dieId, uint32_t &num) | ||
| 179 | +{ | ||
| 180 | + CCU_CHK_RET(CcuDevMgrImp::GetResSpecsMissionNum(deviceLogicId, dieId, num)); | ||
| 181 | + return CcuResult::CCU_SUCCESS; | ||
| 182 | +} | ||
| 183 | + | ||
| 184 | +HcclResult CcuGetMainboardType(uint32_t deviceLogicId, Hccl::HcclMainboardId &hcclMainboardId) | ||
| 185 | +{ | ||
| 186 | + CHK_RET(CcuGetMainboardId(deviceLogicId, hcclMainboardId)); | ||
| 187 | + return HcclResult::HCCL_SUCCESS; | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +// 单个描述符的资源数量映射到 CcuResReq 的 block 字段 | ||
| 191 | +static CcuResult FillResReqByResDesc(CcuResReq &resReq, uint8_t dieId, const CcuResDesc &desc) | ||
| 192 | +{ | ||
| 193 | + uint32_t num = 0; | ||
| 194 | + CCU_CHK_RET(desc.QueryResNum(ResType::LOOP, num)); | ||
| 195 | + resReq.blockLoopEngineReq[dieId] = num; | ||
| 196 | + CCU_CHK_RET(desc.QueryResNum(ResType::MS, num)); | ||
| 197 | + resReq.blockMsReq[dieId] = num; | ||
| 198 | + CCU_CHK_RET(desc.QueryResNum(ResType::CKE, num)); | ||
| 199 | + resReq.blockCkeReq[dieId] = num; | ||
| 200 | + CCU_CHK_RET(desc.QueryResNum(ResType::XN, num)); | ||
| 201 | + resReq.blockXnReq[dieId] = num; | ||
| 202 | + CCU_CHK_RET(desc.QueryResNum(ResType::GSA, num)); | ||
| 203 | + resReq.blockGsaReq[dieId] = num; | ||
| 204 | + | ||
| 205 | + resReq.loopEngineReq[dieId] = 0; | ||
| 206 | + resReq.msReq[dieId] = 0; | ||
| 207 | + resReq.ckeReq[dieId] = 0; | ||
| 208 | + resReq.xnReq[dieId] = 0; | ||
| 209 | + resReq.gsaReq[dieId] = 0; | ||
| 210 | + return CcuResult::CCU_SUCCESS; | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +// 查询各 die 是否启用;若全部未启用则返回错误 | ||
| 214 | +static CcuResult CheckEnabledDies(int32_t deviceLogicId, std::array<bool, CCU_MAX_IODIE_NUM> &dieEnableFlags) | ||
| 215 | +{ | ||
| 216 | + dieEnableFlags = {false, false}; | ||
| 217 | + for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) { | ||
| 218 | + CCU_CHK_RET(CcuGetDieEnableInfo(deviceLogicId, dieId, dieEnableFlags[dieId])); | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + if (!dieEnableFlags[0] && !dieEnableFlags[1]) { | ||
| 222 | + HCCL_ERROR("[%s] failed, all ccu dies are disable, devLogicId[%d].", __func__, deviceLogicId); | ||
| 223 | + return CcuResult::CCU_E_INTERNAL; | ||
| 224 | + } | ||
| 225 | + return CcuResult::CCU_SUCCESS; | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +// 根据资源描述符数组构造 CcuResReq: | ||
| 229 | +// 跳过未启用 die;block 字段由各 die 的 resDesc 填充; | ||
| 230 | +// missionReq 取所有 die 的最大值,再统一回填到各启用 die | ||
| 231 | +static CcuResult BuildResReqByDescs(const CcuResDesc *descs[], uint32_t descNum, | ||
| 232 | + const std::array<bool, CCU_MAX_IODIE_NUM> &dieEnableFlags, int32_t deviceLogicId, CcuResReq &resReq) | ||
| 233 | +{ | ||
| 234 | + resReq = CcuResReq{}; | ||
| 235 | + resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; | ||
| 236 | + | ||
| 237 | + uint32_t maxMissionReq = 0; | ||
| 238 | + for (uint32_t i = 0; i < descNum; i++) { | ||
| 239 | + if (descs[i] == nullptr) { | ||
| 240 | + HCCL_ERROR("[%s] failed, descs[%u] is nullptr, devLogicId[%d].", __func__, i, deviceLogicId); | ||
| 241 | + return CcuResult::CCU_E_PARA; | ||
| 242 | + } | ||
| 243 | + uint8_t dieId = 0; | ||
| 244 | + dieId = static_cast<uint8_t>(descs[i]->dieId); | ||
| 245 | + if (dieId >= CCU_MAX_IODIE_NUM) { | ||
| 246 | + HCCL_ERROR("[%s] failed, dieId[%u] is invalid, devLogicId[%d].", __func__, dieId, deviceLogicId); | ||
| 247 | + return CcuResult::CCU_E_PARA; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + // 不跳过未启用的die,如果die未启用,但请求资源,在分配资源时检查返回错误 | ||
| 251 | + CCU_CHK_RET(FillResReqByResDesc(resReq, dieId, *descs[i])); | ||
| 252 | + uint32_t missionNum = 0; | ||
| 253 | + CCU_CHK_RET(descs[i]->QueryResNum(ResType::MISSION, missionNum)); | ||
| 254 | + if (missionNum > maxMissionReq) { | ||
| 255 | + maxMissionReq = missionNum; | ||
| 256 | + } | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + if (maxMissionReq > 0) { | ||
| 260 | + for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) { | ||
| 261 | + if (dieEnableFlags[dieId]) { | ||
| 262 | + resReq.missionReq.req[dieId] = maxMissionReq; | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + } | ||
| 266 | + return CcuResult::CCU_SUCCESS; | ||
| 267 | +} | ||
| 268 | + | ||
| 269 | +CcuResult CcuAllocResHandleByResDescs(int32_t deviceLogicId, | ||
| 270 | + const CcuResDesc *descs[], uint32_t descNum, CcuResHandle &resHandle) | ||
| 271 | +{ | ||
| 272 | + if (descs == nullptr || descNum == 0 || descNum > hcomm::CCU_MAX_IODIE_NUM) { | ||
| 273 | + HCCL_ERROR("[%s] failed, invalid descs[%p] descNum[%u], devLogicId[%d].", __func__, descs, descNum, deviceLogicId); | ||
| 274 | + return CcuResult::CCU_E_PARA; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags = {false, false}; | ||
| 278 | + CCU_CHK_RET(CheckEnabledDies(deviceLogicId, dieEnableFlags)); | ||
| 279 | + | ||
| 280 | + CcuResReq resReq{}; | ||
| 281 | + CCU_CHK_RET(BuildResReqByDescs(descs, descNum, dieEnableFlags, deviceLogicId, resReq)); | ||
| 282 | + | ||
| 283 | + if (mainBoardType == Hccl::HcclMainboardId::MAINBOARD_OTHERS) { | ||
| 284 | + CCU_CHK_RET(CcuGetMainboardId(deviceLogicId, mainBoardType)); | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + CCU_CHK_RET(CcuDevMgrImp::AllocResHandle(deviceLogicId, resReq, resHandle)); | ||
| 288 | + | ||
| 289 | + HCCL_INFO("[%s] succeed, get res handle[%llx], devLogicId[%d], descNum[%u]", | ||
| 290 | + __func__, resHandle, deviceLogicId, descNum); | ||
| 291 | + return CcuResult::CCU_SUCCESS; | ||
| 292 | +} | ||
| 293 | + | ||
| 140 | constexpr u32 CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 8 * 8 * 2; | 294 | constexpr u32 CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 8 * 8 * 2; |
| 141 | constexpr u32 CCU_MS_DEFAULT_BLOCK_MS_REQ = 64 * 8 * 2; | 295 | constexpr u32 CCU_MS_DEFAULT_BLOCK_MS_REQ = 64 * 8 * 2; |
| 142 | -constexpr u32 CCU_MS_DEFAULT_CKE_REQ = 32; | 296 | +constexpr u32 CCU_MS_DEFAULT_BLOCK_CKE_REQ = 32 + 8 * 8 * 2; |
| 143 | -constexpr u32 CCU_MS_DEFAULT_BLOCK_CKE_REQ = 8 * 8 * 2; | 297 | +constexpr u32 CCU_MS_DEFAULT_BLOCK_XN_REQ = 400; |
| 144 | -constexpr u32 CCU_MS_DEFAULT_CONTINUOUS_XN_REQ = 400; | ||
| 145 | constexpr u32 CCU_MS_DEFAULT_GSA_REQ = 400; | 298 | constexpr u32 CCU_MS_DEFAULT_GSA_REQ = 400; |
| 146 | constexpr u32 CCU_MS_DEFAULT_MISSIONREQ_REQ = 2; | 299 | constexpr u32 CCU_MS_DEFAULT_MISSIONREQ_REQ = 2; |
| 147 | inline void ConfigCcuResReqCcuMs(CcuResReq &resReq, uint8_t dieId, CcuVersion version) | 300 | inline void ConfigCcuResReqCcuMs(CcuResReq &resReq, uint8_t dieId, CcuVersion version) |
| @@ -150,15 +303,16 @@ inline void ConfigCcuResReqCcuMs(CcuResReq &resReq, uint8_t dieId, CcuVersion ve | |||
| 150 | resReq.blockLoopEngineReq[dieId] = CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ; | 303 | resReq.blockLoopEngineReq[dieId] = CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ; |
| 151 | resReq.msReq[dieId] = 0; | 304 | resReq.msReq[dieId] = 0; |
| 152 | resReq.blockMsReq[dieId] = CCU_MS_DEFAULT_BLOCK_MS_REQ; | 305 | resReq.blockMsReq[dieId] = CCU_MS_DEFAULT_BLOCK_MS_REQ; |
| 153 | - resReq.ckeReq[dieId] = CCU_MS_DEFAULT_CKE_REQ; | 306 | + resReq.ckeReq[dieId] = 0; |
| 154 | resReq.blockCkeReq[dieId] = CCU_MS_DEFAULT_BLOCK_CKE_REQ; | 307 | resReq.blockCkeReq[dieId] = CCU_MS_DEFAULT_BLOCK_CKE_REQ; |
| 155 | resReq.xnReq[dieId] = 0; | 308 | resReq.xnReq[dieId] = 0; |
| 309 | + resReq.gsaReq[dieId] = 0; | ||
| 156 | if (version == CcuVersion::CCU_V2) { | 310 | if (version == CcuVersion::CCU_V2) { |
| 157 | - resReq.continuousXnReq[dieId] = CCU_MS_DEFAULT_CONTINUOUS_XN_REQ * 2; // V2场景下申请2倍的Xn数量 | 311 | + resReq.blockXnReq[dieId] = CCU_MS_DEFAULT_BLOCK_XN_REQ * 2; // V2场景下申请2倍的Xn数量 |
| 158 | - resReq.gsaReq[dieId] = 0; | 312 | + resReq.blockGsaReq[dieId] = 0; |
| 159 | } else { | 313 | } else { |
| 160 | - resReq.continuousXnReq[dieId] = CCU_MS_DEFAULT_CONTINUOUS_XN_REQ; | 314 | + resReq.blockXnReq[dieId] = CCU_MS_DEFAULT_BLOCK_XN_REQ; |
| 161 | - resReq.gsaReq[dieId] = CCU_MS_DEFAULT_GSA_REQ; | 315 | + resReq.blockGsaReq[dieId] = CCU_MS_DEFAULT_GSA_REQ; |
| 162 | } | 316 | } |
| 163 | resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; | 317 | resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; |
| 164 | resReq.missionReq.req[dieId] = CCU_MS_DEFAULT_MISSIONREQ_REQ; | 318 | resReq.missionReq.req[dieId] = CCU_MS_DEFAULT_MISSIONREQ_REQ; |
| @@ -166,9 +320,8 @@ inline void ConfigCcuResReqCcuMs(CcuResReq &resReq, uint8_t dieId, CcuVersion ve | |||
| 166 | 320 | ||
| 167 | constexpr u32 CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 16; | 321 | constexpr u32 CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 16; |
| 168 | constexpr u32 CCU_SCHED_DEFAULT_BLOCK_MS_REQ = 128; | 322 | constexpr u32 CCU_SCHED_DEFAULT_BLOCK_MS_REQ = 128; |
| 169 | -constexpr u32 CCU_SCHED_DEFAULT_CKE_REQ = 32; | 323 | +constexpr u32 CCU_SCHED_DEFAULT_BLOCK_CKE_REQ = 32 + 16; |
| 170 | -constexpr u32 CCU_SCHED_DEFAULT_BLOCK_CKE_REQ = 16; | 324 | +constexpr u32 CCU_SCHED_DEFAULT_BLOCK_XN_REQ = 400; |
| 171 | -constexpr u32 CCU_SCHED_DEFAULT_CONTINUOUS_XN_REQ = 400; | ||
| 172 | constexpr u32 CCU_SCHED_DEFAULT_GSA_REQ = 400; | 325 | constexpr u32 CCU_SCHED_DEFAULT_GSA_REQ = 400; |
| 173 | constexpr u32 CCU_SCHED_DEFAULT_MISSIONREQ_REQ = 2; | 326 | constexpr u32 CCU_SCHED_DEFAULT_MISSIONREQ_REQ = 2; |
| 174 | inline void ConfigCcuResReqCcuSched(CcuResReq &resReq, uint8_t dieId, CcuVersion version) | 327 | inline void ConfigCcuResReqCcuSched(CcuResReq &resReq, uint8_t dieId, CcuVersion version) |
| @@ -177,15 +330,16 @@ inline void ConfigCcuResReqCcuSched(CcuResReq &resReq, uint8_t dieId, CcuVersion | |||
| 177 | resReq.blockLoopEngineReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ; | 330 | resReq.blockLoopEngineReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ; |
| 178 | resReq.msReq[dieId] = 0; | 331 | resReq.msReq[dieId] = 0; |
| 179 | resReq.blockMsReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_MS_REQ; | 332 | resReq.blockMsReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_MS_REQ; |
| 180 | - resReq.ckeReq[dieId] = CCU_SCHED_DEFAULT_CKE_REQ; | 333 | + resReq.ckeReq[dieId] = 0; |
| 181 | resReq.blockCkeReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_CKE_REQ; | 334 | resReq.blockCkeReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_CKE_REQ; |
| 182 | resReq.xnReq[dieId] = 0; | 335 | resReq.xnReq[dieId] = 0; |
| 336 | + resReq.gsaReq[dieId] = 0; | ||
| 183 | if (version == CcuVersion::CCU_V2) { | 337 | if (version == CcuVersion::CCU_V2) { |
| 184 | - resReq.continuousXnReq[dieId] = CCU_SCHED_DEFAULT_CONTINUOUS_XN_REQ * 2; // V2场景下申请2倍的Xn数量 | 338 | + resReq.blockXnReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_XN_REQ * 2; // V2场景下申请2倍的Xn数量 |
| 185 | - resReq.gsaReq[dieId] = 0; | 339 | + resReq.blockGsaReq[dieId] = 0; |
| 186 | } else { | 340 | } else { |
| 187 | - resReq.continuousXnReq[dieId] = CCU_SCHED_DEFAULT_CONTINUOUS_XN_REQ; | 341 | + resReq.blockXnReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_XN_REQ; |
| 188 | - resReq.gsaReq[dieId] = CCU_SCHED_DEFAULT_GSA_REQ; | 342 | + resReq.blockGsaReq[dieId] = CCU_SCHED_DEFAULT_GSA_REQ; |
| 189 | } | 343 | } |
| 190 | 344 | ||
| 191 | resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; | 345 | resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; |
| @@ -424,6 +578,17 @@ HcclResult CcuDevMgrImp::ReleaseResHandle(const int32_t deviceLogicId, | |||
| 424 | return ret; | 578 | return ret; |
| 425 | } | 579 | } |
| 426 | 580 | ||
| 581 | +HcclResult CcuDevMgrImp::QueryRemainRes(const int32_t deviceLogicId, const uint8_t dieId, const ResType &internalType, uint32_t &remainNum) | ||
| 582 | +{ | ||
| 583 | + HcclResult ret; | ||
| 584 | + EXCEPTION_HANDLE_BEGIN | ||
| 585 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 586 | + CcuResBatchAllocator::GetInstance(deviceLogicId).QueryRemainRes(dieId, internalType, remainNum) : | ||
| 587 | + Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId).QueryRemainRes(dieId, internalType, remainNum); | ||
| 588 | + EXCEPTION_HANDLE_END | ||
| 589 | + return ret; | ||
| 590 | +} | ||
| 591 | + | ||
| 427 | HcclResult CcuDevMgrImp::AllocIns(const int32_t deviceLogicId, const uint8_t dieId, | 592 | HcclResult CcuDevMgrImp::AllocIns(const int32_t deviceLogicId, const uint8_t dieId, |
| 428 | const uint32_t num, ResInfo &insInfo) | 593 | const uint32_t num, ResInfo &insInfo) |
| 429 | { | 594 | { |
| @@ -448,6 +613,13 @@ HcclResult CcuDevMgrImp::ReleaseIns(const int32_t deviceLogicId, const uint8_t d | |||
| 448 | return ret; | 613 | return ret; |
| 449 | } | 614 | } |
| 450 | 615 | ||
| 616 | +uint32_t CcuDevMgrImp::GetInsConsecutiveRemainSize(const int32_t deviceLogicId, const uint8_t dieId) | ||
| 617 | +{ | ||
| 618 | + return CheckCcuOpenSourceEnable() ? | ||
| 619 | + CcuComponent::GetInstance(deviceLogicId).GetInsConsecutiveRemainSize(dieId) : | ||
| 620 | + Hccl::CcuComponent::GetInstance(deviceLogicId).GetInsConsecutiveRemainSize(dieId); | ||
| 621 | +} | ||
| 622 | + | ||
| 451 | HcclResult CcuDevMgrImp::AllocCke(const int32_t deviceLogicId, const uint8_t dieId, | 623 | HcclResult CcuDevMgrImp::AllocCke(const int32_t deviceLogicId, const uint8_t dieId, |
| 452 | const uint32_t num, std::vector<ResInfo> &ckeInfos) | 624 | const uint32_t num, std::vector<ResInfo> &ckeInfos) |
| 453 | { | 625 | { |
| @@ -562,7 +734,7 @@ HcclResult CcuDevMgrImp::GetMissionKey(const int32_t deviceLogicId, const uint8_ | |||
| 562 | return ret; | 734 | return ret; |
| 563 | } | 735 | } |
| 564 | 736 | ||
| 565 | -HcclResult CcuDevMgrImp::GetInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, | 737 | +HcclResult CcuDevMgrImp::GetResSpecsInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, |
| 566 | uint32_t &instrNum) | 738 | uint32_t &instrNum) |
| 567 | { | 739 | { |
| 568 | HcclResult ret; | 740 | HcclResult ret; |
| @@ -576,6 +748,86 @@ HcclResult CcuDevMgrImp::GetInstructionNum(const int32_t deviceLogicId, const ui | |||
| 576 | return ret; | 748 | return ret; |
| 577 | } | 749 | } |
| 578 | 750 | ||
| 751 | +HcclResult CcuDevMgrImp::GetAllocatableMaxLoopEngineNum(const int32_t deviceLogicId, const uint8_t dieId, | ||
| 752 | + uint32_t &loopNum) | ||
| 753 | +{ | ||
| 754 | + HcclResult ret; | ||
| 755 | + EXCEPTION_HANDLE_BEGIN | ||
| 756 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 757 | + CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 758 | + .GetAllocatableMaxBlockResNum(ResType::LOOP, dieId, loopNum) : | ||
| 759 | + Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 760 | + .GetAllocatableMaxBlockResNum(ResType::LOOP, dieId, loopNum); | ||
| 761 | + EXCEPTION_HANDLE_END | ||
| 762 | + return ret; | ||
| 763 | +} | ||
| 764 | + | ||
| 765 | +HcclResult CcuDevMgrImp::GetAllocatableMaxMsNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &msNum) | ||
| 766 | +{ | ||
| 767 | + HcclResult ret; | ||
| 768 | + EXCEPTION_HANDLE_BEGIN | ||
| 769 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 770 | + CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 771 | + .GetAllocatableMaxBlockResNum(ResType::MS, dieId, msNum) : | ||
| 772 | + Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 773 | + .GetAllocatableMaxBlockResNum(ResType::MS, dieId, msNum); | ||
| 774 | + EXCEPTION_HANDLE_END | ||
| 775 | + return ret; | ||
| 776 | +} | ||
| 777 | + | ||
| 778 | +HcclResult CcuDevMgrImp::GetAllocatableMaxCkeNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &ckeNum) | ||
| 779 | +{ | ||
| 780 | + HcclResult ret; | ||
| 781 | + EXCEPTION_HANDLE_BEGIN | ||
| 782 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 783 | + CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 784 | + .GetAllocatableMaxBlockResNum(ResType::CKE, dieId, ckeNum) : | ||
| 785 | + Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 786 | + .GetAllocatableMaxBlockResNum(ResType::CKE, dieId, ckeNum); | ||
| 787 | + EXCEPTION_HANDLE_END | ||
| 788 | + return ret; | ||
| 789 | +} | ||
| 790 | + | ||
| 791 | +HcclResult CcuDevMgrImp::GetAllocatableMaxXnNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &xnNum) | ||
| 792 | +{ | ||
| 793 | + HcclResult ret; | ||
| 794 | + EXCEPTION_HANDLE_BEGIN | ||
| 795 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 796 | + CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 797 | + .GetAllocatableMaxBlockResNum(ResType::XN, dieId, xnNum) : | ||
| 798 | + Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 799 | + .GetAllocatableMaxBlockResNum(ResType::XN, dieId, xnNum); | ||
| 800 | + EXCEPTION_HANDLE_END | ||
| 801 | + return ret; | ||
| 802 | +} | ||
| 803 | + | ||
| 804 | +HcclResult CcuDevMgrImp::GetAllocatableMaxGsaNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &gsaNum) | ||
| 805 | +{ | ||
| 806 | + HcclResult ret; | ||
| 807 | + EXCEPTION_HANDLE_BEGIN | ||
| 808 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 809 | + CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 810 | + .GetAllocatableMaxBlockResNum(ResType::GSA, dieId, gsaNum) : | ||
| 811 | + Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId) | ||
| 812 | + .GetAllocatableMaxBlockResNum(ResType::GSA, dieId, gsaNum); | ||
| 813 | + EXCEPTION_HANDLE_END | ||
| 814 | + return ret; | ||
| 815 | +} | ||
| 816 | + | ||
| 817 | +HcclResult CcuDevMgrImp::GetResSpecsMissionNum(const int32_t deviceLogicId, const uint8_t dieId, | ||
| 818 | + uint32_t &missionNum) | ||
| 819 | +{ | ||
| 820 | + HcclResult ret; | ||
| 821 | + EXCEPTION_HANDLE_BEGIN | ||
| 822 | + ret = CheckCcuOpenSourceEnable() ? | ||
| 823 | + CcuResSpecifications::GetInstance(deviceLogicId) | ||
| 824 | + .GetMissionNum(dieId, missionNum) : | ||
| 825 | + Hccl::CcuResSpecifications::GetInstance(deviceLogicId) | ||
| 826 | + .GetMissionNum(dieId, missionNum); | ||
| 827 | + EXCEPTION_HANDLE_END | ||
| 828 | + return ret; | ||
| 829 | +} | ||
| 830 | + | ||
| 579 | HcclResult CcuDevMgrImp::GetXnBaseAddr(const int32_t devLogicId, const uint8_t dieId, | 831 | HcclResult CcuDevMgrImp::GetXnBaseAddr(const int32_t devLogicId, const uint8_t dieId, |
| 580 | uint64_t& xnBaseAddr) | 832 | uint64_t& xnBaseAddr) |
| 581 | { | 833 | { |
| @@ -727,4 +979,4 @@ HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId) | |||
| 727 | return ret; | 979 | return ret; |
| 728 | } | 980 | } |
| 729 | 981 | ||
| 730 | -}; // namespace hcomm | 982 | +}; // namespace hcomm |
| @@ -289,9 +289,11 @@ public: | |||
| 289 | static HcclResult GetResource(const int32_t deviceLogicId, const CcuResHandle resHandle, CcuResRepository &ccuResRepo); | 289 | static HcclResult GetResource(const int32_t deviceLogicId, const CcuResHandle resHandle, CcuResRepository &ccuResRepo); |
| 290 | static HcclResult AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq, CcuResHandle &resHandle); | 290 | static HcclResult AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq, CcuResHandle &resHandle); |
| 291 | static HcclResult ReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle resHandle); | 291 | static HcclResult ReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle resHandle); |
| 292 | + static HcclResult QueryRemainRes(const int32_t deviceLogicId, const uint8_t dieId, const ResType &internalType, uint32_t &remainNum); | ||
| 292 | 293 | ||
| 293 | static HcclResult AllocIns(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, ResInfo &insInfo); | 294 | static HcclResult AllocIns(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, ResInfo &insInfo); |
| 294 | static HcclResult ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId, const ResInfo &insInfo); | 295 | static HcclResult ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId, const ResInfo &insInfo); |
| 296 | + static uint32_t GetInsConsecutiveRemainSize(const int32_t deviceLogicId, const uint8_t dieId); | ||
| 295 | static HcclResult AllocCke(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, | 297 | static HcclResult AllocCke(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, |
| 296 | std::vector<ResInfo>& ckeInfos); | 298 | std::vector<ResInfo>& ckeInfos); |
| 297 | static HcclResult ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId, const std::vector<ResInfo> &ckeInfos); | 299 | static HcclResult ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId, const std::vector<ResInfo> &ckeInfos); |
| @@ -308,7 +310,13 @@ public: | |||
| 308 | const std::string &resGroupTag, uint32_t &totalCntXn); | 310 | const std::string &resGroupTag, uint32_t &totalCntXn); |
| 309 | 311 | ||
| 310 | static HcclResult GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &missionKey); | 312 | static HcclResult GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &missionKey); |
| 311 | - static HcclResult GetInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &instrNum); | 313 | + static HcclResult GetResSpecsInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &instrNum); |
| 314 | + static HcclResult GetAllocatableMaxLoopEngineNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &loopNum); | ||
| 315 | + static HcclResult GetAllocatableMaxMsNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &msNum); | ||
| 316 | + static HcclResult GetAllocatableMaxCkeNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &ckeNum); | ||
| 317 | + static HcclResult GetAllocatableMaxXnNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &xnNum); | ||
| 318 | + static HcclResult GetAllocatableMaxGsaNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &gsaNum); | ||
| 319 | + static HcclResult GetResSpecsMissionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t &missionNum); | ||
| 312 | static HcclResult GetXnBaseAddr(const int32_t devLogicId, const uint8_t dieId, uint64_t &xnBaseAddr); | 320 | static HcclResult GetXnBaseAddr(const int32_t devLogicId, const uint8_t dieId, uint64_t &xnBaseAddr); |
| 313 | static HcclResult GetCkeBaseAddr(const int32_t devLogicId, const uint8_t dieId, uint64_t &ckeBaseAddr); | 321 | static HcclResult GetCkeBaseAddr(const int32_t devLogicId, const uint8_t dieId, uint64_t &ckeBaseAddr); |
| 314 | static HcclResult GetXnOffsetCcumAddrById(const int32_t devLogicId, const uint8_t dieId, uint16_t id, uint64_t& xnAddr); | 322 | static HcclResult GetXnOffsetCcumAddrById(const int32_t devLogicId, const uint8_t dieId, uint16_t id, uint64_t& xnAddr); |
| @@ -20,17 +20,41 @@ | |||
| 20 | 20 | ||
| 21 | #include "ccu_comp.h" | 21 | #include "ccu_comp.h" |
| 22 | #include "ccu_res_specs.h" | 22 | #include "ccu_res_specs.h" |
| 23 | +#include "ccu_res_type_converter.h" | ||
| 24 | +#include "ccu_device_res.h" | ||
| 25 | +#include "ccu_rep_reference_manager_v1.h" | ||
| 26 | +#include "ccu_rep_reference_manager.h" | ||
| 23 | 27 | ||
| 24 | namespace hcomm { | 28 | namespace hcomm { |
| 25 | 29 | ||
| 26 | -constexpr uint32_t REQ_RES_TYPE_NUM = 10; | 30 | +constexpr uint32_t REQ_RES_TYPE_NUM = 11; |
| 27 | -constexpr uint32_t BLOCK_RES_TYPE_NUM = 3; | 31 | +constexpr uint32_t BLOCK_RES_TYPE_NUM = 5; |
| 28 | constexpr uint32_t CONS_RES_TYPE_NUM = 1; | 32 | constexpr uint32_t CONS_RES_TYPE_NUM = 1; |
| 29 | -constexpr uint32_t DISCRETE_RES_TYPE_NUM = 5; | 33 | +constexpr uint32_t DISCRETE_RES_TYPE_NUM = 4; |
| 30 | constexpr uint32_t NON_BLOCK_TYPE_NUM = CONS_RES_TYPE_NUM + DISCRETE_RES_TYPE_NUM; | 34 | constexpr uint32_t NON_BLOCK_TYPE_NUM = CONS_RES_TYPE_NUM + DISCRETE_RES_TYPE_NUM; |
| 31 | constexpr uint32_t BLOCK_SIZE_MS_AX_DIE0 = 128; | 35 | constexpr uint32_t BLOCK_SIZE_MS_AX_DIE0 = 128; |
| 32 | constexpr uint32_t CCUA_NUM = 4; | 36 | constexpr uint32_t CCUA_NUM = 4; |
| 33 | 37 | ||
| 38 | +constexpr uint32_t CCU_REPREFMGR_NEW_XN_NUM = hcomm::CcuRep::FUNC_ARG_MAX | ||
| 39 | + + hcomm::CcuRep::FUNC_ARG_MAX | ||
| 40 | + + 1 + hcomm::CcuRep::FUNC_NEST_MAX + 1; | ||
| 41 | +constexpr uint32_t CCU_REPREFMGR_LEGACY_XN_NUM = Hccl::CcuRep::FUNC_IN_MAX | ||
| 42 | + + Hccl::CcuRep::FUNC_OUT_MAX | ||
| 43 | + + 1 + Hccl::CcuRep::FUNC_NEST_MAX + 1; | ||
| 44 | +constexpr uint32_t CCU_REP_TRANSLATOR_GSA_NUM = 3; | ||
| 45 | +constexpr uint32_t CCU_REP_TRANSLATOR_CKE_NUM = 2; | ||
| 46 | +constexpr uint32_t CCU_REP_TRANSLATOR_XN_NUM = 4; | ||
| 47 | +// 建链预留数量 + 开源+legacy的CcuRepTranslator预留数量 | ||
| 48 | +constexpr uint32_t RESERVED_DISCRETE_CKE_NUM = 4 * 128 | ||
| 49 | + + (CCU_REP_TRANSLATOR_CKE_NUM * 16) * 2; | ||
| 50 | +// 建链预留数量 + 开源+legacy的CcuRepReferenceManager预留数量 + 开源+legacy的CcuRepTranslator预留数量 | ||
| 51 | +constexpr uint32_t RESERVED_DISCRETE_XN_NUM = 4 * 128 | ||
| 52 | + + CCU_REPREFMGR_LEGACY_XN_NUM * 16 | ||
| 53 | + + CCU_REPREFMGR_NEW_XN_NUM * 16 | ||
| 54 | + + (CCU_REP_TRANSLATOR_XN_NUM * 16) * 2; | ||
| 55 | +// 开源+legacy的CcuRepTranslator预留数量 | ||
| 56 | +constexpr uint32_t RESERVED_DISCRETE_GSA_NUM = (CCU_REP_TRANSLATOR_GSA_NUM * 16) * 2; | ||
| 57 | + | ||
| 34 | CcuResBatchAllocator &CcuResBatchAllocator::GetInstance(const int32_t deviceLogicId) | 58 | CcuResBatchAllocator &CcuResBatchAllocator::GetInstance(const int32_t deviceLogicId) |
| 35 | { | 59 | { |
| 36 | static CcuResBatchAllocator ccuResBatchAllocator[MAX_MODULE_DEVICE_NUM + 1]; | 60 | static CcuResBatchAllocator ccuResBatchAllocator[MAX_MODULE_DEVICE_NUM + 1]; |
| @@ -65,7 +89,7 @@ HcclResult CcuResBatchAllocator::Init() | |||
| 65 | } | 89 | } |
| 66 | CHK_RET(ret); | 90 | CHK_RET(ret); |
| 67 | 91 | ||
| 68 | - ret = missionMgr_.PreAlloc(devLogicId_, resStrategys_[0].missionNum, dieEnableFlags_); | 92 | + ret = missionMgr_.PreAlloc(devLogicId_, resStrategies_[0].missionNum, dieEnableFlags_); |
| 69 | if (ret == HcclResult::HCCL_E_UNAVAIL) { | 93 | if (ret == HcclResult::HCCL_E_UNAVAIL) { |
| 70 | HCCL_WARNING("[CcuResBatchAllocator][%s] pre alloc mission res failed but passed, " | 94 | HCCL_WARNING("[CcuResBatchAllocator][%s] pre alloc mission res failed but passed, " |
| 71 | "some sources are not enough, devLogicId[%d].", __func__, devLogicId_); | 95 | "some sources are not enough, devLogicId[%d].", __func__, devLogicId_); |
| @@ -89,36 +113,81 @@ HcclResult CcuResBatchAllocator::Deinit() | |||
| 89 | return HcclResult::HCCL_SUCCESS; | 113 | return HcclResult::HCCL_SUCCESS; |
| 90 | } | 114 | } |
| 91 | 115 | ||
| 92 | -struct CcuResBlockNum { | 116 | +static CcuResBlockNums GetPreAllocatedMaxBlockNums(const uint32_t devLogicId, const uint8_t dieId, |
| 93 | - uint32_t loopNum{0}; | 117 | + const std::array<CcuBlockResStrategy, CCU_MAX_IODIE_NUM> &resStrategies) |
| 94 | - uint32_t msNum{0}; | ||
| 95 | - uint32_t ckeNum{0}; | ||
| 96 | -}; | ||
| 97 | - | ||
| 98 | -static CcuResBlockNum GetPreAllocatedMaxBlockNum(const uint32_t devLogicId, const uint8_t dieId, | ||
| 99 | - const std::array<CcuBlockResStrategy, CCU_MAX_IODIE_NUM> &resStrategys) | ||
| 100 | { | 118 | { |
| 101 | - CcuResBlockNum blockNum{}; | 119 | + CcuResBlockNums blockNums{}; |
| 102 | 120 | ||
| 103 | CcuResSpecifications &ccuResSepcs = CcuResSpecifications::GetInstance(devLogicId); | 121 | CcuResSpecifications &ccuResSepcs = CcuResSpecifications::GetInstance(devLogicId); |
| 104 | 122 | ||
| 105 | uint32_t loopNum = 0; | 123 | uint32_t loopNum = 0; |
| 106 | (void)ccuResSepcs.GetLoopEngineNum(dieId, loopNum); | 124 | (void)ccuResSepcs.GetLoopEngineNum(dieId, loopNum); |
| 107 | - blockNum.loopNum = loopNum / resStrategys[dieId].loopNum; | 125 | + blockNums.loopNum = loopNum / resStrategies[dieId].loopNum; |
| 108 | 126 | ||
| 109 | uint32_t msNum = 0; | 127 | uint32_t msNum = 0; |
| 110 | (void)ccuResSepcs.GetMsNum(dieId, msNum); | 128 | (void)ccuResSepcs.GetMsNum(dieId, msNum); |
| 111 | - blockNum.msNum = msNum / resStrategys[dieId].msNum; | 129 | + blockNums.msNum = msNum / resStrategies[dieId].msNum; |
| 112 | 130 | ||
| 113 | uint32_t ckeNum = 0; | 131 | uint32_t ckeNum = 0; |
| 114 | (void)ccuResSepcs.GetCkeNum(dieId, ckeNum); | 132 | (void)ccuResSepcs.GetCkeNum(dieId, ckeNum); |
| 115 | - const uint32_t maxCkeBlockNum = ckeNum / resStrategys[dieId].ckeNum; | 133 | + if (ckeNum > RESERVED_DISCRETE_CKE_NUM) { |
| 116 | - blockNum.ckeNum = std::min({std::max({blockNum.loopNum, blockNum.msNum}), maxCkeBlockNum}); | 134 | + blockNums.ckeNum = (ckeNum - RESERVED_DISCRETE_CKE_NUM) / resStrategies[dieId].ckeNum; |
| 135 | + } else { | ||
| 136 | + blockNums.ckeNum = 0; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + uint32_t xnNum = 0; | ||
| 140 | + (void)ccuResSepcs.GetXnNum(dieId, xnNum); | ||
| 141 | + if (xnNum > RESERVED_DISCRETE_XN_NUM) { | ||
| 142 | + blockNums.xnNum = (xnNum - RESERVED_DISCRETE_XN_NUM) / resStrategies[dieId].xnNum; | ||
| 143 | + } else { | ||
| 144 | + blockNums.xnNum = 0; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + if (ccuResSepcs.GetCcuVersion() == CcuVersion::CCU_V1) { | ||
| 148 | + uint32_t gsaNum = 0; | ||
| 149 | + (void)ccuResSepcs.GetGsaNum(dieId, gsaNum); | ||
| 150 | + if (gsaNum > RESERVED_DISCRETE_GSA_NUM) { | ||
| 151 | + blockNums.gsaNum = (gsaNum - RESERVED_DISCRETE_GSA_NUM) / resStrategies[dieId].gsaNum; | ||
| 152 | + } else { | ||
| 153 | + blockNums.gsaNum = 0; | ||
| 154 | + } | ||
| 155 | + } else { | ||
| 156 | + blockNums.gsaNum = 0; | ||
| 157 | + } | ||
| 117 | 158 | ||
| 118 | HCCL_INFO("[CcuResBatchAllocator][%s] batch allocator will alloc blocks resources: loop blocks[%u] " | 159 | HCCL_INFO("[CcuResBatchAllocator][%s] batch allocator will alloc blocks resources: loop blocks[%u] " |
| 119 | - "ms blocks[%u] cke blocks[%u], devLogicId[%d] dieId[%u].", __func__, blockNum.loopNum, | 160 | + "ms blocks[%u] cke blocks[%u] xn blocks[%u] gsa blocks[%u], devLogicId[%d] dieId[%u].", |
| 120 | - blockNum.msNum, blockNum.ckeNum, devLogicId, dieId); | 161 | + __func__, blockNums.loopNum, blockNums.msNum, blockNums.ckeNum, blockNums.xnNum, blockNums.gsaNum, |
| 121 | - return blockNum; | 162 | + devLogicId, dieId); |
| 163 | + return blockNums; | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +HcclResult CcuResBatchAllocator::GetAllocatableMaxBlockResNum(ResType resType, | ||
| 167 | + uint8_t dieId, uint32_t &num) const | ||
| 168 | +{ | ||
| 169 | + switch (resType) { | ||
| 170 | + case ResType::LOOP: | ||
| 171 | + num = maxResBlockNums_.loopNum * resStrategies_[dieId].loopNum; | ||
| 172 | + break; | ||
| 173 | + case ResType::MS: | ||
| 174 | + num = maxResBlockNums_.msNum * resStrategies_[dieId].msNum; | ||
| 175 | + break; | ||
| 176 | + case ResType::CKE: | ||
| 177 | + num = maxResBlockNums_.ckeNum * resStrategies_[dieId].ckeNum; | ||
| 178 | + break; | ||
| 179 | + case ResType::XN: | ||
| 180 | + num = maxResBlockNums_.xnNum * resStrategies_[dieId].xnNum; | ||
| 181 | + break; | ||
| 182 | + case ResType::GSA: | ||
| 183 | + num = maxResBlockNums_.gsaNum * resStrategies_[dieId].gsaNum; | ||
| 184 | + break; | ||
| 185 | + default: | ||
| 186 | + HCCL_ERROR("[CcuResBatchAllocator][%s] unsupported block res type[%s], devLogicId[%d] dieId[%u].", | ||
| 187 | + __func__, resType.Describe().c_str(), devLogicId_, dieId); | ||
| 188 | + return HcclResult::HCCL_E_PARA; | ||
| 189 | + } | ||
| 190 | + return HcclResult::HCCL_SUCCESS; | ||
| 122 | } | 191 | } |
| 123 | 192 | ||
| 124 | HcclResult CcuResBatchAllocator::PreAllocBlockRes() | 193 | HcclResult CcuResBatchAllocator::PreAllocBlockRes() |
| @@ -132,11 +201,13 @@ HcclResult CcuResBatchAllocator::PreAllocBlockRes() | |||
| 132 | continue; | 201 | continue; |
| 133 | } | 202 | } |
| 134 | 203 | ||
| 135 | - CcuResBlockNum blockNums = GetPreAllocatedMaxBlockNum(devLogicId_, dieId, resStrategys_); | 204 | + maxResBlockNums_ = GetPreAllocatedMaxBlockNums(devLogicId_, dieId, resStrategies_); |
| 136 | const std::array<std::tuple<ResType, uint32_t, uint32_t>, BLOCK_RES_TYPE_NUM> blockResReqs = { | 205 | const std::array<std::tuple<ResType, uint32_t, uint32_t>, BLOCK_RES_TYPE_NUM> blockResReqs = { |
| 137 | - std::make_tuple(ResType::LOOP, blockNums.loopNum, resStrategys_[dieId].loopNum), | 206 | + std::make_tuple(ResType::LOOP, maxResBlockNums_.loopNum, resStrategies_[dieId].loopNum), |
| 138 | - std::make_tuple(ResType::MS, blockNums.msNum, resStrategys_[dieId].msNum), | 207 | + std::make_tuple(ResType::MS, maxResBlockNums_.msNum, resStrategies_[dieId].msNum), |
| 139 | - std::make_tuple(ResType::CKE, blockNums.ckeNum, resStrategys_[dieId].ckeNum), | 208 | + std::make_tuple(ResType::CKE, maxResBlockNums_.ckeNum, resStrategies_[dieId].ckeNum), |
| 209 | + std::make_tuple(ResType::XN, maxResBlockNums_.xnNum, resStrategies_[dieId].xnNum), | ||
| 210 | + std::make_tuple(ResType::GSA, maxResBlockNums_.gsaNum, resStrategies_[dieId].gsaNum), | ||
| 140 | }; | 211 | }; |
| 141 | 212 | ||
| 142 | for (auto &resReq : blockResReqs) { | 213 | for (auto &resReq : blockResReqs) { |
| @@ -175,7 +246,7 @@ HcclResult CcuResBatchAllocator::PreAllocBlockRes() | |||
| 175 | blockInfo.handle = 0; | 246 | blockInfo.handle = 0; |
| 176 | tempBlocks.emplace_back(blockInfo); | 247 | tempBlocks.emplace_back(blockInfo); |
| 177 | } | 248 | } |
| 178 | - resBlocks_[dieId].emplace_back(tempBlocks); | 249 | + resBlocks_[dieId][resType] = std::move(tempBlocks); |
| 179 | } | 250 | } |
| 180 | } | 251 | } |
| 181 | 252 | ||
| @@ -194,16 +265,17 @@ static bool CheckReqValid(const CcuResReq &req, int32_t devLogicId, | |||
| 194 | req.blockMsReq[i], | 265 | req.blockMsReq[i], |
| 195 | req.ckeReq[i], | 266 | req.ckeReq[i], |
| 196 | req.blockCkeReq[i], | 267 | req.blockCkeReq[i], |
| 197 | - req.continuousXnReq[i], | ||
| 198 | req.xnReq[i], | 268 | req.xnReq[i], |
| 269 | + req.blockXnReq[i], | ||
| 199 | req.gsaReq[i], | 270 | req.gsaReq[i], |
| 271 | + req.blockGsaReq[i], | ||
| 200 | req.missionReq.req[i] | 272 | req.missionReq.req[i] |
| 201 | }; | 273 | }; |
| 202 | 274 | ||
| 203 | const bool ifReqEmpty = std::all_of(std::begin(reqs), std::end(reqs), | 275 | const bool ifReqEmpty = std::all_of(std::begin(reqs), std::end(reqs), |
| 204 | [](uint32_t x) { return x == 0; }); | 276 | [](uint32_t x) { return x == 0; }); |
| 205 | if (!dieEnableFlags[i] && !ifReqEmpty) { // 当前die未使能,但请求资源 | 277 | if (!dieEnableFlags[i] && !ifReqEmpty) { // 当前die未使能,但请求资源 |
| 206 | - HCCL_WARNING("[CcuResBatchAllocator][%s] failed, dieId[%u] is not enable, " | 278 | + HCCL_ERROR("[CcuResBatchAllocator][%s] failed, dieId[%u] is not enable, " |
以前是默认能走回退,这里要考虑清楚异常处理 ![]() ![]() | |||
| 207 | "but resource request is not empty, devLogicId[%d].", | 279 | "but resource request is not empty, devLogicId[%d].", |
| 208 | __func__, i, devLogicId); | 280 | __func__, i, devLogicId); |
| 209 | return false; | 281 | return false; |
| @@ -216,7 +288,7 @@ static bool CheckReqValid(const CcuResReq &req, int32_t devLogicId, | |||
| 216 | } | 288 | } |
| 217 | 289 | ||
| 218 | if (!ifValid) { | 290 | if (!ifValid) { |
| 219 | - HCCL_WARNING("[CcuResBatchAllocator][%s] all dies resource request is empty, " | 291 | + HCCL_ERROR("[CcuResBatchAllocator][%s] all dies resource request is empty, " |
| 220 | "devLogicId[%d].", __func__, devLogicId); | 292 | "devLogicId[%d].", __func__, devLogicId); |
| 221 | } | 293 | } |
| 222 | 294 | ||
| @@ -331,11 +403,15 @@ HcclResult CcuResBatchAllocator::AllocBlockRes(const uintptr_t handleKey, | |||
| 331 | 403 | ||
| 332 | std::array<ResTypeReqNumBlockNumFunc, BLOCK_RES_TYPE_NUM> blockReqParas = { | 404 | std::array<ResTypeReqNumBlockNumFunc, BLOCK_RES_TYPE_NUM> blockReqParas = { |
| 333 | std::make_tuple(ResType::LOOP, resReq.blockLoopEngineReq[dieId], | 405 | std::make_tuple(ResType::LOOP, resReq.blockLoopEngineReq[dieId], |
| 334 | - resStrategys_[dieId].loopNum, std::ref(resRepoPtr->blockLoopEngine[dieId])), | 406 | + resStrategies_[dieId].loopNum, std::ref(resRepoPtr->blockLoopEngine[dieId])), |
| 335 | std::make_tuple(ResType::MS, resReq.blockMsReq[dieId], | 407 | std::make_tuple(ResType::MS, resReq.blockMsReq[dieId], |
| 336 | - resStrategys_[dieId].msNum, std::ref(resRepoPtr->blockMs[dieId])), | 408 | + resStrategies_[dieId].msNum, std::ref(resRepoPtr->blockMs[dieId])), |
| 337 | std::make_tuple(ResType::CKE, resReq.blockCkeReq[dieId], | 409 | std::make_tuple(ResType::CKE, resReq.blockCkeReq[dieId], |
| 338 | - resStrategys_[dieId].ckeNum, std::ref(resRepoPtr->blockCke[dieId])) | 410 | + resStrategies_[dieId].ckeNum, std::ref(resRepoPtr->blockCke[dieId])), |
| 411 | + std::make_tuple(ResType::XN, resReq.blockXnReq[dieId], | ||
| 412 | + resStrategies_[dieId].xnNum, std::ref(resRepoPtr->blockXn[dieId])), | ||
| 413 | + std::make_tuple(ResType::GSA, resReq.blockGsaReq[dieId], | ||
| 414 | + resStrategies_[dieId].gsaNum, std::ref(resRepoPtr->blockGsa[dieId])) | ||
| 339 | }; | 415 | }; |
| 340 | 416 | ||
| 341 | for (uint32_t blockType = 0; blockType < BLOCK_RES_TYPE_NUM; blockType++) { | 417 | for (uint32_t blockType = 0; blockType < BLOCK_RES_TYPE_NUM; blockType++) { |
| @@ -347,7 +423,7 @@ HcclResult CcuResBatchAllocator::AllocBlockRes(const uintptr_t handleKey, | |||
| 347 | 423 | ||
| 348 | const ResType resType = std::get<0>(req); | 424 | const ResType resType = std::get<0>(req); |
| 349 | const uint32_t blockSize = std::get<2>(req); | 425 | const uint32_t blockSize = std::get<2>(req); |
| 350 | - auto &blocks = resBlocks_[dieId][blockType]; | 426 | + auto &blocks = resBlocks_[dieId][resType]; |
| 351 | auto &resInfos = std::get<3>(req); | 427 | auto &resInfos = std::get<3>(req); |
| 352 | auto ret = HandleBlockRes(handleKey, num, blockSize, blocks, resInfos); | 428 | auto ret = HandleBlockRes(handleKey, num, blockSize, blocks, resInfos); |
| 353 | if (ret != HcclResult::HCCL_SUCCESS) { | 429 | if (ret != HcclResult::HCCL_SUCCESS) { |
| @@ -355,7 +431,7 @@ HcclResult CcuResBatchAllocator::AllocBlockRes(const uintptr_t handleKey, | |||
| 355 | "failed to allocate [%s] block resource, remaining block resources are " | 431 | "failed to allocate [%s] block resource, remaining block resources are " |
| 356 | "not enough, request num[%u].", __func__, devLogicId_, dieId, | 432 | "not enough, request num[%u].", __func__, devLogicId_, dieId, |
| 357 | resType.Describe().c_str(), num); | 433 | resType.Describe().c_str(), num); |
| 358 | - DumpBlockResInfo(std::get<0>(req), resBlocks_[dieId][blockType]); | 434 | + DumpBlockResInfo(resType, resBlocks_[dieId][resType]); |
| 359 | return ret; | 435 | return ret; |
| 360 | } | 436 | } |
| 361 | } | 437 | } |
| @@ -377,8 +453,8 @@ HcclResult CcuResBatchAllocator::AllocConsecutiveRes(const CcuResReq &resReq, | |||
| 377 | } | 453 | } |
| 378 | 454 | ||
| 379 | std::array<ResTypeReqNumResInfoTuple, CONS_RES_TYPE_NUM> reqParas = { | 455 | std::array<ResTypeReqNumResInfoTuple, CONS_RES_TYPE_NUM> reqParas = { |
| 380 | - std::make_tuple(ResType::XN, resReq.continuousXnReq[dieId], | 456 | + std::make_tuple(ResType::XN, resReq.xnReq[dieId], |
| 381 | - std::ref(resRepoPtr->continuousXn[dieId])) | 457 | + std::ref(resRepoPtr->xn[dieId])) |
| 382 | }; | 458 | }; |
| 383 | 459 | ||
| 384 | for (const auto &req : reqParas) { | 460 | for (const auto &req : reqParas) { |
| @@ -422,7 +498,6 @@ HcclResult CcuResBatchAllocator::AllocDiscreteRes(const CcuResReq &resReq, | |||
| 422 | std::ref(resRepoPtr->loopEngine[dieId])), | 498 | std::ref(resRepoPtr->loopEngine[dieId])), |
| 423 | std::make_tuple(ResType::MS, resReq.msReq[dieId], std::ref(resRepoPtr->ms[dieId])), | 499 | std::make_tuple(ResType::MS, resReq.msReq[dieId], std::ref(resRepoPtr->ms[dieId])), |
| 424 | std::make_tuple(ResType::CKE, resReq.ckeReq[dieId], std::ref(resRepoPtr->cke[dieId])), | 500 | std::make_tuple(ResType::CKE, resReq.ckeReq[dieId], std::ref(resRepoPtr->cke[dieId])), |
| 425 | - std::make_tuple(ResType::XN, resReq.xnReq[dieId], std::ref(resRepoPtr->xn[dieId])), | ||
| 426 | std::make_tuple(ResType::GSA, resReq.gsaReq[dieId], std::ref(resRepoPtr->gsa[dieId])) | 501 | std::make_tuple(ResType::GSA, resReq.gsaReq[dieId], std::ref(resRepoPtr->gsa[dieId])) |
| 427 | }; | 502 | }; |
| 428 | 503 | ||
| @@ -546,7 +621,7 @@ HcclResult CcuResBatchAllocator::ReleaseResource(std::unique_ptr<CcuResRepositor | |||
| 546 | 621 | ||
| 547 | void CcuResBatchAllocator::ReleaseBlockResource(std::unique_ptr<CcuResRepository> &resRepoPtr) | 622 | void CcuResBatchAllocator::ReleaseBlockResource(std::unique_ptr<CcuResRepository> &resRepoPtr) |
| 548 | { | 623 | { |
| 549 | - using BlockSizeResNum = std::pair<uint32_t, std::vector<ResInfo>&>; | 624 | + using BlockSizeResNum = std::tuple<ResType, uint32_t, std::vector<ResInfo>&>; |
| 550 | 625 | ||
| 551 | for (uint8_t i = 0; i < CCU_MAX_IODIE_NUM; i++) { | 626 | for (uint8_t i = 0; i < CCU_MAX_IODIE_NUM; i++) { |
| 552 | if (!dieEnableFlags_[i]) { | 627 | if (!dieEnableFlags_[i]) { |
| @@ -554,19 +629,22 @@ void CcuResBatchAllocator::ReleaseBlockResource(std::unique_ptr<CcuResRepository | |||
| 554 | } | 629 | } |
| 555 | 630 | ||
| 556 | const std::array<BlockSizeResNum, BLOCK_RES_TYPE_NUM> blockReqParas = { | 631 | const std::array<BlockSizeResNum, BLOCK_RES_TYPE_NUM> blockReqParas = { |
| 557 | - std::make_pair(resStrategys_[i].loopNum, std::ref(resRepoPtr->blockLoopEngine[i])), | 632 | + std::make_tuple(ResType::LOOP, resStrategies_[i].loopNum, std::ref(resRepoPtr->blockLoopEngine[i])), |
| 558 | - std::make_pair(resStrategys_[i].msNum, std::ref(resRepoPtr->blockMs[i])), | 633 | + std::make_tuple(ResType::MS, resStrategies_[i].msNum, std::ref(resRepoPtr->blockMs[i])), |
| 559 | - std::make_pair(resStrategys_[i].ckeNum, std::ref(resRepoPtr->blockCke[i])) | 634 | + std::make_tuple(ResType::CKE, resStrategies_[i].ckeNum, std::ref(resRepoPtr->blockCke[i])), |
| 635 | + std::make_tuple(ResType::XN, resStrategies_[i].xnNum, std::ref(resRepoPtr->blockXn[i])), | ||
| 636 | + std::make_tuple(ResType::GSA, resStrategies_[i].gsaNum, std::ref(resRepoPtr->blockGsa[i])) | ||
| 560 | }; | 637 | }; |
| 561 | 638 | ||
| 562 | for (uint32_t j = 0; j < BLOCK_RES_TYPE_NUM; j++) { | 639 | for (uint32_t j = 0; j < BLOCK_RES_TYPE_NUM; j++) { |
| 563 | auto req = blockReqParas[j]; | 640 | auto req = blockReqParas[j]; |
| 564 | - std::vector<ResInfo> &resInfos = req.second; | 641 | + std::vector<ResInfo> &resInfos = std::get<2>(req); |
| 565 | - if (resInfos.size() == 0) { | 642 | + auto resType = std::get<0>(req); |
| 643 | + std::vector<BlockInfo> &blocks = resBlocks_[i][resType]; | ||
| 644 | + if (resInfos.size() == 0 || blocks.size() == 0) { | ||
| 566 | continue; | 645 | continue; |
| 567 | } | 646 | } |
| 568 | - | 647 | + ReleaseBlockRes(std::get<1>(req), blocks, resInfos); |
| 569 | - ReleaseBlockRes(req.first, resBlocks_[i][j], resInfos); | ||
| 570 | } | 648 | } |
| 571 | } | 649 | } |
| 572 | } | 650 | } |
| @@ -629,7 +707,6 @@ HcclResult CcuResBatchAllocator::ReleaseNonBlockTypeRes( | |||
| 629 | {ResType::LOOP, &resRepoPtr->loopEngine[dieId]}, | 707 | {ResType::LOOP, &resRepoPtr->loopEngine[dieId]}, |
| 630 | {ResType::MS, &resRepoPtr->ms[dieId]}, | 708 | {ResType::MS, &resRepoPtr->ms[dieId]}, |
| 631 | {ResType::CKE, &resRepoPtr->cke[dieId]}, | 709 | {ResType::CKE, &resRepoPtr->cke[dieId]}, |
| 632 | - {ResType::XN, &resRepoPtr->continuousXn[dieId]}, | ||
| 633 | {ResType::XN, &resRepoPtr->xn[dieId]}, | 710 | {ResType::XN, &resRepoPtr->xn[dieId]}, |
| 634 | {ResType::GSA, &resRepoPtr->gsa[dieId]} | 711 | {ResType::GSA, &resRepoPtr->gsa[dieId]} |
| 635 | }}; | 712 | }}; |
| @@ -822,4 +899,65 @@ void CcuResBatchAllocator::CcuMissionMgr::Reset() | |||
| 822 | blocks_.clear(); | 899 | blocks_.clear(); |
| 823 | } | 900 | } |
| 824 | 901 | ||
| 825 | -}; // namespace hcomm | 902 | +// 根据 resType 解析对应的 blocks 指针,将 MISSION 与普通块类型的分支收敛至此 |
| 903 | +// GetAllocatableMaxBlockResNum 内部通过 switch 校验块类型,非法类型直接返回错误 | ||
| 904 | +HcclResult CcuResBatchAllocator::ResolveBlocksPtr(uint8_t dieId, ResType resType, | ||
| 905 | + const std::vector<BlockInfo>*& blocksPtr) const | ||
| 906 | +{ | ||
| 907 | + if (resType == ResType::MISSION) { | ||
| 908 | + blocksPtr = &missionMgr_.GetBlocks(); | ||
| 909 | + return HCCL_SUCCESS; | ||
| 910 | + } | ||
| 911 | + | ||
| 912 | + uint32_t poolSize = 0; | ||
| 913 | + CHK_RET(GetAllocatableMaxBlockResNum(resType, dieId, poolSize)); | ||
| 914 | + if (poolSize == 0) { | ||
| 915 | + blocksPtr = nullptr; | ||
| 916 | + return HCCL_SUCCESS; | ||
| 917 | + } | ||
| 918 | + | ||
| 919 | + auto it = resBlocks_[dieId].find(resType); | ||
| 920 | + if (it == resBlocks_[dieId].end()) { | ||
| 921 | + blocksPtr = nullptr; | ||
| 922 | + return HCCL_SUCCESS; | ||
| 923 | + } | ||
| 924 | + blocksPtr = &it->second; | ||
| 925 | + return HCCL_SUCCESS; | ||
| 926 | +} | ||
| 927 | + | ||
| 928 | +// 直接扫描 resBlocks 的 allocated 标志计算最大连续空闲块数 × blockSize | ||
| 929 | +// Block 分配时 HandleBlockRes 同步更新 allocated, 无需绕道 handleMap | ||
| 930 | +HcclResult CcuResBatchAllocator::QueryRemainRes( | ||
| 931 | + uint8_t dieId, ResType resType, uint32_t &remainNum) const | ||
| 932 | +{ | ||
| 933 | + const std::vector<BlockInfo> *blocksPtr = nullptr; | ||
| 934 | + uint32_t blockSize = 0; | ||
| 935 | + | ||
| 936 | + CHK_RET(ResolveBlocksPtr(dieId, resType, blocksPtr)); | ||
| 937 | + if (blocksPtr == nullptr || blocksPtr->empty()) { | ||
| 938 | + remainNum = 0; | ||
| 939 | + return HCCL_SUCCESS; | ||
| 940 | + } | ||
| 941 | + | ||
| 942 | + blockSize = blocksPtr->front().num; | ||
| 943 | + uint32_t maxFreeBlocks = 0; | ||
| 944 | + uint32_t curFreeBlocks = 0; | ||
| 945 | + for (const auto &block : *blocksPtr) { | ||
| 946 | + if (!block.allocated) { | ||
| 947 | + curFreeBlocks++; | ||
| 948 | + continue; | ||
| 949 | + } | ||
| 950 | + maxFreeBlocks = curFreeBlocks > maxFreeBlocks ? curFreeBlocks : maxFreeBlocks; | ||
| 951 | + curFreeBlocks = 0; | ||
| 952 | + } | ||
| 953 | + if (curFreeBlocks > maxFreeBlocks) { | ||
| 954 | + maxFreeBlocks = curFreeBlocks; | ||
| 955 | + } | ||
| 956 | + | ||
| 957 | + remainNum = maxFreeBlocks * blockSize; | ||
| 958 | + HCCL_INFO("[CcuResBatchAllocator][%s] resType[%s] maxFreeBlocks[%u] blockSize[%u] remainNum[%u]", | ||
| 959 | + __func__, resType.Describe().c_str(), maxFreeBlocks, blockSize, remainNum); | ||
| 960 | + return HCCL_SUCCESS; | ||
| 961 | +} | ||
| 962 | + | ||
| 963 | +}; // namespace hcomm | ||
| @@ -20,6 +20,8 @@ | |||
| 20 | 20 | ||
| 21 | #include "ccu_res_specs.h" | 21 | #include "ccu_res_specs.h" |
| 22 | #include "ccu_dev_mgr_imp.h" | 22 | #include "ccu_dev_mgr_imp.h" |
| 23 | +#include "ccu_device_res.h" | ||
| 24 | +#include "ccu_res_desc.h" | ||
| 23 | 25 | ||
| 24 | namespace hcomm { | 26 | namespace hcomm { |
| 25 | 27 | ||
| @@ -31,6 +33,14 @@ struct BlockInfo { | |||
| 31 | bool allocated{false}; | 33 | bool allocated{false}; |
| 32 | }; | 34 | }; |
| 33 | 35 | ||
| 36 | +struct CcuResBlockNums { | ||
| 37 | + uint32_t loopNum{0}; | ||
| 38 | + uint32_t msNum{0}; | ||
| 39 | + uint32_t ckeNum{0}; | ||
| 40 | + uint32_t xnNum{0}; | ||
| 41 | + uint32_t gsaNum{0}; | ||
| 42 | +}; | ||
| 43 | + | ||
| 34 | class CcuResBatchAllocator { | 44 | class CcuResBatchAllocator { |
| 35 | public: | 45 | public: |
| 36 | static CcuResBatchAllocator& GetInstance(const int32_t deviceLogicId); | 46 | static CcuResBatchAllocator& GetInstance(const int32_t deviceLogicId); |
| @@ -40,7 +50,10 @@ public: | |||
| 40 | HcclResult AllocResHandle(const CcuResReq& resReq, CcuResHandle &resHandle); | 50 | HcclResult AllocResHandle(const CcuResReq& resReq, CcuResHandle &resHandle); |
| 41 | HcclResult ReleaseResHandle(const CcuResHandle& handle); | 51 | HcclResult ReleaseResHandle(const CcuResHandle& handle); |
| 42 | HcclResult GetResource(const CcuResHandle& handle, CcuResRepository &ccuResRepo); | 52 | HcclResult GetResource(const CcuResHandle& handle, CcuResRepository &ccuResRepo); |
| 43 | - | 53 | + HcclResult QueryRemainRes(uint8_t dieId, ResType resType, uint32_t &remainNum) const; |
| 54 | + // 获取指定 die 上可分配的块类型资源数量 = 预分配块数量 × CcuBlockResStrategy 对应块大小 | ||
| 55 | + // 仅支持 ResType::LOOP / MS / CKE / XN / GSA | ||
| 56 | + HcclResult GetAllocatableMaxBlockResNum(ResType resType, uint8_t dieId, uint32_t &num) const; | ||
| 44 | private: | 57 | private: |
| 45 | class CcuMissionMgr { | 58 | class CcuMissionMgr { |
| 46 | public: | 59 | public: |
| @@ -53,7 +66,8 @@ private: | |||
| 53 | HcclResult Alloc(const uintptr_t handleKey, const MissionReq &missionReq, | 66 | HcclResult Alloc(const uintptr_t handleKey, const MissionReq &missionReq, |
| 54 | MissionResInfo &missionInfos); | 67 | MissionResInfo &missionInfos); |
| 55 | void Release(MissionResInfo &missionInfos); | 68 | void Release(MissionResInfo &missionInfos); |
| 56 | - | 69 | + const std::vector<BlockInfo>& GetBlocks() const { return blocks_; } |
| 70 | + | ||
| 57 | private: | 71 | private: |
| 58 | uint32_t stragtegy_{0}; | 72 | uint32_t stragtegy_{0}; |
| 59 | std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags_; | 73 | std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags_; |
| @@ -78,19 +92,21 @@ private: | |||
| 78 | HcclResult ReleaseResource(std::unique_ptr<CcuResRepository>& resRepoPtr); | 92 | HcclResult ReleaseResource(std::unique_ptr<CcuResRepository>& resRepoPtr); |
| 79 | void ReleaseBlockResource(std::unique_ptr<CcuResRepository> &resRepoPtr); | 93 | void ReleaseBlockResource(std::unique_ptr<CcuResRepository> &resRepoPtr); |
| 80 | HcclResult ReleaseNonBlockTypeRes(std::unique_ptr<CcuResRepository>& resRepoPtr) const; | 94 | HcclResult ReleaseNonBlockTypeRes(std::unique_ptr<CcuResRepository>& resRepoPtr) const; |
| 81 | - | 95 | + // 根据 resType 解析对应的 blocks 指针,用于 QueryRemainRes 降低圈复杂度 |
| 96 | + HcclResult ResolveBlocksPtr(uint8_t dieId, ResType resType, const std::vector<BlockInfo>*& blocksPtr) const; | ||
| 82 | private: | 97 | private: |
| 83 | - std::mutex innerMutex_; | 98 | + mutable std::mutex innerMutex_; |
| 84 | int32_t devLogicId_{0}; | 99 | int32_t devLogicId_{0}; |
| 85 | bool initFlag_{false}; | 100 | bool initFlag_{false}; |
| 86 | std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags_{}; | 101 | std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags_{}; |
| 87 | - std::array<CcuBlockResStrategy, CCU_MAX_IODIE_NUM> resStrategys_{}; | 102 | + std::array<CcuBlockResStrategy, CCU_MAX_IODIE_NUM> resStrategies_{}; |
| 88 | - std::array<std::vector<std::vector<BlockInfo>>, CCU_MAX_IODIE_NUM> resBlocks_{}; | 103 | + std::array<std::unordered_map<ResType, std::vector<BlockInfo>, std::EnumClassHash>, CCU_MAX_IODIE_NUM> resBlocks_{}; |
| 89 | // 键值为CcuResRepository裸指针转换的uintptr_t | 104 | // 键值为CcuResRepository裸指针转换的uintptr_t |
| 90 | std::unordered_map<uintptr_t, std::unique_ptr<CcuResRepository>> handleMap_{}; | 105 | std::unordered_map<uintptr_t, std::unique_ptr<CcuResRepository>> handleMap_{}; |
| 91 | CcuMissionMgr missionMgr_{}; | 106 | CcuMissionMgr missionMgr_{}; |
| 107 | + CcuResBlockNums maxResBlockNums_{}; | ||
| 92 | }; | 108 | }; |
| 93 | 109 | ||
| 94 | }; // namespace hcomm | 110 | }; // namespace hcomm |
| 95 | 111 | ||
| 96 | -#endif // CCU_RES_BATCH_ALLOCATOR_H | 112 | +#endif // CCU_RES_BATCH_ALLOCATOR_H |
| @@ -0,0 +1,46 @@ | |||
| 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 | + | ||
| 11 | +#include "ccu_res_desc.h" | ||
| 12 | + | ||
| 13 | +namespace hcomm { | ||
| 14 | +static_assert(CCU_RES_TYPE_COUNT == static_cast<size_t>(ResType::__COUNT__), | ||
| 15 | + "CCU_RES_TYPE_COUNT must match ResType::__COUNT__"); | ||
| 16 | + | ||
| 17 | +CcuResult CcuResDesc::SetResNum(ResType resType, uint32_t num) | ||
| 18 | +{ | ||
| 19 | + if (!IsValidResType(resType)) { | ||
| 20 | + return CcuResult::CCU_E_PARA; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + resNum[ResTypeIndex(resType)] = num; | ||
| 24 | + return CcuResult::CCU_SUCCESS; | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +CcuResult CcuResDesc::QueryResNum(ResType resType, uint32_t &num) const | ||
| 28 | +{ | ||
| 29 | + if (!IsValidResType(resType)) { | ||
| 30 | + return CcuResult::CCU_E_PARA; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + num = resNum[ResTypeIndex(resType)]; | ||
| 34 | + return CcuResult::CCU_SUCCESS; | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +bool CcuResDesc::IsValidResType(ResType resType) | ||
| 38 | +{ | ||
| 39 | + return resType < ResType::__COUNT__; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +size_t CcuResDesc::ResTypeIndex(ResType resType) | ||
| 43 | +{ | ||
| 44 | + return static_cast<size_t>(static_cast<ResType::Value>(resType)); | ||
| 45 | +} | ||
| 46 | +} // namespace hcomm | ||
| @@ -0,0 +1,49 @@ | |||
| 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 | + | ||
| 11 | +#ifndef HCOMM_CCU_RES_DESC_H | ||
| 12 | +#define HCOMM_CCU_RES_DESC_H | ||
| 13 | + | ||
| 14 | +#include <array> | ||
| 15 | +#include <cstddef> | ||
| 16 | + | ||
| 17 | +#include "ccu_common.h" | ||
| 18 | +#include "ccu_res_defs.h" | ||
| 19 | +#include "ccu_types.h" | ||
| 20 | +#include "ccu_dev_mgr_imp.h" | ||
| 21 | + | ||
| 22 | +namespace hcomm { | ||
| 23 | + | ||
| 24 | +// CCU 资源类型数量,需与 ResType::__COUNT__ 保持一致 | ||
| 25 | +constexpr size_t CCU_RES_TYPE_COUNT = 8; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * @brief CCU 资源描述符,描述单个 ioDie 上各类资源的申请数量 | ||
| 29 | + * | ||
| 30 | + * @note 该结构被 ccu_device 层(CcuAllocResHandleByResDescs)与 | ||
| 31 | + * ccu_instance 层(CcuResDescMgr/CcuInstance)共用, | ||
| 32 | + * 因此定义在 ccu_device 下避免 ccu_device 反向依赖 ccu_instance。 | ||
| 33 | + */ | ||
| 34 | +class CcuResDesc { | ||
| 35 | +public: | ||
| 36 | + uint32_t dieId{CCU_MAX_IODIE_NUM}; | ||
| 37 | + std::array<uint32_t, CCU_RES_TYPE_COUNT> resNum{}; | ||
| 38 | + | ||
| 39 | + CcuResult SetResNum(ResType resType, uint32_t num); | ||
| 40 | + CcuResult QueryResNum(ResType resType, uint32_t &num) const; | ||
| 41 | + | ||
| 42 | +private: | ||
| 43 | + static bool IsValidResType(ResType resType); | ||
| 44 | + static size_t ResTypeIndex(ResType resType); | ||
| 45 | +}; | ||
| 46 | + | ||
| 47 | +} // namespace hcomm | ||
| 48 | + | ||
| 49 | +#endif // HCOMM_CCU_RES_DESC_H | ||
| @@ -65,6 +65,8 @@ struct CcuBlockResStrategy { | |||
| 65 | uint32_t loopNum{16}; | 65 | uint32_t loopNum{16}; |
| 66 | uint32_t ckeNum{16}; | 66 | uint32_t ckeNum{16}; |
| 67 | uint32_t msNum{128}; | 67 | uint32_t msNum{128}; |
| 68 | + uint32_t xnNum{16}; | ||
| 69 | + uint32_t gsaNum{16}; | ||
| 68 | uint32_t missionNum{2}; | 70 | uint32_t missionNum{2}; |
| 69 | }; | 71 | }; |
| 70 | 72 | ||
| @@ -11,6 +11,7 @@ | |||
| 11 | set(src_list | 11 | set(src_list |
| 12 | ccu_res_pack.cc | 12 | ccu_res_pack.cc |
| 13 | ccu_instance.cc | 13 | ccu_instance.cc |
| 14 | + ccu_res_desc_mgr.cc | ||
| 14 | ccu_instance_mgr.cc | 15 | ccu_instance_mgr.cc |
| 15 | ) | 16 | ) |
| 16 | 17 | ||
| @@ -21,4 +22,4 @@ if(TARGET hcomm) | |||
| 21 | target_include_directories(hcomm PRIVATE | 22 | target_include_directories(hcomm PRIVATE |
| 22 | ${CMAKE_CURRENT_SOURCE_DIR} | 23 | ${CMAKE_CURRENT_SOURCE_DIR} |
| 23 | ) | 24 | ) |
| 24 | -endif() | 25 | +endif() |
| @@ -19,6 +19,8 @@ | |||
| 19 | 19 | ||
| 20 | #include "ccu_res_pack.h" | 20 | #include "ccu_res_pack.h" |
| 21 | #include "ccu_kernel_mgr.h" | 21 | #include "ccu_kernel_mgr.h" |
| 22 | +#include "ccu_res_specs.h" | ||
| 23 | +#include "ccu_dev_mgr_imp.h" | ||
| 22 | 24 | ||
| 23 | namespace hcomm { | 25 | namespace hcomm { |
| 24 | 26 | ||
| @@ -33,19 +35,19 @@ CcuInstance::~CcuInstance() | |||
| 33 | } | 35 | } |
| 34 | kernelHandles_.clear(); | 36 | kernelHandles_.clear(); |
| 35 | 37 | ||
| 36 | - resPack_ = nullptr; // 释放通信域持有CCU资源 | 38 | + resPack_ = nullptr; // 释放instance持有的CCU资源 |
| 37 | if (ccuDrvHandle_) { | 39 | if (ccuDrvHandle_) { |
| 38 | ccuDrvHandle_ = nullptr; // 先减少引用计数,再尝试关闭 | 40 | ccuDrvHandle_ = nullptr; // 先减少引用计数,再尝试关闭 |
| 39 | (void)CcuDeinitFeature(devLogicId_); | 41 | (void)CcuDeinitFeature(devLogicId_); |
| 40 | - // 尝试关闭CCU功能,最后一个通信域调用时会关闭CCU驱动 | 42 | + // 尝试关闭CCU功能,最后一个调用时会关闭CCU驱动 |
| 41 | } | 43 | } |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | -CcuResult CcuInstance::Init() | 46 | +CcuResult CcuInstance::InitByInsType(const CcuInstanceType insType) |
| 45 | { | 47 | { |
| 46 | - if (insType_ >= CcuInstanceType::CCU_UNUSED) { | 48 | + if (insType >= CcuInstanceType::CCU_UNUSED) { |
| 47 | HCCL_ERROR("[CcuInstance][%s] failed, CcuInstanceType[%d] is invalid.", | 49 | HCCL_ERROR("[CcuInstance][%s] failed, CcuInstanceType[%d] is invalid.", |
| 48 | - __func__, insType_); | 50 | + __func__, insType); |
| 49 | return CcuResult::CCU_E_PARA; | 51 | return CcuResult::CCU_E_PARA; |
| 50 | } | 52 | } |
| 51 | 53 | ||
| @@ -56,9 +58,87 @@ CcuResult CcuInstance::Init() | |||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | if (!resPack_) { | 60 | if (!resPack_) { |
| 59 | - resPack_.reset(new (std::nothrow) CcuResPack(insType_)); | 61 | + resPack_.reset(new (std::nothrow) CcuResPack()); |
| 60 | CCU_CHK_PTR_NULL(resPack_); | 62 | CCU_CHK_PTR_NULL(resPack_); |
| 61 | - CCU_CHK_RET(resPack_->Init()); | 63 | + CCU_CHK_RET(resPack_->InitByInsType(insType)); |
这里资源申请可能不足需要回退,要专门处理返回值 ![]() ![]() guoziqi Jul 25 Comments: Jul 25 Comments: ![]() ![]() | |||
| 64 | + CCU_CHK_RET(FillTotalResDescs()); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + return CcuResult::CCU_SUCCESS; | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +CcuResult CcuInstance::InitByResDescs(const CcuResDesc *descs[], uint32_t descNum) | ||
| 71 | +{ | ||
| 72 | + if (descs == nullptr || descNum == 0 || descNum > hcomm::CCU_MAX_IODIE_NUM) { | ||
| 73 | + HCCL_ERROR("[CcuInstance][%s] failed, invalid descs[%p] descNum[%u].", | ||
| 74 | + __func__, descs, descNum); | ||
| 75 | + return CcuResult::CCU_E_PARA; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + devLogicId_ = HcclGetThreadDeviceId(); | ||
| 79 | + | ||
| 80 | + if (!ccuDrvHandle_) { | ||
| 81 | + CCU_CHK_RET(CcuInitFeature(devLogicId_, ccuDrvHandle_)); | ||
要处理驱动拉取失败的回退,明确是否算错误 ![]() ![]() | |||
| 82 | + } | ||
| 83 | + | ||
| 84 | + if (!resPack_) { | ||
| 85 | + resPack_.reset(new (std::nothrow) CcuResPack()); | ||
| 86 | + CCU_CHK_PTR_NULL(resPack_); | ||
| 87 | + CCU_CHK_RET(resPack_->InitByResDescs(descs, descNum)); | ||
| 88 | + CCU_CHK_RET(FillTotalResDescs()); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + return CcuResult::CCU_SUCCESS; | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +CcuResult CcuInstance::InitByAllRes() | ||
| 95 | +{ | ||
| 96 | + devLogicId_ = HcclGetThreadDeviceId(); | ||
| 97 | + | ||
| 98 | + if (!ccuDrvHandle_) { | ||
| 99 | + CCU_CHK_RET(CcuInitFeature(devLogicId_, ccuDrvHandle_)); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + // 申请当前 Device 上所有已使能 ioDie 的全部资源: | ||
| 103 | + // 先查询各 die 是否启用,仅对已使能的 die 调用 CcuGetXXXNum 获取资源总量, | ||
| 104 | + // 未启用的 die 其 resNum 保持 0(resNum 默认初始化为 0) | ||
| 105 | + std::array<hcomm::CcuResDesc, hcomm::CCU_MAX_IODIE_NUM> descs{}; | ||
| 106 | + std::array<const hcomm::CcuResDesc *, hcomm::CCU_MAX_IODIE_NUM> descPtrs{}; | ||
| 107 | + for (uint8_t i = 0; i < hcomm::CCU_MAX_IODIE_NUM; i++) { | ||
| 108 | + descs[i].dieId = i; | ||
| 109 | + descPtrs[i] = &descs[i]; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + for (uint8_t dieId = 0; dieId < hcomm::CCU_MAX_IODIE_NUM; dieId++) { | ||
| 113 | + bool dieEnable = false; | ||
| 114 | + CCU_CHK_RET(CcuGetDieEnableInfo(devLogicId_, dieId, dieEnable)); | ||
| 115 | + if (!dieEnable) { | ||
| 116 | + continue; // 未启用的 die,resNum 保持 0 | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + uint32_t num = 0; | ||
| 120 | + // 各资源类型总量查询(per-die),按块分的资源查的是块大小*块总数 | ||
| 121 | + CCU_CHK_RET(CcuGetLoopEngineNum(devLogicId_, dieId, num)); | ||
| 122 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::LOOP, num)); | ||
| 123 | + CCU_CHK_RET(CcuGetMsNum(devLogicId_, dieId, num)); | ||
| 124 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::MS, num)); | ||
| 125 | + CCU_CHK_RET(CcuGetCkeNum(devLogicId_, dieId, num)); | ||
| 126 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::CKE, num)); | ||
| 127 | + CCU_CHK_RET(CcuGetXnNum(devLogicId_, dieId, num)); | ||
| 128 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::XN, num)); | ||
| 129 | + CCU_CHK_RET(CcuGetGsaNum(devLogicId_, dieId, num)); | ||
| 130 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::GSA, num)); | ||
| 131 | + CCU_CHK_RET(CcuGetInstructionNum(devLogicId_, dieId, num)); | ||
| 132 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::INS, num)); | ||
| 133 | + CCU_CHK_RET(CcuGetMissionNum(devLogicId_, dieId, num)); | ||
| 134 | + CCU_CHK_RET(descs[dieId].SetResNum(ResType::MISSION, num)); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + if (!resPack_) { | ||
| 138 | + resPack_.reset(new (std::nothrow) CcuResPack()); | ||
| 139 | + CCU_CHK_PTR_NULL(resPack_); | ||
| 140 | + CCU_CHK_RET(resPack_->InitByResDescs(descPtrs.data(), hcomm::CCU_MAX_IODIE_NUM)); | ||
| 141 | + CCU_CHK_RET(FillTotalResDescs()); | ||
| 62 | } | 142 | } |
| 63 | 143 | ||
| 64 | return CcuResult::CCU_SUCCESS; | 144 | return CcuResult::CCU_SUCCESS; |
| @@ -80,6 +160,50 @@ CcuResPack *CcuInstance::GetResPack() | |||
| 80 | return resPack_.get(); | 160 | return resPack_.get(); |
| 81 | } | 161 | } |
| 82 | 162 | ||
| 163 | +// 累加某 die 上某资源 vector 中各 ResInfo::num,得到该 die 该资源的占用数量 | ||
| 164 | +static uint32_t SumResNum(const std::vector<ResInfo> &resInfos, std::string resName) | ||
| 165 | +{ | ||
| 166 | + uint32_t total = 0; | ||
| 167 | + for (const auto &info : resInfos) { | ||
| 168 | + total += info.num; | ||
| 169 | + } | ||
| 170 | + HCCL_INFO("[CcuInstance][FillTotalResDescs] resType: %s, resNum: %u", resName.c_str(), total); | ||
| 171 | + return total; | ||
| 172 | +} | ||
| 173 | + | ||
| 174 | +CcuResult CcuInstance::FillTotalResDescs() | ||
| 175 | +{ | ||
| 176 | + if (resPack_ == nullptr) { | ||
| 177 | + HCCL_ERROR("[CcuInstance][%s] failed, resPack_ is nullptr.", __func__); | ||
| 178 | + return CcuResult::CCU_E_INTERNAL; | ||
| 179 | + } | ||
| 180 | + const auto &resRepo = resPack_->GetCcuResRepo(); | ||
| 181 | + | ||
| 182 | + for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) { | ||
| 183 | + totalResDescs_[dieId].dieId = dieId; | ||
| 184 | + // 各资源类型占用数量 = block 路径 + 非 block 连续路径之和 | ||
| 185 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::LOOP, | ||
| 186 | + SumResNum(resRepo.blockLoopEngine[dieId], "blockLoopEngine") + SumResNum(resRepo.loopEngine[dieId], "loopEngine"))); | ||
| 187 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::MS, | ||
| 188 | + SumResNum(resRepo.blockMs[dieId], "blockMs") + SumResNum(resRepo.ms[dieId], "ms"))); | ||
| 189 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::CKE, | ||
| 190 | + SumResNum(resRepo.blockCke[dieId], "blockCke") + SumResNum(resRepo.cke[dieId], "cke"))); | ||
| 191 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::XN, | ||
| 192 | + SumResNum(resRepo.blockXn[dieId], "blockXn") + SumResNum(resRepo.xn[dieId], "xn"))); | ||
| 193 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::GSA, | ||
| 194 | + SumResNum(resRepo.blockGsa[dieId], "blockGsa") + SumResNum(resRepo.gsa[dieId], "gsa"))); | ||
| 195 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::MISSION, SumResNum(resRepo.mission.mission[dieId], "mission"))); | ||
| 196 | + // INS 当前无对应占用资源项,写 0 | ||
| 197 | + CCU_CHK_RET(totalResDescs_[dieId].SetResNum(ResType::INS, 0)); | ||
| 198 | + } | ||
| 199 | + return CcuResult::CCU_SUCCESS; | ||
| 200 | +} | ||
| 201 | + | ||
| 202 | +const CcuResDesc &CcuInstance::GetTotalResDescs(uint8_t dieId) const | ||
| 203 | +{ | ||
| 204 | + return totalResDescs_[dieId]; | ||
| 205 | +} | ||
| 206 | + | ||
| 83 | CcuResult CcuInstance::SaveKernel(const CcuKernelHandle kernelHandle) | 207 | CcuResult CcuInstance::SaveKernel(const CcuKernelHandle kernelHandle) |
| 84 | { | 208 | { |
| 85 | kernelHandles_.push_back(kernelHandle); | 209 | kernelHandles_.push_back(kernelHandle); |
| @@ -8,9 +8,10 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | -#ifndef CCU_RES_CONTAINER_H | 11 | +#ifndef HCOMM_CCU_INSTANCE_H |
| 12 | -#define CCU_RES_CONTAINER_H | 12 | +#define HCOMM_CCU_INSTANCE_H |
| 13 | 13 | ||
| 14 | +#include <array> | ||
| 14 | #include <memory> | 15 | #include <memory> |
| 15 | #include <vector> | 16 | #include <vector> |
| 16 | 17 | ||
| @@ -18,6 +19,8 @@ | |||
| 18 | #include "ccu_res_pack.h" | 19 | #include "ccu_res_pack.h" |
| 19 | #include "ccu_drv_handle.h" | 20 | #include "ccu_drv_handle.h" |
| 20 | #include "ccu_device_res.h" | 21 | #include "ccu_device_res.h" |
| 22 | +#include "ccu_res_desc.h" | ||
| 23 | +#include "ccu_res_desc_mgr.h" | ||
| 21 | 24 | ||
| 22 | namespace hcomm { | 25 | namespace hcomm { |
| 23 | 26 | ||
| @@ -26,11 +29,17 @@ namespace hcomm { | |||
| 26 | */ | 29 | */ |
| 27 | class CcuInstance { | 30 | class CcuInstance { |
| 28 | public: | 31 | public: |
| 29 | - explicit CcuInstance(CcuInstanceType insType) : insType_(insType) {}; | 32 | + explicit CcuInstance(){}; |
| 30 | ~CcuInstance(); | 33 | ~CcuInstance(); |
| 31 | - CcuResult Init(); | 34 | + CcuResult InitByInsType(const CcuInstanceType insType); |
如果保留instance type,是否保留成员变量用于定位 ![]() ![]() | |||
| 35 | + // 基于资源描述符数组初始化(新接口路径,资源数量由 resDesc 驱动) | ||
| 36 | + CcuResult InitByResDescs(const CcuResDesc *descs[], uint32_t descNum); | ||
| 37 | + // 使用当前 Device 上所有已使能 ioDie 的全部资源初始化 | ||
| 38 | + CcuResult InitByAllRes(); | ||
| 32 | CcuResult Reset(); | 39 | CcuResult Reset(); |
| 33 | CcuResPack *GetResPack(); | 40 | CcuResPack *GetResPack(); |
| 41 | + // 获取 ccuIns 在指定 die 上持有的资源描述符,用于查询接口 | ||
| 42 | + const CcuResDesc &GetTotalResDescs(uint8_t dieId) const; | ||
| 34 | CcuResult SaveKernel(const CcuKernelHandle kernelHandle); | 43 | CcuResult SaveKernel(const CcuKernelHandle kernelHandle); |
| 35 | const std::vector<CcuKernelHandle> &GetUntranslatedKernels(); | 44 | const std::vector<CcuKernelHandle> &GetUntranslatedKernels(); |
| 36 | 45 | ||
| @@ -40,15 +49,18 @@ public: | |||
| 40 | void AbortRegister(); | 49 | void AbortRegister(); |
| 41 | 50 | ||
| 42 | private: | 51 | private: |
| 52 | + // 从 resPack_ 取 CcuResRepository,把各 die 各资源类型的占用数量写入 totalResDescs_ | ||
| 53 | + CcuResult FillTotalResDescs(); | ||
| 54 | + | ||
| 43 | enum class RegisterState { IDLE, REGISTERING, REGISTER_ABORTED }; | 55 | enum class RegisterState { IDLE, REGISTERING, REGISTER_ABORTED }; |
| 44 | RegisterState registerState_{RegisterState::IDLE}; | 56 | RegisterState registerState_{RegisterState::IDLE}; |
| 45 | - CcuInstanceType insType_{CcuInstanceType::CCU_UNUSED}; | ||
| 46 | int32_t devLogicId_{INT32_MAX}; | 57 | int32_t devLogicId_{INT32_MAX}; |
| 47 | std::shared_ptr<hcomm::CcuDrvHandle> ccuDrvHandle_{}; | 58 | std::shared_ptr<hcomm::CcuDrvHandle> ccuDrvHandle_{}; |
| 48 | std::unique_ptr<CcuResPack> resPack_{}; | 59 | std::unique_ptr<CcuResPack> resPack_{}; |
| 49 | std::vector<CcuKernelHandle> kernelHandles_{}; | 60 | std::vector<CcuKernelHandle> kernelHandles_{}; |
| 50 | std::vector<CcuKernelHandle> untranslatedKernelHandles_{}; | 61 | std::vector<CcuKernelHandle> untranslatedKernelHandles_{}; |
| 62 | + std::array<CcuResDesc, CCU_MAX_IODIE_NUM> totalResDescs_{}; // ccuIns持有的全部资源描述符 | ||
| 51 | }; | 63 | }; |
| 52 | 64 | ||
| 53 | } // namespace hcomm | 65 | } // namespace hcomm |
| 54 | -#endif // CCU_RES_CONTAINER_H | 66 | +#endif // HCOMM_CCU_INSTANCE_H |
| @@ -55,24 +55,26 @@ CcuResult CcuInstanceMgr::Deinit() | |||
| 55 | { | 55 | { |
| 56 | std::unique_lock<std::shared_timed_mutex> lock(insMapMutex_); | 56 | std::unique_lock<std::shared_timed_mutex> lock(insMapMutex_); |
| 57 | insMap_.clear(); | 57 | insMap_.clear(); |
| 58 | + (void)resDescMgr_.Deinit(); | ||
| 58 | initializedFlag_ = false; | 59 | initializedFlag_ = false; |
| 59 | return CcuResult::CCU_SUCCESS; | 60 | return CcuResult::CCU_SUCCESS; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | -CcuResult CcuInstanceMgr::Create( | 63 | +CcuResult CcuInstanceMgr::CreateByInsType(const CcuInstanceType insType, CcuInsHandle &insHandle) |
| 63 | - CcuInstanceType insType, CcuInsHandle &insHandle) | ||
| 64 | { | 64 | { |
| 65 | std::unique_lock<std::shared_timed_mutex> lock(insMapMutex_); | 65 | std::unique_lock<std::shared_timed_mutex> lock(insMapMutex_); |
| 66 | 66 | ||
| 67 | std::unique_ptr<CcuInstance> instance{nullptr}; | 67 | std::unique_ptr<CcuInstance> instance{nullptr}; |
| 68 | EXCEPTION_CATCH( | 68 | EXCEPTION_CATCH( |
| 69 | - instance = std::make_unique<CcuInstance>(insType), | 69 | + instance = std::make_unique<CcuInstance>(), |
| 70 | - return CcuResult::CCU_E_PTR); | 70 | + return CcuResult::CCU_E_INTERNAL); |
| 71 | 71 | ||
| 72 | - CCU_CHK_RET(instance->Init()); | 72 | + CCU_CHK_RET(instance->InitByInsType(insType)); |
| 73 | 73 | ||
| 74 | instanceId_ += 1; | 74 | instanceId_ += 1; |
| 75 | - insMap_.emplace(instanceId_, std::move(instance)); | 75 | + EXCEPTION_CATCH( |
| 76 | + insMap_.emplace(instanceId_, std::move(instance)), | ||
| 77 | + return CcuResult::CCU_E_INTERNAL); | ||
| 76 | insHandle = instanceId_; | 78 | insHandle = instanceId_; |
| 77 | return CcuResult::CCU_SUCCESS; | 79 | return CcuResult::CCU_SUCCESS; |
| 78 | } | 80 | } |
| @@ -104,4 +106,80 @@ CcuResult CcuInstanceMgr::Destroy(CcuInsHandle insHandle) | |||
| 104 | return CcuResult::CCU_SUCCESS; | 106 | return CcuResult::CCU_SUCCESS; |
| 105 | } | 107 | } |
| 106 | 108 | ||
| 107 | -} // namespace hcomm | 109 | +CcuResult CcuInstanceMgr::CreateByResDescs( |
| 110 | + const CcuResDesc *descs[], uint32_t descNum, CcuInsHandle &insHandle) | ||
| 111 | +{ | ||
| 112 | + std::unique_lock<std::shared_timed_mutex> lock(insMapMutex_); | ||
| 113 | + | ||
| 114 | + std::unique_ptr<CcuInstance> instance{nullptr}; | ||
| 115 | + EXCEPTION_CATCH( | ||
| 116 | + instance = std::make_unique<CcuInstance>(), | ||
| 117 | + return CcuResult::CCU_E_INTERNAL); | ||
| 118 | + | ||
| 119 | + CCU_CHK_RET(instance->InitByResDescs(descs, descNum)); | ||
| 120 | + | ||
| 121 | + instanceId_ += 1; | ||
| 122 | + EXCEPTION_CATCH( | ||
| 123 | + insMap_.emplace(instanceId_, std::move(instance)), | ||
| 124 | + return CcuResult::CCU_E_INTERNAL); | ||
| 125 | + insHandle = instanceId_; | ||
| 126 | + return CcuResult::CCU_SUCCESS; | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | +CcuResult CcuInstanceMgr::CreateByAllRes(CcuInsHandle &insHandle) | ||
| 130 | +{ | ||
| 131 | + std::unique_lock<std::shared_timed_mutex> lock(insMapMutex_); | ||
| 132 | + | ||
| 133 | + std::unique_ptr<CcuInstance> instance{nullptr}; | ||
| 134 | + EXCEPTION_CATCH( | ||
| 135 | + instance = std::make_unique<CcuInstance>(), | ||
| 136 | + return CcuResult::CCU_E_INTERNAL); | ||
| 137 | + | ||
| 138 | + CCU_CHK_RET(instance->InitByAllRes()); | ||
| 139 | + | ||
| 140 | + instanceId_ += 1; | ||
| 141 | + EXCEPTION_CATCH( | ||
| 142 | + insMap_.emplace(instanceId_, std::move(instance)), | ||
| 143 | + return CcuResult::CCU_E_INTERNAL); | ||
| 144 | + insHandle = instanceId_; | ||
| 145 | + return CcuResult::CCU_SUCCESS; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +CcuResult CcuInstanceMgr::QueryInsResDesc(CcuInsHandle &ccuInsHandle, uint8_t dieId, HcommCcuResDescHandle &resDesc) | ||
| 149 | +{ | ||
| 150 | + std::shared_lock<std::shared_timed_mutex> lock(insMapMutex_); | ||
| 151 | + | ||
| 152 | + auto it = insMap_.find(ccuInsHandle); | ||
| 153 | + if (it == insMap_.end()) { | ||
| 154 | + HCCL_ERROR("[CcuInstanceMgr][%s] handle[%llx] is not existed.", | ||
| 155 | + __func__, ccuInsHandle); | ||
| 156 | + return CcuResult::CCU_E_NOT_FOUND; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + // 从 ccuIns 持有的 totalResDescs_ 取该 die 的资源描述符,逐项写入入参 resDesc | ||
| 160 | + const auto &totalDesc = it->second->GetTotalResDescs(dieId); | ||
| 161 | + uint32_t num = 0; | ||
| 162 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::LOOP, num)); | ||
| 163 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::LOOP, num)); | ||
| 164 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::MS, num)); | ||
| 165 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::MS, num)); | ||
| 166 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::CKE, num)); | ||
| 167 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::CKE, num)); | ||
| 168 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::XN, num)); | ||
| 169 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::XN, num)); | ||
| 170 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::GSA, num)); | ||
| 171 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::GSA, num)); | ||
| 172 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::MISSION, num)); | ||
| 173 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::MISSION, num)); | ||
| 174 | + CCU_CHK_RET(totalDesc.QueryResNum(ResType::INS, num)); | ||
| 175 | + CCU_CHK_RET(resDescMgr_.SetResNum(resDesc, ResType::INS, num)); | ||
| 176 | + | ||
| 177 | + return CcuResult::CCU_SUCCESS; | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +CcuResDescMgr &CcuInstanceMgr::GetResDescMgr() | ||
| 181 | +{ | ||
| 182 | + return resDescMgr_; | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +} // namespace hcomm | ||
| @@ -11,12 +11,13 @@ | |||
| 11 | #ifndef HCOMM_CCU_INSTANCE_MGR_H | 11 | #ifndef HCOMM_CCU_INSTANCE_MGR_H |
| 12 | #define HCOMM_CCU_INSTANCE_MGR_H | 12 | #define HCOMM_CCU_INSTANCE_MGR_H |
| 13 | 13 | ||
| 14 | +#include <memory> | ||
| 14 | #include <mutex> | 15 | #include <mutex> |
| 15 | #include <shared_mutex> | 16 | #include <shared_mutex> |
| 16 | #include <unordered_map> | 17 | #include <unordered_map> |
| 17 | 18 | ||
| 18 | -#include "ccu_types.h" | ||
| 19 | #include "ccu_instance.h" | 19 | #include "ccu_instance.h" |
| 20 | +#include "ccu_res_desc_mgr.h" | ||
| 20 | 21 | ||
| 21 | namespace hcomm { | 22 | namespace hcomm { |
| 22 | 23 | ||
| @@ -27,9 +28,17 @@ public: | |||
| 27 | CcuResult Init(); | 28 | CcuResult Init(); |
| 28 | CcuResult Deinit(); | 29 | CcuResult Deinit(); |
| 29 | 30 | ||
| 30 | - CcuResult Create(CcuInstanceType insType, CcuInsHandle &insHandle); | 31 | + // 基于实例类型创建实例 |
| 32 | + CcuResult CreateByInsType(const CcuInstanceType insType, CcuInsHandle &insHandle); | ||
| 33 | + // 基于资源描述符数组创建实例 | ||
| 34 | + CcuResult CreateByResDescs(const CcuResDesc *descs[], uint32_t descNum, CcuInsHandle &insHandle); | ||
| 35 | + // 使用当前 Device 上所有已使能 ioDie 的全部资源创建实例 | ||
| 36 | + CcuResult CreateByAllRes(CcuInsHandle &insHandle); | ||
| 37 | + // 查询实例持有的资源描述符 | ||
| 38 | + CcuResult QueryInsResDesc(CcuInsHandle &ccuInsHandle, uint8_t dieId, HcommCcuResDescHandle &resDesc); | ||
| 31 | CcuInstance *Get(CcuInsHandle insHandle) const; | 39 | CcuInstance *Get(CcuInsHandle insHandle) const; |
| 32 | CcuResult Destroy(CcuInsHandle insHandle); | 40 | CcuResult Destroy(CcuInsHandle insHandle); |
| 41 | + CcuResDescMgr &GetResDescMgr(); | ||
| 33 | 42 | ||
| 34 | private: | 43 | private: |
| 35 | explicit CcuInstanceMgr() = default; | 44 | explicit CcuInstanceMgr() = default; |
| @@ -44,7 +53,8 @@ private: | |||
| 44 | CcuInsHandle instanceId_{0}; | 53 | CcuInsHandle instanceId_{0}; |
| 45 | mutable std::shared_timed_mutex insMapMutex_; | 54 | mutable std::shared_timed_mutex insMapMutex_; |
| 46 | std::unordered_map<CcuInsHandle, std::unique_ptr<CcuInstance>> insMap_{}; | 55 | std::unordered_map<CcuInsHandle, std::unique_ptr<CcuInstance>> insMap_{}; |
| 56 | + CcuResDescMgr resDescMgr_; | ||
| 47 | }; | 57 | }; |
| 48 | }; // namespace hcomm | 58 | }; // namespace hcomm |
| 49 | 59 | ||
| 50 | -#endif // HCOMM_CCU_INSTANCE_MGR_H | 60 | +#endif // HCOMM_CCU_INSTANCE_MGR_H |
| @@ -0,0 +1,148 @@ | |||
| 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 | + | ||
| 11 | +#include "ccu_res_desc_mgr.h" | ||
| 12 | + | ||
| 13 | +#include <algorithm> | ||
| 14 | +#include <mutex> | ||
| 15 | +#include <vector> | ||
| 16 | + | ||
| 17 | +#include "ccu_dev_mgr_imp.h" | ||
| 18 | +#include "ccu_log.h" | ||
| 19 | +#include "exception_handler.h" | ||
| 20 | + | ||
| 21 | +namespace hcomm { | ||
| 22 | + | ||
| 23 | +CcuResult CcuResDescMgr::Create(uint32_t dieId, HcommCcuResDescHandle &handle) | ||
| 24 | +{ | ||
| 25 | + std::unique_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 26 | + | ||
| 27 | + std::unique_ptr<CcuResDesc> desc{nullptr}; | ||
| 28 | + EXCEPTION_CATCH( | ||
| 29 | + desc = std::make_unique<CcuResDesc>(), | ||
| 30 | + return CcuResult::CCU_E_INTERNAL); | ||
| 31 | + | ||
| 32 | + desc->dieId = dieId; | ||
| 33 | + nextHandle_ += 1; | ||
| 34 | + EXCEPTION_CATCH( | ||
| 35 | + descMap_.emplace(nextHandle_, std::move(desc)), | ||
| 36 | + return CcuResult::CCU_E_INTERNAL); | ||
| 37 | + handle = nextHandle_; | ||
| 38 | + return CcuResult::CCU_SUCCESS; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +CcuResult CcuResDescMgr::FindDesc( | ||
| 42 | + HcommCcuResDescHandle handle, const char *funcName, ConstDescIterator &it) const | ||
| 43 | +{ | ||
| 44 | + it = descMap_.find(handle); | ||
| 45 | + if (it == descMap_.cend()) { | ||
| 46 | + HCCL_ERROR("[CcuResDescMgr][%s] handle[%llx] is not existed.", funcName, handle); | ||
| 47 | + return CcuResult::CCU_E_NOT_FOUND; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + return CcuResult::CCU_SUCCESS; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +const CcuResDesc *CcuResDescMgr::Get(HcommCcuResDescHandle handle) const | ||
| 54 | +{ | ||
| 55 | + std::shared_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 56 | + auto it = descMap_.cend(); | ||
| 57 | + if (FindDesc(handle, __func__, it) != CcuResult::CCU_SUCCESS) { | ||
| 58 | + return nullptr; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + return it->second.get(); | ||
[一般][CON-04][确定] 这里返回裸指针时 ![]() ![]() | |||
| 62 | +} | ||
| 63 | + | ||
| 64 | +CcuResult CcuResDescMgr::Destroy(HcommCcuResDescHandle handle) | ||
| 65 | +{ | ||
| 66 | + std::unique_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 67 | + auto it = descMap_.cend(); | ||
| 68 | + CCU_CHK_RET(FindDesc(handle, __func__, it)); | ||
| 69 | + | ||
| 70 | + descMap_.erase(it); | ||
| 71 | + return CcuResult::CCU_SUCCESS; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +CcuResult CcuResDescMgr::SetResNum(HcommCcuResDescHandle handle, ResType resType, uint32_t resNum) | ||
| 75 | +{ | ||
| 76 | + std::unique_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 77 | + auto it = descMap_.cend(); | ||
| 78 | + CCU_CHK_RET(FindDesc(handle, __func__, it)); | ||
| 79 | + | ||
| 80 | + return it->second->SetResNum(resType, resNum); | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +CcuResult CcuResDescMgr::QueryResNum(HcommCcuResDescHandle handle, ResType resType, uint32_t &resNum) const | ||
| 84 | +{ | ||
| 85 | + std::shared_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 86 | + auto it = descMap_.cend(); | ||
| 87 | + CCU_CHK_RET(FindDesc(handle, __func__, it)); | ||
| 88 | + | ||
| 89 | + return it->second->QueryResNum(resType, resNum); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +CcuResult CcuResDescMgr::QueryDieId(HcommCcuResDescHandle handle, uint32_t &dieId) const | ||
| 93 | +{ | ||
| 94 | + std::shared_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 95 | + auto it = descMap_.cend(); | ||
| 96 | + CCU_CHK_RET(FindDesc(handle, __func__, it)); | ||
| 97 | + | ||
| 98 | + dieId = it->second->dieId; | ||
| 99 | + return CcuResult::CCU_SUCCESS; | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +CcuResult CcuResDescMgr::QueryRemainRes(HcommCcuResDescHandle handle, int32_t devLogicId) const | ||
| 103 | +{ | ||
| 104 | + std::unique_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 105 | + auto it = descMap_.cend(); | ||
| 106 | + CCU_CHK_RET(FindDesc(handle, __func__, it)); | ||
| 107 | + | ||
| 108 | + CcuResDesc &desc = *it->second; | ||
| 109 | + const uint8_t dieId = static_cast<uint8_t>(desc.dieId); | ||
| 110 | + | ||
| 111 | + // 遍历全部 ResType (LOOP..MISSION, 不含 INS) | ||
| 112 | + constexpr ResType kResTypes[] = { | ||
| 113 | + ResType::LOOP, ResType::MS, ResType::CKE, | ||
| 114 | + ResType::XN, ResType::GSA, ResType::MISSION | ||
| 115 | + }; | ||
| 116 | + | ||
| 117 | + uint32_t remainNum = 0; | ||
| 118 | + for (auto internalType : kResTypes) { | ||
| 119 | + // 查询最大连续剩余 | ||
| 120 | + if (CcuDevMgrImp::QueryRemainRes(devLogicId, dieId, internalType, remainNum) != HCCL_SUCCESS) { | ||
| 121 | + HCCL_ERROR("[CcuResDescMgr][%s] devLogicId[%d] dieId[%u] resType[%s] query failed", | ||
| 122 | + __func__, devLogicId, dieId, internalType.Describe().c_str()); | ||
| 123 | + return CcuResult::CCU_E_INTERNAL; | ||
| 124 | + } | ||
| 125 | + HCCL_INFO("[CcuResDescMgr][%s] devLogicId[%d] dieId[%u] resType[%s] remainNum[%u]", | ||
| 126 | + __func__, devLogicId, dieId, internalType.Describe().c_str(), remainNum); | ||
| 127 | + // 写入最大连续剩余 | ||
| 128 | + CCU_CHK_RET(desc.SetResNum(internalType, remainNum)); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + // 单独处理 INSTRUCTION: 从 CcuComponent 查询实际剩余量 | ||
| 132 | + uint32_t insFreeSize = CcuDevMgrImp::GetInsConsecutiveRemainSize(devLogicId, dieId); | ||
| 133 | + HCCL_INFO("[CcuResDescMgr][%s] devLogicId[%d] dieId[%u] resType[ResType::INS] remainNum[%u]", | ||
| 134 | + __func__, devLogicId, dieId, insFreeSize); | ||
| 135 | + CCU_CHK_RET(desc.SetResNum(ResType::INS, insFreeSize)); | ||
| 136 | + | ||
| 137 | + return CcuResult::CCU_SUCCESS; | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +CcuResult CcuResDescMgr::Deinit() | ||
| 141 | +{ | ||
| 142 | + std::unique_lock<std::shared_timed_mutex> lock(descMapMutex_); | ||
| 143 | + descMap_.clear(); | ||
| 144 | + nextHandle_ = 0; | ||
| 145 | + return CcuResult::CCU_SUCCESS; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +} // namespace hcomm | ||
| @@ -0,0 +1,54 @@ | |||
| 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 | + | ||
| 11 | +#ifndef HCOMM_CCU_RES_DESC_MGR_H | ||
| 12 | +#define HCOMM_CCU_RES_DESC_MGR_H | ||
| 13 | + | ||
| 14 | +#include <memory> | ||
| 15 | +#include <shared_mutex> | ||
| 16 | +#include <unordered_map> | ||
| 17 | + | ||
| 18 | +#include "ccu_res_defs.h" | ||
| 19 | +#include "ccu_res_desc.h" | ||
| 20 | + | ||
| 21 | +namespace hcomm { | ||
| 22 | + | ||
| 23 | +class CcuResDescMgr { | ||
| 24 | +public: | ||
| 25 | + CcuResDescMgr() = default; | ||
| 26 | + ~CcuResDescMgr() = default; | ||
| 27 | + CcuResDescMgr(const CcuResDescMgr &) = delete; | ||
| 28 | + CcuResDescMgr &operator=(const CcuResDescMgr &) = delete; | ||
| 29 | + | ||
| 30 | + CcuResult Create(uint32_t dieId, HcommCcuResDescHandle &handle); | ||
| 31 | + const CcuResDesc *Get(HcommCcuResDescHandle handle) const; | ||
| 32 | + CcuResult Destroy(HcommCcuResDescHandle handle); | ||
| 33 | + CcuResult SetResNum(HcommCcuResDescHandle handle, ResType resType, uint32_t resNum); | ||
| 34 | + CcuResult QueryResNum(HcommCcuResDescHandle handle, ResType resType, uint32_t &resNum) const; | ||
| 35 | + CcuResult QueryDieId(HcommCcuResDescHandle handle, uint32_t &dieId) const; | ||
| 36 | + CcuResult Deinit(); | ||
| 37 | + | ||
| 38 | + // 在锁内遍历资源类型 → 查询容量 → 收集区间 → 扫描最大连续 → 写入 desc | ||
| 39 | + CcuResult QueryRemainRes(HcommCcuResDescHandle handle, int32_t devLogicId) const; | ||
| 40 | + | ||
| 41 | +private: | ||
| 42 | + using DescMap = std::unordered_map<HcommCcuResDescHandle, std::unique_ptr<CcuResDesc>>; | ||
| 43 | + using ConstDescIterator = DescMap::const_iterator; | ||
| 44 | + | ||
| 45 | + CcuResult FindDesc(HcommCcuResDescHandle handle, const char *funcName, ConstDescIterator &it) const; | ||
| 46 | + | ||
| 47 | + mutable std::shared_timed_mutex descMapMutex_; | ||
| 48 | + HcommCcuResDescHandle nextHandle_{0}; | ||
| 49 | + DescMap descMap_{}; | ||
| 50 | +}; | ||
| 51 | + | ||
| 52 | +} // namespace hcomm | ||
| 53 | + | ||
| 54 | +#endif // HCOMM_CCU_RES_DESC_MGR_H | ||
| @@ -29,28 +29,6 @@ CcuResPack::~CcuResPack() | |||
| 29 | resHandle_ = 0; | 29 | resHandle_ = 0; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | -CcuResult CcuResPack::Init() | ||
| 33 | -{ | ||
| 34 | - devLogicId_ = HcclGetThreadDeviceId(); | ||
| 35 | - if (insType_ == CcuInstanceType::CCU_UNUSED) { | ||
| 36 | - HCCL_ERROR("[CcuResPack][%s] failed, error ccu instance type[%d].", | ||
| 37 | - __func__, static_cast<int32_t>(insType_)); | ||
| 38 | - return CcuResult::CCU_E_PARA; | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - // 根据通信域算子展开模式申请资源 | ||
| 42 | - // 如果资源不足,返回HCCL_E_UNAVAIL,表示需要回退 | ||
| 43 | - auto ret = CcuAllocResHandleByInsType(devLogicId_, insType_, resHandle_); | ||
| 44 | - if (ret == CcuResult::CCU_E_UNAVAIL) { | ||
| 45 | - HCCL_RUN_WARNING("[%s] failed but passed, resource is not enough, " | ||
| 46 | - "devLogicId[%d], ccuInsType[%d].", __func__, devLogicId_, insType_); | ||
| 47 | - return ret; | ||
| 48 | - } | ||
| 49 | - CCU_CHK_RET(ret); | ||
| 50 | - CCU_CHK_RET(Reset()); | ||
| 51 | - return CcuResult::CCU_SUCCESS; | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | CcuResult CcuResPack::Reset() | 32 | CcuResult CcuResPack::Reset() |
| 55 | { | 33 | { |
| 56 | if (!resHandle_) { | 34 | if (!resHandle_) { |
| @@ -61,6 +39,46 @@ CcuResult CcuResPack::Reset() | |||
| 61 | return CcuResult::CCU_SUCCESS; | 39 | return CcuResult::CCU_SUCCESS; |
| 62 | } | 40 | } |
| 63 | 41 | ||
| 42 | + | ||
| 43 | +CcuResult CcuResPack::InitByInsType(const CcuInstanceType insType) | ||
| 44 | +{ | ||
| 45 | + devLogicId_ = HcclGetThreadDeviceId(); | ||
| 46 | + if (insType == CcuInstanceType::CCU_UNUSED) { | ||
| 47 | + HCCL_ERROR("[CcuResPack][%s] failed, error ccu instance type[%d].", | ||
| 48 | + __func__, static_cast<int32_t>(insType)); | ||
| 49 | + return CcuResult::CCU_E_PARA; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + // 根据通信域算子展开模式申请资源 | ||
| 53 | + // 如果资源不足,返回HCCL_E_UNAVAIL,表示需要回退 | ||
| 54 | + auto ret = CcuAllocResHandleByInsType(devLogicId_, insType, resHandle_); | ||
| 55 | + if (ret == CcuResult::CCU_E_UNAVAIL) { | ||
| 56 | + HCCL_RUN_WARNING("[%s] failed but passed, resource is not enough, " | ||
| 57 | + "devLogicId[%d], ccuInsType[%d].", __func__, devLogicId_, insType); | ||
| 58 | + return ret; | ||
| 59 | + } | ||
| 60 | + CCU_CHK_RET(ret); | ||
| 61 | + CCU_CHK_RET(Reset()); | ||
| 62 | + return CcuResult::CCU_SUCCESS; | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +CcuResult CcuResPack::InitByResDescs(const CcuResDesc *descs[], uint32_t descNum) | ||
| 66 | +{ | ||
| 67 | + devLogicId_ = HcclGetThreadDeviceId(); | ||
| 68 | + | ||
| 69 | + // 基于 resDesc 驱动的资源数量申请资源 | ||
| 70 | + // 如果资源不足,返回CCU_E_UNAVAIL,表示需要回退 | ||
| 71 | + auto ret = CcuAllocResHandleByResDescs(devLogicId_, descs, descNum, resHandle_); | ||
| 72 | + if (ret == CcuResult::CCU_E_UNAVAIL) { | ||
| 73 | + HCCL_RUN_WARNING("[%s] failed but passed, resource is not enough, " | ||
| 74 | + "devLogicId[%d], descNum[%u].", __func__, devLogicId_, descNum); | ||
| 75 | + return ret; | ||
| 76 | + } | ||
| 77 | + CCU_CHK_RET(ret); | ||
| 78 | + CCU_CHK_RET(Reset()); | ||
| 79 | + return CcuResult::CCU_SUCCESS; | ||
| 80 | +} | ||
| 81 | + | ||
| 64 | CcuResRepository &CcuResPack::GetCcuResRepo() | 82 | CcuResRepository &CcuResPack::GetCcuResRepo() |
| 65 | { | 83 | { |
| 66 | return resRepo_; | 84 | return resRepo_; |
| @@ -11,16 +11,19 @@ | |||
| 11 | #define CCU_RES_PACK_H | 11 | #define CCU_RES_PACK_H |
| 12 | 12 | ||
| 13 | #include "ccu_types.h" | 13 | #include "ccu_types.h" |
| 14 | +#include "ccu_res_desc.h" | ||
| 14 | #include "ccu_device_pub.h" | 15 | #include "ccu_device_pub.h" |
| 15 | 16 | ||
| 16 | namespace hcomm { | 17 | namespace hcomm { |
| 17 | 18 | ||
| 18 | class CcuResPack{ | 19 | class CcuResPack{ |
| 19 | public: | 20 | public: |
| 20 | - explicit CcuResPack(CcuInstanceType insType) : insType_(insType) {}; | 21 | + explicit CcuResPack() {}; |
| 21 | ~CcuResPack(); | 22 | ~CcuResPack(); |
| 22 | - | 23 | + // 基于实例类型初始化 |
| 23 | - CcuResult Init(); | 24 | + CcuResult InitByInsType(const CcuInstanceType insType); |
| 25 | + // 基于资源描述符数组初始化(资源数量由 resDesc 驱动,与 Init 的 insType 路径区分) | ||
| 26 | + CcuResult InitByResDescs(const CcuResDesc *descs[], uint32_t descNum); | ||
| 24 | CcuResult Reset(); | 27 | CcuResult Reset(); |
| 25 | 28 | ||
| 26 | CcuResRepository &GetCcuResRepo(); | 29 | CcuResRepository &GetCcuResRepo(); |
| @@ -32,7 +35,6 @@ private: | |||
| 32 | CcuResPack &operator=(CcuResPack &&that) = delete; | 35 | CcuResPack &operator=(CcuResPack &&that) = delete; |
| 33 | 36 | ||
| 34 | int32_t devLogicId_{0}; | 37 | int32_t devLogicId_{0}; |
| 35 | - CcuInstanceType insType_{CcuInstanceType::CCU_UNUSED}; | ||
| 36 | CcuResHandle resHandle_{nullptr}; | 38 | CcuResHandle resHandle_{nullptr}; |
| 37 | CcuResRepository resRepo_{}; | 39 | CcuResRepository resRepo_{}; |
| 38 | }; | 40 | }; |
| @@ -112,8 +112,7 @@ static HcclResult GetDieIdByChannels(const std::unordered_set<ChannelHandle> &ch | |||
| 112 | } | 112 | } |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | - HCCL_ERROR("[CcuKernel][%s] failed, all dies are disable, devLogicId[%d].", | 115 | + HCCL_ERROR("[CcuKernel][%s] failed, all dies are disable, devLogicId[%d].", __func__, devLogicId); |
| 116 | - __func__, devLogicId); | ||
| 117 | return HcclResult::HCCL_E_INTERNAL; | 116 | return HcclResult::HCCL_E_INTERNAL; |
| 118 | } | 117 | } |
| 119 | 118 | ||
| @@ -132,6 +131,21 @@ static HcclResult GetDieIdByChannels(const std::unordered_set<ChannelHandle> &ch | |||
| 132 | return HcclResult::HCCL_SUCCESS; | 131 | return HcclResult::HCCL_SUCCESS; |
| 133 | } | 132 | } |
| 134 | 133 | ||
| 134 | +static HcclResult CheckChannelsDie( | ||
| 135 | + const std::unordered_set<ChannelHandle> &channels, const uint32_t targetDieId) | ||
| 136 | +{ | ||
| 137 | + for (const auto channel : channels) { | ||
| 138 | + uint32_t channelDieId = 0; | ||
| 139 | + CHK_RET(GetDieIdByChannel(channel, channelDieId)); | ||
| 140 | + if (channelDieId != targetDieId) { | ||
| 141 | + HCCL_ERROR("[%s] failed, channel[0x%llx] dieId[%u] differs from target dieId[%u].", | ||
| 142 | + __func__, channel, channelDieId, targetDieId); | ||
| 143 | + return HcclResult::HCCL_E_PARA; | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + return HcclResult::HCCL_SUCCESS; | ||
| 147 | +} | ||
| 148 | + | ||
| 135 | static void MoveResourcesToDie(CcuRepResource &res, uint32_t targetDieId) | 149 | static void MoveResourcesToDie(CcuRepResource &res, uint32_t targetDieId) |
| 136 | { | 150 | { |
| 137 | if (targetDieId == 0) return; // 初始资源位于die0,不用设置 | 151 | if (targetDieId == 0) return; // 初始资源位于die0,不用设置 |
| @@ -148,6 +162,7 @@ static void MoveResourcesToDie(CcuRepResource &res, uint32_t targetDieId) | |||
| 148 | moveAndSet(res.completedEvent); | 162 | moveAndSet(res.completedEvent); |
| 149 | moveAndSet(res.blockCompletedEvent); | 163 | moveAndSet(res.blockCompletedEvent); |
| 150 | moveAndSet(res.address); | 164 | moveAndSet(res.address); |
| 165 | + moveAndSet(res.blockAddress); | ||
| 151 | moveAndSet(res.continuousVariable); | 166 | moveAndSet(res.continuousVariable); |
| 152 | moveAndSet(res.variable); | 167 | moveAndSet(res.variable); |
| 153 | moveAndSet(res.localNotify); | 168 | moveAndSet(res.localNotify); |
| @@ -201,13 +216,13 @@ static HcclResult UpdateProfilingInfo( | |||
| 201 | return HcclResult::HCCL_SUCCESS; | 216 | return HcclResult::HCCL_SUCCESS; |
| 202 | } | 217 | } |
| 203 | 218 | ||
| 204 | -HcclResult CcuKernel::SelectDie() | 219 | +HcclResult CcuKernel::ApplyDieFromChannels() |
| 205 | { | 220 | { |
| 206 | uint32_t dieId{0}; | 221 | uint32_t dieId{0}; |
| 207 | CHK_RET(GetDieIdByChannels(channels_, dieId)); | 222 | CHK_RET(GetDieIdByChannels(channels_, dieId)); |
| 208 | - CHK_PRT_RET(dieId >= CCU_MAX_IODIE_NUM, | 223 | + CHK_PRT_RET( |
| 209 | - HCCL_ERROR("[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", | 224 | + dieId >= CCU_MAX_IODIE_NUM, |
| 210 | - __func__, dieId, CCU_MAX_IODIE_NUM), | 225 | + HCCL_ERROR("[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", __func__, dieId, CCU_MAX_IODIE_NUM), |
| 211 | HcclResult::HCCL_E_PARA); | 226 | HcclResult::HCCL_E_PARA); |
| 212 | SetDieId(dieId); | 227 | SetDieId(dieId); |
| 213 | MoveResourcesToDie(res_, dieId); | 228 | MoveResourcesToDie(res_, dieId); |
| @@ -216,6 +231,30 @@ HcclResult CcuKernel::SelectDie() | |||
| 216 | return HcclResult::HCCL_SUCCESS; | 231 | return HcclResult::HCCL_SUCCESS; |
| 217 | } | 232 | } |
| 218 | 233 | ||
| 234 | +HcclResult CcuKernel::ValidateAndApplyDie(const uint32_t targetDieId) | ||
| 235 | +{ | ||
| 236 | + CHK_PRT_RET(targetDieId >= CCU_MAX_IODIE_NUM, | ||
| 237 | + HCCL_ERROR("[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", | ||
| 238 | + __func__, targetDieId, CCU_MAX_IODIE_NUM), | ||
| 239 | + HcclResult::HCCL_E_PARA); | ||
| 240 | + | ||
| 241 | + const int32_t devLogicId = HcclGetThreadDeviceId(); | ||
| 242 | + bool enableFlag = false; | ||
| 243 | + CHK_RET(static_cast<HcclResult>( | ||
| 244 | + CcuGetDieEnableInfo(devLogicId, static_cast<uint8_t>(targetDieId), enableFlag))); | ||
| 245 | + CHK_PRT_RET(!enableFlag, | ||
| 246 | + HCCL_ERROR("[CcuKernel][%s] failed, target dieId[%u] is disabled, devLogicId[%d].", | ||
| 247 | + __func__, targetDieId, devLogicId), | ||
| 248 | + HcclResult::HCCL_E_PARA); | ||
| 249 | + CHK_RET(CheckChannelsDie(channels_, targetDieId)); | ||
| 250 | + | ||
| 251 | + SetDieId(targetDieId); | ||
| 252 | + MoveResourcesToDie(res_, targetDieId); | ||
| 253 | + (void)UpdateProfilingInfo(profilingInfo, targetDieId, name_); | ||
| 254 | + | ||
| 255 | + return HcclResult::HCCL_SUCCESS; | ||
| 256 | +} | ||
| 257 | + | ||
| 219 | void CcuKernel::SetInsGenerater(CcuInsGeneratorBase* insGeneratorBase) | 258 | void CcuKernel::SetInsGenerater(CcuInsGeneratorBase* insGeneratorBase) |
| 220 | { | 259 | { |
| 221 | insGenerator = insGeneratorBase; | 260 | insGenerator = insGeneratorBase; |
| @@ -325,24 +364,25 @@ CcuResReq CcuKernel::GetResourceRequest() | |||
| 325 | uint32_t dieId = GetDieId(); | 364 | uint32_t dieId = GetDieId(); |
| 326 | req.msReq[dieId] = res_.ccubufs[dieId].size(); | 365 | req.msReq[dieId] = res_.ccubufs[dieId].size(); |
| 327 | req.blockMsReq[dieId] = res_.blockCcubufs[dieId].size(); | 366 | req.blockMsReq[dieId] = res_.blockCcubufs[dieId].size(); |
| 328 | - req.ckeReq[dieId] = res_.completedEvent[dieId].size() | 367 | + req.ckeReq[dieId] = res_.completedEvent[dieId].size(); |
| 329 | - + res_.localNotify[dieId].size(); | 368 | + req.blockCkeReq[dieId] = res_.blockCompletedEvent[dieId].size() + res_.localNotify[dieId].size(); |
| 330 | - req.blockCkeReq[dieId] = res_.blockCompletedEvent[dieId].size(); | ||
| 331 | req.loopEngineReq[dieId] = res_.executor[dieId].size(); | 369 | req.loopEngineReq[dieId] = res_.executor[dieId].size(); |
| 332 | req.blockLoopEngineReq[dieId] = res_.blockExecutor[dieId].size(); | 370 | req.blockLoopEngineReq[dieId] = res_.blockExecutor[dieId].size(); |
| 333 | req.gsaReq[dieId] = res_.address[dieId].size(); | 371 | req.gsaReq[dieId] = res_.address[dieId].size(); |
| 372 | + req.blockGsaReq[dieId] = res_.blockAddress[dieId].size(); | ||
| 334 | req.xnReq[dieId] = res_.variable[dieId].size(); | 373 | req.xnReq[dieId] = res_.variable[dieId].size(); |
| 335 | - req.continuousXnReq[dieId] = res_.continuousVariable[dieId].size(); | 374 | + req.blockXnReq[dieId] = res_.continuousVariable[dieId].size(); |
| 336 | 375 | ||
| 337 | req.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; | 376 | req.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE; |
| 338 | req.missionReq.req[dieId] = 1; | 377 | req.missionReq.req[dieId] = 1; |
| 339 | 378 | ||
| 340 | auto info | 379 | auto info |
| 341 | = Hccl::StringFormat("resource request: dieId[%u], ms[%u], blockMs[%u], cke[%u], blockCke[%u], " | 380 | = Hccl::StringFormat("resource request: dieId[%u], ms[%u], blockMs[%u], cke[%u], blockCke[%u], " |
| 342 | - "loopEngine[%u], blockLoopEngine[%u], gsa[%u], xn[%u], continuous xn[%u], missionId[%u]", | 381 | + "loopEngine[%u], blockLoopEngine[%u], gsa[%u], blockGsa[%u], xn[%u], blockXn[%u], " |
| 382 | + "missionId[%u]", | ||
| 343 | dieId, req.msReq[dieId], req.blockMsReq[dieId], req.ckeReq[dieId], req.blockCkeReq[dieId], | 383 | dieId, req.msReq[dieId], req.blockMsReq[dieId], req.ckeReq[dieId], req.blockCkeReq[dieId], |
| 344 | - req.loopEngineReq[dieId], req.blockLoopEngineReq[dieId], req.gsaReq[dieId], req.xnReq[dieId], | 384 | + req.loopEngineReq[dieId], req.blockLoopEngineReq[dieId], req.gsaReq[dieId], req.blockGsaReq[dieId], |
| 345 | - req.continuousXnReq[dieId], req.missionReq.req[dieId]); | 385 | + req.xnReq[dieId], req.blockXnReq[dieId], req.missionReq.req[dieId]); |
| 346 | 386 | ||
| 347 | HCCL_INFO("%s", info.c_str()); | 387 | HCCL_INFO("%s", info.c_str()); |
| 348 | 388 | ||
| @@ -392,7 +432,7 @@ CcuResult CcuKernel::AddressAlloc(CcuAddressHandle *addrHandle) | |||
| 392 | CcuResult CcuKernel::EventAlloc(CcuEventHandle *eventHandle) | 432 | CcuResult CcuKernel::EventAlloc(CcuEventHandle *eventHandle) |
| 393 | { | 433 | { |
| 394 | PLF_CONFIG_INFO(PLF_DATA_OP, "[EventAlloc]"); | 434 | PLF_CONFIG_INFO(PLF_DATA_OP, "[EventAlloc]"); |
| 395 | - const auto &event = CreateResAssist(res_.completedEvent); | 435 | + const auto &event = CreateResAssist(res_.blockCompletedEvent); |
| 396 | CcuEventHandle handle = ccuEventMap_.size(); | 436 | CcuEventHandle handle = ccuEventMap_.size(); |
| 397 | ccuEventMap_.emplace(handle, event); | 437 | ccuEventMap_.emplace(handle, event); |
| 398 | *eventHandle = handle; | 438 | *eventHandle = handle; |
| @@ -401,7 +441,7 @@ CcuResult CcuKernel::EventAlloc(CcuEventHandle *eventHandle) | |||
| 401 | CcuResult CcuKernel::BufferAlloc(CcuBufferHandle *bufHandle) | 441 | CcuResult CcuKernel::BufferAlloc(CcuBufferHandle *bufHandle) |
| 402 | { | 442 | { |
| 403 | PLF_CONFIG_INFO(PLF_DATA_OP, "[BufferAlloc]"); | 443 | PLF_CONFIG_INFO(PLF_DATA_OP, "[BufferAlloc]"); |
| 404 | - const auto &buf = CreateResAssist(res_.ccubufs); | 444 | + const auto &buf = CreateResAssist(res_.blockCcubufs); |
| 405 | CcuBufferHandle handle = ccuBufferMap_.size(); | 445 | CcuBufferHandle handle = ccuBufferMap_.size(); |
| 406 | ccuBufferMap_.emplace(handle, buf); | 446 | ccuBufferMap_.emplace(handle, buf); |
| 407 | *bufHandle = handle; | 447 | *bufHandle = handle; |
| @@ -2222,8 +2262,8 @@ CcuResult CcuKernel::FuncCall(uint64_t handle, const CcuVariableHandle *inArgs, | |||
| 2222 | } | 2262 | } |
| 2223 | 2263 | ||
| 2224 | // 按 maxLoopNum 把 res_.blockExecutor[0] 扩容到至少 maxLoopNum 个 LoopEngine。 | 2264 | // 按 maxLoopNum 把 res_.blockExecutor[0] 扩容到至少 maxLoopNum 个 LoopEngine。 |
| 2225 | -// 与 CreateBlockResAssist 对齐:所有 LoopEngine 资源先落在 die0 池,待 | 2265 | +// 与 CreateBlockResAssist 对齐:所有 LoopEngine 资源先落在 die0 池,待实际 die 确定后 |
| 2226 | -// SelectDie 完成后再由 MoveResourcesToDie 迁移到目标 die。 | 2266 | +// 再由 MoveResourcesToDie 迁移到目标 die。 |
| 2227 | // 不同 LoopGroup 通过 local loopIdx 复用同一池低位 executorId,所以这里只 | 2267 | // 不同 LoopGroup 通过 local loopIdx 复用同一池低位 executorId,所以这里只 |
| 2228 | // "补足"而不是"累加"。 | 2268 | // "补足"而不是"累加"。 |
| 2229 | CcuResult CcuKernel::EnsureLoopEnginePool(uint32_t maxLoopNum) | 2269 | CcuResult CcuKernel::EnsureLoopEnginePool(uint32_t maxLoopNum) |
| @@ -2593,7 +2633,7 @@ CcuRep::Address CcuKernel::CreateAddress() | |||
| 2593 | // A6创建Address时,需要添加到Variable的列表中,但是仍以Address返回 | 2633 | // A6创建Address时,需要添加到Variable的列表中,但是仍以Address返回 |
| 2594 | return CcuRep::Address(CreateResAssist(res_.continuousVariable)); | 2634 | return CcuRep::Address(CreateResAssist(res_.continuousVariable)); |
| 2595 | } | 2635 | } |
| 2596 | - return CreateResAssist(res_.address); | 2636 | + return CreateResAssist(res_.blockAddress); |
| 2597 | } | 2637 | } |
| 2598 | 2638 | ||
| 2599 | CcuRep::LocalNotify CcuKernel::CreateLocalNotify() | 2639 | CcuRep::LocalNotify CcuKernel::CreateLocalNotify() |
| @@ -2603,17 +2643,17 @@ CcuRep::LocalNotify CcuKernel::CreateLocalNotify() | |||
| 2603 | 2643 | ||
| 2604 | CcuRep::CompletedEvent CcuKernel::CreateCompletedEvent() | 2644 | CcuRep::CompletedEvent CcuKernel::CreateCompletedEvent() |
| 2605 | { | 2645 | { |
| 2606 | - return CreateResAssist(res_.completedEvent); | 2646 | + return CreateResAssist(res_.blockCompletedEvent); |
| 2607 | } | 2647 | } |
| 2608 | 2648 | ||
| 2609 | CcuRep::CcuBuf CcuKernel::CreateCcuBuf() | 2649 | CcuRep::CcuBuf CcuKernel::CreateCcuBuf() |
| 2610 | { | 2650 | { |
| 2611 | - return CreateResAssist(res_.ccubufs); | 2651 | + return CreateResAssist(res_.blockCcubufs); |
| 2612 | } | 2652 | } |
| 2613 | 2653 | ||
| 2614 | CcuRep::Executor CcuKernel::CreateExecutor() | 2654 | CcuRep::Executor CcuKernel::CreateExecutor() |
| 2615 | { | 2655 | { |
| 2616 | - return CreateResAssist(res_.executor); | 2656 | + return CreateResAssist(res_.blockExecutor); |
| 2617 | } | 2657 | } |
| 2618 | 2658 | ||
| 2619 | CcuRep::LocalAddr CcuKernel::CreateLocalAddr() | 2659 | CcuRep::LocalAddr CcuKernel::CreateLocalAddr() |
| @@ -2963,4 +3003,4 @@ HcclResult CcuKernel::Add2ConstValue2VarMap(std::vector<uint64_t> &values) | |||
| 2963 | return HCCL_SUCCESS; | 3003 | return HCCL_SUCCESS; |
| 2964 | } | 3004 | } |
| 2965 | 3005 | ||
| 2966 | -}; // namespace hcomm | 3006 | +}; // namespace hcomm |
| @@ -71,7 +71,8 @@ public: | |||
| 71 | ~CcuKernel() override; | 71 | ~CcuKernel() override; |
| 72 | 72 | ||
| 73 | HcclResult SetupProfilingInfo(const char *kernelFuncName); | 73 | HcclResult SetupProfilingInfo(const char *kernelFuncName); |
| 74 | - HcclResult SelectDie(); | 74 | + HcclResult ApplyDieFromChannels(); |
| 75 | + HcclResult ValidateAndApplyDie(uint32_t targetDieId); | ||
| 75 | 76 | ||
| 76 | CcuResReq GetResourceRequest(); | 77 | CcuResReq GetResourceRequest(); |
| 77 | CcuResRepository &GetResRepository(); | 78 | CcuResRepository &GetResRepository(); |
| @@ -104,7 +105,7 @@ public: | |||
| 104 | std::vector<CcuProfilingInfo> &allCcuProfilingInfo); | 105 | std::vector<CcuProfilingInfo> &allCcuProfilingInfo); |
| 105 | 106 | ||
| 106 | const std::vector<CcuProfilingInfo> &GetAllCcuProfilingInfo() { return allCcuProfilingInfos_; }; | 107 | const std::vector<CcuProfilingInfo> &GetAllCcuProfilingInfo() { return allCcuProfilingInfos_; }; |
| 107 | - | 108 | + |
| 108 | // process const values | 109 | // process const values |
| 109 | std::unordered_map<uint64_t, CcuRep::Variable>& GetConstValue2VarMap() { return constValue2VarMap; } | 110 | std::unordered_map<uint64_t, CcuRep::Variable>& GetConstValue2VarMap() { return constValue2VarMap; } |
| 110 | HcclResult Add2ConstValue2VarMap(std::vector<uint64_t> &values); | 111 | HcclResult Add2ConstValue2VarMap(std::vector<uint64_t> &values); |
| @@ -491,4 +492,4 @@ private: | |||
| 491 | 492 | ||
| 492 | } // namespace hcomm | 493 | } // namespace hcomm |
| 493 | 494 | ||
| 494 | -#endif // HCOMM_CCU_KERNEL_H | 495 | +#endif // HCOMM_CCU_KERNEL_H |


需要写不申请instruction不