已合并
feat(ccu): align CCU handles and resource descriptors with POD ABI #182
cellur_z创建于 9月14日
feat(ccu): align CCU handles and resource descriptors with POD ABI #182
已合并
共 73 个文件变更+1232-1371
| @@ -29,6 +29,7 @@ target_include_directories(ccu_all_to_all PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "ccu_kernel.h" | 17 | #include "ccu_kernel.h" |
| 18 | #include "ccu/hcomm/ccu_launch.h" | 18 | #include "ccu/hcomm/ccu_launch.h" |
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | 20 | ||
| 22 | namespace ops_hccl_a2a { | 21 | namespace ops_hccl_a2a { |
| 23 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; | 22 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; |
| @@ -111,11 +110,9 @@ static HcclResult RegisterAllToAllKernel( | |||
| 111 | 110 | ||
| 112 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel | 111 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel |
| 113 | 112 | ||
| 114 | - CcuInsHandle ins_handle{0}; | 113 | + CcuInsHandle ins_handle{}; |
| 115 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 114 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 116 | - HcommCcuRegisterContextHandle context_{nullptr}; | 115 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 117 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 118 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 119 | if (regStartRet != CCU_SUCCESS) { | 116 | if (regStartRet != CCU_SUCCESS) { |
| 120 | return HCCL_E_INTERNAL; | 117 | return HCCL_E_INTERNAL; |
| 121 | } | 118 | } |
| @@ -29,6 +29,7 @@ target_include_directories(ccu_all_to_all_vc PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "ccu_kernel.h" | 17 | #include "ccu_kernel.h" |
| 18 | #include "ccu/hcomm/ccu_launch.h" | 18 | #include "ccu/hcomm/ccu_launch.h" |
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | 20 | ||
| 22 | namespace ops_hccl_a2avc { | 21 | namespace ops_hccl_a2avc { |
| 23 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; | 22 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; |
| @@ -111,11 +110,9 @@ static HcclResult RegisterAllToAllVCKernel( | |||
| 111 | 110 | ||
| 112 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel | 111 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel |
| 113 | 112 | ||
| 114 | - CcuInsHandle ins_handle{0}; | 113 | + CcuInsHandle ins_handle{}; |
| 115 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 114 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 116 | - HcommCcuRegisterContextHandle context_{nullptr}; | 115 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 117 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 118 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 119 | if (regStartRet != CCU_SUCCESS) { | 116 | if (regStartRet != CCU_SUCCESS) { |
| 120 | return HCCL_E_INTERNAL; | 117 | return HCCL_E_INTERNAL; |
| 121 | } | 118 | } |
| @@ -29,6 +29,7 @@ target_include_directories(ccu_all_to_allv PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "ccu_kernel.h" | 17 | #include "ccu_kernel.h" |
| 18 | #include "ccu/hcomm/ccu_launch.h" | 18 | #include "ccu/hcomm/ccu_launch.h" |
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | 20 | ||
| 22 | namespace ops_hccl_a2av { | 21 | namespace ops_hccl_a2av { |
| 23 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; | 22 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; |
| @@ -110,11 +109,9 @@ static HcclResult RegisterAllToAllVKernel( | |||
| 110 | 109 | ||
| 111 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel | 110 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel |
| 112 | 111 | ||
| 113 | - CcuInsHandle ins_handle{0}; | 112 | + CcuInsHandle ins_handle{}; |
| 114 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 113 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 115 | - HcommCcuRegisterContextHandle context_{nullptr}; | 114 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 116 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 117 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 118 | if (regStartRet != CCU_SUCCESS) { | 115 | if (regStartRet != CCU_SUCCESS) { |
| 119 | return HCCL_E_INTERNAL; | 116 | return HCCL_E_INTERNAL; |
| 120 | } | 117 | } |
| @@ -29,6 +29,7 @@ target_include_directories(ccu_allgather PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include <hccl/hccl_res.h> | 17 | #include <hccl/hccl_res.h> |
| 18 | 18 | ||
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | #include "alg_resource.h" | 20 | #include "alg_resource.h" |
| 22 | #include "ccu/hcomm/ccu_launch.h" | 21 | #include "ccu/hcomm/ccu_launch.h" |
| 23 | #include "ccu_kernel.h" | 22 | #include "ccu_kernel.h" |
| @@ -111,11 +110,9 @@ static HcclResult RegisterAllGatherKernel( | |||
| 111 | 110 | ||
| 112 | resCtxHost.ccuKernels.resize(1); | 111 | resCtxHost.ccuKernels.resize(1); |
| 113 | 112 | ||
| 114 | - CcuInsHandle ins_handle{0}; | 113 | + CcuInsHandle ins_handle{}; |
| 115 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 114 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 116 | - HcommCcuRegisterContextHandle context_{nullptr}; | 115 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 117 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 118 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 119 | if (regStartRet != CCU_SUCCESS) { | 116 | if (regStartRet != CCU_SUCCESS) { |
| 120 | return HCCL_E_INTERNAL; | 117 | return HCCL_E_INTERNAL; |
| 121 | } | 118 | } |
| @@ -28,7 +28,6 @@ | |||
| 28 | 28 | ||
| 29 | #include "ccu_kernel.h" | 29 | #include "ccu_kernel.h" |
| 30 | #include <ccu/hcomm/ccu_launch.h> | 30 | #include <ccu/hcomm/ccu_launch.h> |
| 31 | -#include "../../../common/ccu_register_context.h" | ||
| 32 | #include <ccu/hcomm/ccu_resource_api.h> | 31 | #include <ccu/hcomm/ccu_resource_api.h> |
| 33 | #include <hccl/hccl_ccu_res.h> | 32 | #include <hccl/hccl_ccu_res.h> |
| 34 | #include "../../../common/ccu_instance.h" | 33 | #include "../../../common/ccu_instance.h" |
| @@ -165,11 +164,9 @@ HcclResult RegisterCcuKernel( | |||
| 165 | kernel_arg->channelCount = static_cast<uint32_t>(channels.size()); | 164 | kernel_arg->channelCount = static_cast<uint32_t>(channels.size()); |
| 166 | 165 | ||
| 167 | resCtx.ccuKernels.resize(1); | 166 | resCtx.ccuKernels.resize(1); |
| 168 | - CcuInsHandle ins_handle{0}; | 167 | + CcuInsHandle ins_handle{}; |
| 169 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 168 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 170 | - HcommCcuRegisterContextHandle context_{nullptr}; | 169 | + RETURN_IF_HCCL_FAIL(ConvertCcuToHccl(asccomm_ccu_kernel_register_start(ins_handle))); |
| 171 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 172 | - RETURN_IF_HCCL_FAIL(ConvertCcuToHccl(asccomm_ccu_kernel_register_start(ins_handle, context_))); | ||
| 173 | 170 | ||
| 174 | ccu_kernel_handle kernelHandle = 0; | 171 | ccu_kernel_handle kernelHandle = 0; |
| 175 | const void* kernel_args[] = {kernel_arg.get()}; | 172 | const void* kernel_args[] = {kernel_arg.get()}; |
| @@ -29,7 +29,6 @@ | |||
| 29 | #include <hccl/hcomm_primitives.h> | 29 | #include <hccl/hcomm_primitives.h> |
| 30 | 30 | ||
| 31 | #include <ccu/hcomm/ccu_launch.h> | 31 | #include <ccu/hcomm/ccu_launch.h> |
| 32 | -#include "../../../common/ccu_register_context.h" | ||
| 33 | #include <ccu/hcomm/ccu_resource_api.h> | 32 | #include <ccu/hcomm/ccu_resource_api.h> |
| 34 | #include <hccl/hccl_ccu_res.h> | 33 | #include <hccl/hccl_ccu_res.h> |
| 35 | #include "../../../common/ccu_instance.h" | 34 | #include "../../../common/ccu_instance.h" |
| @@ -238,11 +237,9 @@ HcclResult RegisterCcuKernel( | |||
| 238 | kernel_arg->channelCount = static_cast<uint32_t>(channels.size()); | 237 | kernel_arg->channelCount = static_cast<uint32_t>(channels.size()); |
| 239 | 238 | ||
| 240 | resCtx.ccuKernels.resize(1); | 239 | resCtx.ccuKernels.resize(1); |
| 241 | - CcuInsHandle ins_handle{0}; | 240 | + CcuInsHandle ins_handle{}; |
| 242 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 241 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 243 | - HcommCcuRegisterContextHandle context_{nullptr}; | 242 | + RETURN_IF_HCCL_FAIL(ConvertCcuToHccl(asccomm_ccu_kernel_register_start(ins_handle))); |
| 244 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 245 | - RETURN_IF_HCCL_FAIL(ConvertCcuToHccl(asccomm_ccu_kernel_register_start(ins_handle, context_))); | ||
| 246 | 243 | ||
| 247 | ccu_kernel_handle kernelHandle = 0; | 244 | ccu_kernel_handle kernelHandle = 0; |
| 248 | const void* kernel_args[] = {kernel_arg.get()}; | 245 | const void* kernel_args[] = {kernel_arg.get()}; |
| @@ -29,6 +29,7 @@ target_include_directories(ccu_allreduce PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "ccu_kernel.h" | 17 | #include "ccu_kernel.h" |
| 18 | #include "ccu/hcomm/ccu_launch.h" | 18 | #include "ccu/hcomm/ccu_launch.h" |
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | #include <hccl/hccl_ccu_res.h> | 20 | #include <hccl/hccl_ccu_res.h> |
| 22 | 21 | ||
| 23 | namespace ops_hccl_ar { | 22 | namespace ops_hccl_ar { |
| @@ -112,11 +111,9 @@ static HcclResult RegisterAllReduceKernel( | |||
| 112 | 111 | ||
| 113 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel | 112 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel |
| 114 | 113 | ||
| 115 | - CcuInsHandle ins_handle{0}; | 114 | + CcuInsHandle ins_handle{}; |
| 116 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 115 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 117 | - HcommCcuRegisterContextHandle context_{nullptr}; | 116 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 118 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 119 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 120 | if (regStartRet != CCU_SUCCESS) { | 117 | if (regStartRet != CCU_SUCCESS) { |
| 121 | return HCCL_E_INTERNAL; | 118 | return HCCL_E_INTERNAL; |
| 122 | } | 119 | } |
| @@ -29,6 +29,7 @@ target_include_directories(ccu_broadcast PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "ccu_kernel.h" | 17 | #include "ccu_kernel.h" |
| 18 | #include "ccu/hcomm/ccu_launch.h" | 18 | #include "ccu/hcomm/ccu_launch.h" |
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | 20 | ||
| 22 | namespace ops_hccl_bcast { | 21 | namespace ops_hccl_bcast { |
| 23 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; | 22 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; |
| @@ -111,11 +110,9 @@ static HcclResult RegisterBroadcastKernel( | |||
| 111 | 110 | ||
| 112 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel | 111 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel |
| 113 | 112 | ||
| 114 | - CcuInsHandle ins_handle{0}; | 113 | + CcuInsHandle ins_handle{}; |
| 115 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 114 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 116 | - HcommCcuRegisterContextHandle context_{nullptr}; | 115 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 117 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 118 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 119 | if (regStartRet != CCU_SUCCESS) { | 116 | if (regStartRet != CCU_SUCCESS) { |
| 120 | return HCCL_E_INTERNAL; | 117 | return HCCL_E_INTERNAL; |
| 121 | } | 118 | } |
| @@ -29,6 +29,7 @@ target_include_directories(ccu_reduce_scatter PRIVATE | |||
| 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api | 29 | ${ASCEND_HOME_PATH}/asc/include/comm_api |
| 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm | 30 | ${ASCEND_HOME_PATH}/pkg_inc/asccomm |
| 31 | ${ASCEND_HOME_PATH}/include | 31 | ${ASCEND_HOME_PATH}/include |
| 32 | + ${ASCEND_HOME_PATH}/include/hcomm | ||
| 32 | ${ASCEND_HOME_PATH}/pkg_inc | 33 | ${ASCEND_HOME_PATH}/pkg_inc |
| 33 | ) | 34 | ) |
| 34 | 35 | ||
| @@ -17,7 +17,6 @@ | |||
| 17 | #include "ccu_kernel.h" | 17 | #include "ccu_kernel.h" |
| 18 | #include "ccu/hcomm/ccu_launch.h" | 18 | #include "ccu/hcomm/ccu_launch.h" |
| 19 | #include "../../../common/ccu_instance.h" | 19 | #include "../../../common/ccu_instance.h" |
| 20 | -#include "../../../common/ccu_register_context.h" | ||
| 21 | 20 | ||
| 22 | namespace ops_hccl_rs { | 21 | namespace ops_hccl_rs { |
| 23 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; | 22 | constexpr uint32_t CHANNEL_NOTIFY_NUM = 3; |
| @@ -112,11 +111,9 @@ static HcclResult RegisterReduceScatterKernel( | |||
| 112 | 111 | ||
| 113 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel | 112 | resCtxHost.ccuKernels.resize(1); // 只注册一个 kernel |
| 114 | 113 | ||
| 115 | - CcuInsHandle ins_handle{0}; | 114 | + CcuInsHandle ins_handle{}; |
| 116 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); | 115 | RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuInstance(comm, ins_handle)); |
| 117 | - HcommCcuRegisterContextHandle context_{nullptr}; | 116 | + CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle); |
| 118 | - RETURN_IF_HCCL_FAIL(asccomm_examples::QueryCcuRegisterContext(comm, context_)); | ||
| 119 | - CcuResult regStartRet = asccomm_ccu_kernel_register_start(ins_handle, context_); | ||
| 120 | if (regStartRet != CCU_SUCCESS) { | 117 | if (regStartRet != CCU_SUCCESS) { |
| 121 | return HCCL_E_INTERNAL; | 118 | return HCCL_E_INTERNAL; |
| 122 | } | 119 | } |
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | #include <hccl/hccl_rank_graph.h> | 16 | #include <hccl/hccl_rank_graph.h> |
| 17 | #include <ccu/hcomm/ccu_api_types.h> | 17 | #include <ccu/hcomm/ccu_api_types.h> |
| 18 | +#include <hcomm/hcomm_ccu_resource.h> | ||
| 18 | 19 | ||
| 19 | extern "C" HcclResult HcclCommQueryCcuIns(HcclComm comm, CcuInsHandle* insHandles, uint32_t* insNum); | 20 | extern "C" HcclResult HcclCommQueryCcuIns(HcclComm comm, CcuInsHandle* insHandles, uint32_t* insNum); |
| 20 | 21 | ||
| @@ -12,13 +12,13 @@ | |||
| 12 | #define ASCCOMM_EXAMPLES_CCU_REGISTER_CONTEXT_H | 12 | #define ASCCOMM_EXAMPLES_CCU_REGISTER_CONTEXT_H |
| 13 | 13 | ||
| 14 | #include <hccl/hccl_types.h> | 14 | #include <hccl/hccl_types.h> |
| 15 | -#include <hcomm/hcomm_ccu_res.h> | 15 | +#include <hcomm/hcomm_ccu_resource.h> |
| 16 | 16 | ||
| 17 | -extern "C" HcclResult HcclCommQueryCcuRegisterContext(HcclComm comm, HcommCcuRegisterContextHandle* context); | 17 | +extern "C" HcclResult HcclCommQueryCcuRegisterContext(HcclComm comm, HcommCcuInstanceHandle* context); |
| 18 | 18 | ||
| 19 | namespace asccomm_examples { | 19 | namespace asccomm_examples { |
| 20 | 20 | ||
| 21 | -inline HcclResult QueryCcuRegisterContext(HcclComm comm, HcommCcuRegisterContextHandle& context) | 21 | +inline HcclResult QueryCcuRegisterContext(HcclComm comm, HcommCcuInstanceHandle& context) |
| 22 | { | 22 | { |
| 23 | context = nullptr; | 23 | context = nullptr; |
| 24 | return HcclCommQueryCcuRegisterContext(comm, &context); | 24 | return HcclCommQueryCcuRegisterContext(comm, &context); |
| @@ -16,13 +16,13 @@ | |||
| 16 | // 与 hccl 内部类型解耦,符合控制面/数据面 ABI 边界约束。 | 16 | // 与 hccl 内部类型解耦,符合控制面/数据面 ABI 边界约束。 |
| 17 | #include "ccu/hcomm/ccu_api_types.h" | 17 | #include "ccu/hcomm/ccu_api_types.h" |
| 18 | #include "hcomm/hcomm_ccu_launch.h" | 18 | #include "hcomm/hcomm_ccu_launch.h" |
| 19 | -#include "hcomm/hcomm_ccu_res.h" | 19 | +#include "hcomm/hcomm_ccu_resource.h" |
| 20 | 20 | ||
| 21 | #ifdef __cplusplus | 21 | #ifdef __cplusplus |
| 22 | extern "C" { | 22 | extern "C" { |
| 23 | #endif // __cplusplus | 23 | #endif // __cplusplus |
| 24 | 24 | ||
| 25 | -extern CcuResult asccomm_ccu_kernel_register_start(CcuInsHandle ins_handle, HcommCcuRegisterContextHandle context_); | 25 | +extern CcuResult asccomm_ccu_kernel_register_start(CcuInsHandle ins_handle); |
| 26 | 26 | ||
| 27 | extern CcuResult asccomm_ccu_kernel_register( | 27 | extern CcuResult asccomm_ccu_kernel_register( |
| 28 | CcuInsHandle ins_handle, uint32_t die_id, const char* kernel_func_name, const void* kernel_func, | 28 | CcuInsHandle ins_handle, uint32_t die_id, const char* kernel_func_name, const void* kernel_func, |
| @@ -15,7 +15,7 @@ | |||
| 15 | #include <cstdint> | 15 | #include <cstdint> |
| 16 | #include <cstdio> | 16 | #include <cstdio> |
| 17 | 17 | ||
| 18 | -#include "hcomm/hcomm_ccu_common.h" | 18 | +#include "hcomm/hcomm_ccu_resource.h" |
| 19 | 19 | ||
| 20 | namespace AscendC { | 20 | namespace AscendC { |
| 21 | namespace ccu { | 21 | namespace ccu { |
| @@ -9,29 +9,44 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | /** | 11 | /** |
| 12 | - * @file hcomm_ccu_abi.h | 12 | + * @file hcomm_ccu_base.h |
| 13 | - * @brief CCU 跨 SO(hcomm ↔ asc-comm)POD 结构的统一 ABI 头。 | 13 | + * @brief CCU 跨 SO ABI 基础常量和返回码。 |
| 14 | - * | ||
| 15 | - * 所有跨动态库传递的 POD 均以 HcommCcuAbiHeaderPod 开头: | ||
| 16 | - * version 标识 ABI 版本、magicWord 标识结构类型、size 标识结构体大小, | ||
| 17 | - * 用于在读取业务字段前快速校验两端布局是否兼容,避免二进制不兼容导致的内存越界。 | ||
| 18 | */ | 14 | */ |
| 19 | -#ifndef HCOMM_CCU_ABI_H | 15 | +#ifndef HCOMM_CCU_BASE_H |
| 20 | -#define HCOMM_CCU_ABI_H | 16 | +#define HCOMM_CCU_BASE_H |
| 21 | 17 | ||
| 22 | #include <stdint.h> | 18 | #include <stdint.h> |
| 23 | 19 | ||
| 24 | -/** 所有 CCU 跨 SO POD 的统一头部(16 字节定长) */ | 20 | +#include "hcomm_res_defs.h" |
| 25 | -typedef struct { | 21 | + |
| 26 | - uint32_t version; // ABI 版本号 | 22 | +#ifdef __cplusplus |
| 27 | - uint32_t magicWord; // 结构类型魔数,用于区分不同的 POD | 23 | +extern "C" { |
| 28 | - uint32_t size; // 结构体总大小(sizeof),用于布局校验 | 24 | +#endif |
| 29 | - uint32_t reserved; // 保留字段,置 0 | ||
| 30 | -} HcommCcuAbiHeaderPod; | ||
| 31 | 25 | ||
| 32 | /** 支持的最大 DIE 数量 */ | 26 | /** 支持的最大 DIE 数量 */ |
| 33 | enum { | 27 | enum { |
| 34 | HCOMM_CCU_MAX_DIE_NUM = 2, | 28 | HCOMM_CCU_MAX_DIE_NUM = 2, |
| 35 | }; | 29 | }; |
| 36 | 30 | ||
| 37 | -#endif // HCOMM_CCU_ABI_H | 31 | +/** CCU C 接口返回码:异常不能穿过 C ABI */ |
| 32 | +typedef enum { | ||
| 33 | + CCU_SUCCESS = 0, | ||
| 34 | + CCU_E_PARA = 1, | ||
| 35 | + CCU_E_PTR = 2, | ||
| 36 | + CCU_E_INTERNAL = 4, | ||
| 37 | + CCU_E_NOT_SUPPORT = 5, | ||
| 38 | + CCU_E_NOT_FOUND = 6, | ||
| 39 | + CCU_E_UNAVAIL = 7, | ||
| 40 | + CCU_E_RUNTIME = 15, | ||
| 41 | + CCU_E_DRV_START = 4096, | ||
| 42 | + CCU_E_DRV_INIT_FAILED = 4097, | ||
| 43 | + CCU_E_DRV_BUSY = 4098, | ||
| 44 | + CCU_E_DRV_END = 4224, | ||
| 45 | + CCU_E_RESERVED = 9216 | ||
| 46 | +} CcuResult; | ||
| 47 | + | ||
| 48 | +#ifdef __cplusplus | ||
| 49 | +} | ||
| 50 | +#endif | ||
| 51 | + | ||
| 52 | +#endif // HCOMM_CCU_BASE_H | ||
| @@ -1,83 +0,0 @@ | |||
| 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_CHANNEL_H | ||
| 12 | -#define HCOMM_CCU_CHANNEL_H | ||
| 13 | - | ||
| 14 | -#include <stddef.h> | ||
| 15 | -#include <stdint.h> | ||
| 16 | - | ||
| 17 | -#include "hcomm/hcomm_ccu_abi.h" | ||
| 18 | - | ||
| 19 | -// 旧版两阶段查询使用的魔数与版本(保留以兼容既有调用方) | ||
| 20 | -static const uint32_t HCOMM_CCU_CHANNEL_MAGIC_WORD = 0x0fcf0f0fU; | ||
| 21 | -static const uint32_t HCOMM_CCU_CHANNEL_VERSION = 3U; | ||
| 22 | - | ||
| 23 | -#ifndef CHANNEL_HANDLE_DEFINED | ||
| 24 | -#define CHANNEL_HANDLE_DEFINED | ||
| 25 | -// 通道句柄:不透明唯一标识,跨 SO 以整型值传递 | ||
| 26 | -typedef uint64_t ChannelHandle; | ||
| 27 | -#endif | ||
| 28 | - | ||
| 29 | -#ifdef __cplusplus | ||
| 30 | -#include <type_traits> | ||
| 31 | -extern "C" { | ||
| 32 | -#endif | ||
| 33 | - | ||
| 34 | -enum { | ||
| 35 | - HCOMM_CCU_CHANNEL_ABI_VERSION = 3, // 当前 POD ABI 版本 | ||
| 36 | - HCOMM_CCU_CHANNEL_POD_MAGIC_WORD = 0x43435543U, // "CCUC",标识 Channel POD 类型 | ||
| 37 | - HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY = 4, // 每个 channel 固定持有的 XN/CKE 资源槽数量 | ||
| 38 | -}; | ||
| 39 | - | ||
| 40 | -/** | ||
| 41 | - * @brief CCU Channel 单次查询快照 POD(channel pop 优化后的定长结构)。 | ||
| 42 | - * | ||
| 43 | - * 相比旧 ChannelEntity 的两阶段查询(先查数量再传缓冲区),本 POD 把 | ||
| 44 | - * channel 的全部资源信息压缩为定长字段:本地/远端 XN、CKE id 各固定 4 槽, | ||
| 45 | - * 外加远端 CCU buffer 的基址/大小/token。调用方无需准备变长缓冲区, | ||
| 46 | - * hcomm 在持锁期间一次性填满快照,之后数据面只读该 POD。 | ||
| 47 | - */ | ||
| 48 | -typedef struct { | ||
| 49 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | ||
| 50 | - | ||
| 51 | - int32_t deviceLogicId; // 所在设备逻辑 id | ||
| 52 | - uint32_t ccuVersion; // CCU 版本(V1/V2) | ||
| 53 | - uint32_t dieId; // die id | ||
| 54 | - uint32_t channelId; // channel id(DFX 记录用) | ||
| 55 | - | ||
| 56 | - uint32_t localXnIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 本端 XN id 槽 | ||
| 57 | - uint32_t remoteXnIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 远端 XN id 槽 | ||
| 58 | - uint32_t localCkeIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 本端 CKE id 槽 | ||
| 59 | - uint32_t remoteCkeIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 远端 CKE id 槽 | ||
| 60 | - | ||
| 61 | - uint64_t rmtCcuBufAddr; // 远端 CCU 资源 buffer 基址 | ||
| 62 | - uint32_t rmtCcuBufSize; // 远端 CCU 资源 buffer 大小 | ||
| 63 | - uint32_t rmtCcuBufTokenId; // 远端 CCU buffer 保护 token id | ||
| 64 | - uint32_t rmtCcuBufTokenValue; // 远端 CCU buffer 保护 token value | ||
| 65 | - uint32_t reserved[3]; // 预留扩展空间,当前必须清零 | ||
| 66 | -} HcommCcuChannelPod; | ||
| 67 | - | ||
| 68 | -#ifdef __cplusplus | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | -static_assert(std::is_standard_layout<HcommCcuChannelPod>::value, "HcommCcuChannelPod must be standard-layout"); | ||
| 72 | -static_assert(std::is_trivially_copyable<HcommCcuChannelPod>::value, "HcommCcuChannelPod must be trivially copyable"); | ||
| 73 | -static_assert(sizeof(HcommCcuChannelPod) == 128, "HcommCcuChannelPod ABI size changed"); | ||
| 74 | -static_assert(offsetof(HcommCcuChannelPod, header) == 0, "HcommCcuChannelPod.header ABI offset changed"); | ||
| 75 | -static_assert(offsetof(HcommCcuChannelPod, localXnIds) == 32, "HcommCcuChannelPod.localXnIds ABI offset changed"); | ||
| 76 | -static_assert(offsetof(HcommCcuChannelPod, remoteXnIds) == 48, "HcommCcuChannelPod.remoteXnIds ABI offset changed"); | ||
| 77 | -static_assert(offsetof(HcommCcuChannelPod, localCkeIds) == 64, "HcommCcuChannelPod.localCkeIds ABI offset changed"); | ||
| 78 | -static_assert(offsetof(HcommCcuChannelPod, remoteCkeIds) == 80, "HcommCcuChannelPod.remoteCkeIds ABI offset changed"); | ||
| 79 | -static_assert(offsetof(HcommCcuChannelPod, rmtCcuBufAddr) == 96, "HcommCcuChannelPod.rmtCcuBufAddr ABI offset changed"); | ||
| 80 | -static_assert(offsetof(HcommCcuChannelPod, reserved) == 116, "HcommCcuChannelPod.reserved ABI offset changed"); | ||
| 81 | -#endif | ||
| 82 | - | ||
| 83 | -#endif // HCOMM_CCU_CHANNEL_H | ||
| @@ -1,54 +0,0 @@ | |||
| 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 | -/** | ||
| 12 | - * @file hcomm_ccu_common.h | ||
| 13 | - * @brief CCU 数据面(asc-comm)与控制面(hcomm)共用的基础错误码与句柄类型。 | ||
| 14 | - * | ||
| 15 | - * 这些类型原定义于 hcomm 数据面侧(ccu_res.h),数据面迁移后统一由 hcomm 包内头提供, | ||
| 16 | - * asc-comm 通过 include 路径引用,保证两仓对同一组 CcuResult 枚举值编译一致。 | ||
| 17 | - */ | ||
| 18 | -#ifndef HCOMM_CCU_COMMON_H | ||
| 19 | -#define HCOMM_CCU_COMMON_H | ||
| 20 | - | ||
| 21 | -#include <stdint.h> | ||
| 22 | - | ||
| 23 | -#ifdef __cplusplus | ||
| 24 | -extern "C" { | ||
| 25 | -#endif | ||
| 26 | - | ||
| 27 | -/** CCU C 接口返回码:hcomm C 适配层返回的错误码必须与 asc-comm 解释一致,异常不能穿过 C ABI */ | ||
| 28 | -typedef enum { | ||
| 29 | - CCU_SUCCESS = 0, | ||
| 30 | - CCU_E_PARA = 1, | ||
| 31 | - CCU_E_PTR = 2, | ||
| 32 | - CCU_E_INTERNAL = 4, | ||
| 33 | - CCU_E_NOT_SUPPORT = 5, | ||
| 34 | - CCU_E_NOT_FOUND = 6, | ||
| 35 | - CCU_E_UNAVAIL = 7, | ||
| 36 | - CCU_E_RUNTIME = 15, | ||
| 37 | - CCU_E_DRV_START = 4096, // 驱动错误起始 | ||
| 38 | - CCU_E_DRV_INIT_FAILED = 4097, // 驱动初始化失败 | ||
| 39 | - CCU_E_DRV_BUSY = 4098, // 驱动忙(可回退场景) | ||
| 40 | - CCU_E_DRV_END = 4224, // 驱动错误结束 | ||
| 41 | - CCU_E_RESERVED = 9216 | ||
| 42 | -} CcuResult; | ||
| 43 | - | ||
| 44 | -/** CCU Instance 类型:注册上下文申请的实例类型;hcomm 创建 RegisterContext 时校验,并据此分配资源句柄 */ | ||
| 45 | -typedef enum { CCU_DEFAULT = 0, CCU_SCHED = 1, CCU_MS = 2, CCU_UNUSED = 254, CCU_RESERVED = 255 } CcuInstanceType; | ||
| 46 | - | ||
| 47 | -/** CCU Instance 句柄:64 位不透明注册上下文句柄;hcomm 负责编码、校验、销毁,asc-comm 只能按值保存和回传 */ | ||
| 48 | -typedef uint64_t CcuInsHandle; | ||
| 49 | - | ||
| 50 | -#ifdef __cplusplus | ||
| 51 | -} | ||
| 52 | -#endif | ||
| 53 | - | ||
| 54 | -#endif // HCOMM_CCU_COMMON_H | ||
| @@ -1,69 +0,0 @@ | |||
| 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 | -/** | ||
| 12 | - * @file hcomm_ccu_control.h | ||
| 13 | - * @brief CCU 控制面函数表 POD(供 asc-comm 数据面通过注入方式调用 hcomm 控制面查询)。 | ||
| 14 | - * | ||
| 15 | - * 数据面不直接链接 hcomm 内部对象,而是通过 RegisterContext 中的函数指针表 | ||
| 16 | - * 完成 channel 快照查询、指令下发、mission/loop 上下文查询与资源值查询, | ||
| 17 | - * 实现"数据面可访问控制面资源"且"两仓 ABI 稳定"的解耦目标。 | ||
| 18 | - */ | ||
| 19 | -#ifndef HCOMM_CCU_CONTROL_H | ||
| 20 | -#define HCOMM_CCU_CONTROL_H | ||
| 21 | - | ||
| 22 | -#include <stddef.h> | ||
| 23 | -#include <stdint.h> | ||
| 24 | - | ||
| 25 | -#include "hcomm/hcomm_ccu_abi.h" | ||
| 26 | -#include "hcomm/hcomm_ccu_channel.h" | ||
| 27 | -#include "hcomm/hcomm_ccu_dfx.h" | ||
| 28 | -#include "hcomm/hcomm_ccu_instruction.h" | ||
| 29 | - | ||
| 30 | -#ifdef __cplusplus | ||
| 31 | -#include <type_traits> | ||
| 32 | -extern "C" { | ||
| 33 | -#endif | ||
| 34 | - | ||
| 35 | -enum { | ||
| 36 | - HCOMM_CCU_CONTROL_ABI_VERSION = 2, // 控制面函数表 POD ABI 版本 | ||
| 37 | - HCOMM_CCU_CONTROL_OPS_MAGIC_WORD = 0x434F5053U, // "COPS",函数表 POD 魔数 | ||
| 38 | -}; | ||
| 39 | - | ||
| 40 | -// 一次查询 Channel 的 POD 快照(hcomm 实现,asc-comm 调用方提供输出指针) | ||
| 41 | -typedef int32_t (*HcommCcuChannelQueryFn)(ChannelHandle channel, HcommCcuChannelPod* channelPod); | ||
| 42 | -// 将已位于设备内存的微码指令下发至 CCU(hcomm 内部完成报文组装与驱动交互) | ||
| 43 | -typedef int32_t (*HcommCcuInstructionLoadFn)(const HcommCcuInstructionLoadPod* request); | ||
| 44 | - | ||
| 45 | -/** 控制面函数表:所有函数指针在 RegisterContextCreate 时由 hcomm 填充,数据面只读调用 */ | ||
| 46 | -typedef struct { | ||
| 47 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | ||
| 48 | - HcommCcuChannelQueryFn channelQuery; // 查询 channel 的 XN/CKE/远端 buffer 快照 | ||
| 49 | - HcommCcuInstructionLoadFn loadInstruction; // 下发微码指令 | ||
| 50 | - HcommCcuMissionContextQueryFn missionContextQuery; // 查询 mission 上下文(当前/起止指令) | ||
| 51 | - HcommCcuLoopContextQueryFn loopContextQuery; // 查询 loop 上下文(当前计数/地址步长) | ||
| 52 | - HcommCcuResourceQueryFn ckeQuery; // 按 id 查询 CKE(信号量)资源值 | ||
| 53 | - HcommCcuResourceQueryFn xnQuery; // 按 id 查询 XN(变量)资源值 | ||
| 54 | - HcommCcuResourceQueryFn gsaQuery; // 按 id 查询 GSA(通用存储)资源值 | ||
| 55 | - uint64_t reserved; // 预留函数表扩展位,当前必须为 0 | ||
| 56 | -} HcommCcuControlOpsPod; | ||
| 57 | - | ||
| 58 | -#ifdef __cplusplus | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | -static_assert(std::is_standard_layout<HcommCcuControlOpsPod>::value, "HcommCcuControlOpsPod must be standard-layout"); | ||
| 62 | -static_assert( | ||
| 63 | - std::is_trivially_copyable<HcommCcuControlOpsPod>::value, "HcommCcuControlOpsPod must be trivially copyable"); | ||
| 64 | -static_assert(sizeof(HcommCcuControlOpsPod) == 80, "HcommCcuControlOpsPod ABI size changed"); | ||
| 65 | -static_assert( | ||
| 66 | - offsetof(HcommCcuControlOpsPod, channelQuery) == 16, "HcommCcuControlOpsPod.channelQuery ABI offset changed"); | ||
| 67 | -#endif | ||
| 68 | - | ||
| 69 | -#endif // HCOMM_CCU_CONTROL_H | ||
| @@ -15,30 +15,28 @@ | |||
| 15 | * 任务异常定位调用链: | 15 | * 任务异常定位调用链: |
| 16 | * hcomm 检测到 CCU 任务异常 | 16 | * hcomm 检测到 CCU 任务异常 |
| 17 | * -> 从 TaskParam 取得 asc-comm 注入的 diagnose 回调(见 hcomm_ccu_launch.h) | 17 | * -> 从 TaskParam 取得 asc-comm 注入的 diagnose 回调(见 hcomm_ccu_launch.h) |
| 18 | - * -> hcomm 构造 HcommCcuDfxRequestPod(指定设备/die/逻辑与执行 mission/kernel) | 18 | + * -> hcomm 构造 HcommCcuDfxRequest(指定设备/die/逻辑与执行 mission/kernel) |
| 19 | * -> 调用 HcommCcuDiagnoseFn,asc-comm 查询 mission/loop/CKE/XN/GSA 和 Channel 现场 | 19 | * -> 调用 HcommCcuDiagnoseFn,asc-comm 查询 mission/loop/CKE/XN/GSA 和 Channel 现场 |
| 20 | - * -> asc-comm 逐条构造 HcommCcuDfxRecordPod,经 HcommCcuDfxEmitFn 同步回调返回 hcomm | 20 | + * -> asc-comm 逐条构造 HcommCcuDfxRecord,经 HcommCcuDfxEmitFn 同步回调返回 hcomm |
| 21 | * -> hcomm 在回调内按值复制,格式化、打印并补充 Channel/Rank/Jetty 信息 | 21 | * -> hcomm 在回调内按值复制,格式化、打印并补充 Channel/Rank/Jetty 信息 |
| 22 | * | 22 | * |
| 23 | * 诊断过程中 asc-comm 还会调用 hcomm 注入的 mission/loop/资源查询函数 | 23 | * 诊断过程中 asc-comm 还会调用 hcomm 注入的 mission/loop/资源查询函数 |
| 24 | - * (见 hcomm_ccu_control.h 的 missionContextQuery/loopContextQuery/ckeQuery/xnQuery/gsaQuery) | 24 | + * (见 hcomm_ccu_resource.h 中 ascCustom 槽位的 missionContextQuery/loopContextQuery/ckeQuery/xnQuery/gsaQuery) |
| 25 | * 补充硬件现场。 | 25 | * 补充硬件现场。 |
| 26 | */ | 26 | */ |
| 27 | + | ||
| 27 | #ifndef HCOMM_CCU_DFX_H | 28 | #ifndef HCOMM_CCU_DFX_H |
| 28 | #define HCOMM_CCU_DFX_H | 29 | #define HCOMM_CCU_DFX_H |
| 29 | 30 | ||
| 30 | -#include <stddef.h> | ||
| 31 | #include <stdint.h> | 31 | #include <stdint.h> |
| 32 | - | 32 | +#include "hcomm_res_defs.h" |
| 33 | -#include "hcomm/hcomm_ccu_channel.h" | ||
| 34 | 33 | ||
| 35 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
| 36 | -#include <type_traits> | ||
| 37 | extern "C" { | 35 | extern "C" { |
| 38 | #endif | 36 | #endif |
| 39 | 37 | ||
| 40 | enum { | 38 | enum { |
| 41 | - HCOMM_CCU_DFX_ABI_VERSION = 1, // DFX POD ABI 版本;布局变化时必须与 asc-comm 同步升级 | 39 | + HCOMM_CCU_DFX_ABI_VERSION = 1, // DFX ABI 版本;布局变化时必须与 asc-comm 同步升级 |
| 42 | HCOMM_CCU_DFX_CHANNEL_CAPACITY = 16, // 单条记录最多关联的 channel 数 | 40 | HCOMM_CCU_DFX_CHANNEL_CAPACITY = 16, // 单条记录最多关联的 channel 数 |
| 43 | HCOMM_CCU_DFX_BUFFER_CAPACITY = 8, // BUFFER_REDUCE 最多关联的 buffer 数 | 41 | HCOMM_CCU_DFX_BUFFER_CAPACITY = 8, // BUFFER_REDUCE 最多关联的 buffer 数 |
| 44 | HCOMM_CCU_DFX_MISSION_MESSAGE_CAPACITY = 64, // mission 错误信息缓冲长度 | 42 | HCOMM_CCU_DFX_MISSION_MESSAGE_CAPACITY = 64, // mission 错误信息缓冲长度 |
| @@ -56,7 +54,7 @@ typedef enum { | |||
| 56 | HCOMM_CCU_DFX_RECORD_LOOP_GROUP = 7, // 循环组执行现场记录(msg.loopGroup) | 54 | HCOMM_CCU_DFX_RECORD_LOOP_GROUP = 7, // 循环组执行现场记录(msg.loopGroup) |
| 57 | } HcommCcuDfxRecordType; | 55 | } HcommCcuDfxRecordType; |
| 58 | 56 | ||
| 59 | -/** REP 类型的稳定数值(随 HcommCcuDfxRecordPod.repType 透传);属于跨 SO ABI 的一部分,不可随意改动 */ | 57 | +/** REP 类型的稳定数值(随 HcommCcuDfxRecord.repType 透传);属于跨 SO ABI 的一部分,不可随意改动 */ |
| 60 | typedef enum { | 58 | typedef enum { |
| 61 | HCOMM_CCU_REP_LOOP = 28, | 59 | HCOMM_CCU_REP_LOOP = 28, |
| 62 | HCOMM_CCU_REP_LOOP_GROUP = 29, | 60 | HCOMM_CCU_REP_LOOP_GROUP = 29, |
| @@ -88,7 +86,7 @@ typedef struct { | |||
| 88 | uint16_t missionStatus; // mission 状态和子状态组成的 16 位异常状态 | 86 | uint16_t missionStatus; // mission 状态和子状态组成的 16 位异常状态 |
| 89 | uint16_t reserved0; // 预留字段,当前必须为 0 | 87 | uint16_t reserved0; // 预留字段,当前必须为 0 |
| 90 | uint32_t reserved1; // 预留字段,当前必须为 0 | 88 | uint32_t reserved1; // 预留字段,当前必须为 0 |
| 91 | -} HcommCcuDfxRequestPod; | 89 | +} HcommCcuDfxRequest; |
| 92 | 90 | ||
| 93 | /** 等待信号类记录:signal 的 id/掩码/当前值与关联 channel */ | 91 | /** 等待信号类记录:signal 的 id/掩码/当前值与关联 channel */ |
| 94 | typedef struct { | 92 | typedef struct { |
| @@ -99,7 +97,7 @@ typedef struct { | |||
| 99 | uint64_t paramValue; // REM_POST_VAR:参数当前值(其他类型为 0) | 97 | uint64_t paramValue; // REM_POST_VAR:参数当前值(其他类型为 0) |
| 100 | uint16_t channelId[HCOMM_CCU_DFX_CHANNEL_CAPACITY]; // 关联 Channel ID;未使用槽填 UINT16_MAX | 98 | uint16_t channelId[HCOMM_CCU_DFX_CHANNEL_CAPACITY]; // 关联 Channel ID;未使用槽填 UINT16_MAX |
| 101 | ChannelHandle channelHandle[HCOMM_CCU_DFX_CHANNEL_CAPACITY]; // 与 channelId[] 同下标对应的 Channel Handle | 99 | ChannelHandle channelHandle[HCOMM_CCU_DFX_CHANNEL_CAPACITY]; // 与 channelId[] 同下标对应的 Channel Handle |
| 102 | -} HcommCcuDfxWaitSignalPod; | 100 | +} HcommCcuDfxWaitSignal; |
| 103 | 101 | ||
| 104 | /** 内存搬运类记录:本/远端地址、token、长度与信号 */ | 102 | /** 内存搬运类记录:本/远端地址、token、长度与信号 */ |
| 105 | typedef struct { | 103 | typedef struct { |
| @@ -115,7 +113,7 @@ typedef struct { | |||
| 115 | uint16_t opType; // 搬运中附带的操作类型编码 | 113 | uint16_t opType; // 搬运中附带的操作类型编码 |
| 116 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 | 114 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 |
| 117 | ChannelHandle channelHandle; // hcomm 用于补充远端 Rank 和 Channel 现场的不透明 Handle | 115 | ChannelHandle channelHandle; // hcomm 用于补充远端 Rank 和 Channel 现场的不透明 Handle |
| 118 | -} HcommCcuDfxTransferPod; | 116 | +} HcommCcuDfxTransfer; |
| 119 | 117 | ||
| 120 | /** Buffer 搬运类记录 */ | 118 | /** Buffer 搬运类记录 */ |
| 121 | typedef struct { | 119 | typedef struct { |
| @@ -127,7 +125,7 @@ typedef struct { | |||
| 127 | uint64_t token; // 该设备内存地址对应的访问 Token | 125 | uint64_t token; // 该设备内存地址对应的访问 Token |
| 128 | uint64_t len; // Buffer 搬运长度 | 126 | uint64_t len; // Buffer 搬运长度 |
| 129 | ChannelHandle channelHandle; // 远端 Buffer 操作对应的 Channel Handle | 127 | ChannelHandle channelHandle; // 远端 Buffer 操作对应的 Channel Handle |
| 130 | -} HcommCcuDfxBufferTransferPod; | 128 | +} HcommCcuDfxBufferTransfer; |
| 131 | 129 | ||
| 132 | /** Buffer 归约类记录 */ | 130 | /** Buffer 归约类记录 */ |
| 133 | typedef struct { | 131 | typedef struct { |
| @@ -139,7 +137,7 @@ typedef struct { | |||
| 139 | uint16_t signalId; // 归约关联的 CKE 信号 ID | 137 | uint16_t signalId; // 归约关联的 CKE 信号 ID |
| 140 | uint16_t signalMask; // 归约关联的信号掩码 | 138 | uint16_t signalMask; // 归约关联的信号掩码 |
| 141 | uint16_t xnIdLength; // 保存归约长度的 XN 资源 ID,不是长度值本身 | 139 | uint16_t xnIdLength; // 保存归约长度的 XN 资源 ID,不是长度值本身 |
| 142 | -} HcommCcuDfxBufferReducePod; | 140 | +} HcommCcuDfxBufferReduce; |
| 143 | 141 | ||
| 144 | /** 循环执行现场记录 */ | 142 | /** 循环执行现场记录 */ |
| 145 | typedef struct { | 143 | typedef struct { |
| @@ -150,7 +148,7 @@ typedef struct { | |||
| 150 | uint16_t loopCurrentCnt; // 从硬件上下文查询到的当前执行次数 | 148 | uint16_t loopCurrentCnt; // 从硬件上下文查询到的当前执行次数 |
| 151 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 | 149 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 |
| 152 | uint32_t addrStride; // 每轮 loop 使用的地址步长 | 150 | uint32_t addrStride; // 每轮 loop 使用的地址步长 |
| 153 | -} HcommCcuDfxLoopPod; | 151 | +} HcommCcuDfxLoop; |
| 154 | 152 | ||
| 155 | /** 循环组执行现场记录 */ | 153 | /** 循环组执行现场记录 */ |
| 156 | typedef struct { | 154 | typedef struct { |
| @@ -158,7 +156,7 @@ typedef struct { | |||
| 158 | uint16_t loopInsCnt; // Group 内包含的 loop 指令数量 | 156 | uint16_t loopInsCnt; // Group 内包含的 loop 指令数量 |
| 159 | uint16_t expandOffset; // 硬件展开参数中的起始偏移 | 157 | uint16_t expandOffset; // 硬件展开参数中的起始偏移 |
| 160 | uint16_t expandCount; // 硬件展开次数 | 158 | uint16_t expandCount; // 硬件展开次数 |
| 161 | -} HcommCcuDfxLoopGroupPod; | 159 | +} HcommCcuDfxLoopGroup; |
| 162 | 160 | ||
| 163 | /** 诊断记录:按 type 区分 msg 联合体中的具体子结构(DFX 回调实际传输的外层记录) */ | 161 | /** 诊断记录:按 type 区分 msg 联合体中的具体子结构(DFX 回调实际传输的外层记录) */ |
| 164 | typedef struct { | 162 | typedef struct { |
| @@ -172,21 +170,21 @@ typedef struct { | |||
| 172 | struct { | 170 | struct { |
| 173 | char missionError[HCOMM_CCU_DFX_MISSION_MESSAGE_CAPACITY]; // mission 错误文本,仅 MISSION 类型有效 | 171 | char missionError[HCOMM_CCU_DFX_MISSION_MESSAGE_CAPACITY]; // mission 错误文本,仅 MISSION 类型有效 |
| 174 | } mission; | 172 | } mission; |
| 175 | - HcommCcuDfxWaitSignalPod waitSignal; // 仅 WAIT_SIGNAL 类型有效 | 173 | + HcommCcuDfxWaitSignal waitSignal; // 仅 WAIT_SIGNAL 类型有效 |
| 176 | - HcommCcuDfxTransferPod transMem; // 仅 TRANSFER 类型有效 | 174 | + HcommCcuDfxTransfer transMem; // 仅 TRANSFER 类型有效 |
| 177 | - HcommCcuDfxBufferTransferPod bufTransMem; // 仅 BUFFER_TRANSFER 类型有效 | 175 | + HcommCcuDfxBufferTransfer bufTransMem; // 仅 BUFFER_TRANSFER 类型有效 |
| 178 | - HcommCcuDfxBufferReducePod bufferReduce; // 仅 BUFFER_REDUCE 类型有效 | 176 | + HcommCcuDfxBufferReduce bufferReduce; // 仅 BUFFER_REDUCE 类型有效 |
| 179 | - HcommCcuDfxLoopPod loop; // 仅 LOOP 类型有效 | 177 | + HcommCcuDfxLoop loop; // 仅 LOOP 类型有效 |
| 180 | - HcommCcuDfxLoopGroupPod loopGroup; // 仅 LOOP_GROUP 类型有效 | 178 | + HcommCcuDfxLoopGroup loopGroup; // 仅 LOOP_GROUP 类型有效 |
| 181 | } msg; | 179 | } msg; |
| 182 | -} HcommCcuDfxRecordPod; | 180 | +} HcommCcuDfxRecord; |
| 183 | 181 | ||
| 184 | // 记录回调:asc-comm 诊断时逐条同步输出;hcomm 传入 context 原样回传。 | 182 | // 记录回调:asc-comm 诊断时逐条同步输出;hcomm 传入 context 原样回传。 |
| 185 | // record 指针仅在本次调用期间有效,hcomm 必须立即按值复制,不能保存指针。 | 183 | // record 指针仅在本次调用期间有效,hcomm 必须立即按值复制,不能保存指针。 |
| 186 | -typedef int32_t (*HcommCcuDfxEmitFn)(void* context, const HcommCcuDfxRecordPod* record); | 184 | +typedef int32_t (*HcommCcuDfxEmitFn)(void* context, const HcommCcuDfxRecord* record); |
| 187 | // 诊断入口:hcomm 任务异常时调用(由 asc-comm 提供并经 HcommCcuTaskProfilePod.diagnose 注入)。 | 185 | // 诊断入口:hcomm 任务异常时调用(由 asc-comm 提供并经 HcommCcuTaskProfilePod.diagnose 注入)。 |
| 188 | // 给定请求定位执行现场,并逐条调用 emit 回调输出全部相关记录。 | 186 | // 给定请求定位执行现场,并逐条调用 emit 回调输出全部相关记录。 |
| 189 | -typedef int32_t (*HcommCcuDiagnoseFn)(const HcommCcuDfxRequestPod* request, HcommCcuDfxEmitFn emit, void* context); | 187 | +typedef int32_t (*HcommCcuDiagnoseFn)(const HcommCcuDfxRequest* request, HcommCcuDfxEmitFn emit, void* context); |
| 190 | 188 | ||
| 191 | /** mission 执行上下文(指令展开现场);由 hcomm 查询驱动后按 CCU 版本解析填充 */ | 189 | /** mission 执行上下文(指令展开现场);由 hcomm 查询驱动后按 CCU 版本解析填充 */ |
| 192 | typedef struct { | 190 | typedef struct { |
| @@ -194,37 +192,25 @@ typedef struct { | |||
| 194 | uint16_t endInstructionId; // mission 结束指令 ID | 192 | uint16_t endInstructionId; // mission 结束指令 ID |
| 195 | uint16_t startInstructionId; // mission 起始指令 ID | 193 | uint16_t startInstructionId; // mission 起始指令 ID |
| 196 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 | 194 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 |
| 197 | -} HcommCcuMissionContextPod; | 195 | +} HcommCcuMissionContext; |
| 198 | 196 | ||
| 199 | /** loop 执行上下文;由 hcomm 查询驱动后按 CCU 版本解析填充 */ | 197 | /** loop 执行上下文;由 hcomm 查询驱动后按 CCU 版本解析填充 */ |
| 200 | typedef struct { | 198 | typedef struct { |
| 201 | uint16_t currentCount; // loop 当前已执行次数 | 199 | uint16_t currentCount; // loop 当前已执行次数 |
| 202 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 | 200 | uint16_t reserved; // 对齐和扩展字段,当前必须为 0 |
| 203 | uint32_t addressStride; // loop 硬件上下文中的地址步长 | 201 | uint32_t addressStride; // loop 硬件上下文中的地址步长 |
| 204 | -} HcommCcuLoopContextPod; | 202 | +} HcommCcuLoopContext; |
| 205 | 203 | ||
| 206 | // 控制面注入的上下文查询函数指针(hcomm 实现,asc-comm 诊断时调用,结果按 CCU 版本解析) | 204 | // 控制面注入的上下文查询函数指针(hcomm 实现,asc-comm 诊断时调用,结果按 CCU 版本解析) |
| 207 | typedef int32_t (*HcommCcuMissionContextQueryFn)( | 205 | typedef int32_t (*HcommCcuMissionContextQueryFn)( |
| 208 | - int32_t deviceId, uint32_t dieId, uint32_t missionId, HcommCcuMissionContextPod* context); | 206 | + int32_t deviceId, uint32_t dieId, uint32_t missionId, HcommCcuMissionContext* context); |
| 209 | typedef int32_t (*HcommCcuLoopContextQueryFn)( | 207 | typedef int32_t (*HcommCcuLoopContextQueryFn)( |
| 210 | - int32_t deviceId, uint32_t dieId, uint32_t loopId, HcommCcuLoopContextPod* context); | 208 | + int32_t deviceId, uint32_t dieId, uint32_t loopId, HcommCcuLoopContext* context); |
| 211 | // 资源值查询:按资源 id 返回 XN/CKE/GSA 的当前值(控制面实现,数据面诊断时调用) | 209 | // 资源值查询:按资源 id 返回 XN/CKE/GSA 的当前值(控制面实现,数据面诊断时调用) |
| 212 | typedef int32_t (*HcommCcuResourceQueryFn)(int32_t deviceId, uint32_t dieId, uint32_t resourceId, uint64_t* value); | 210 | typedef int32_t (*HcommCcuResourceQueryFn)(int32_t deviceId, uint32_t dieId, uint32_t resourceId, uint64_t* value); |
| 213 | 211 | ||
| 214 | #ifdef __cplusplus | 212 | #ifdef __cplusplus |
| 215 | } | 213 | } |
| 216 | - | ||
| 217 | -static_assert(std::is_standard_layout<HcommCcuDfxRequestPod>::value, "HcommCcuDfxRequestPod must be standard-layout"); | ||
| 218 | -static_assert( | ||
| 219 | - std::is_trivially_copyable<HcommCcuDfxRequestPod>::value, "HcommCcuDfxRequestPod must be trivially copyable"); | ||
| 220 | -static_assert(std::is_standard_layout<HcommCcuDfxRecordPod>::value, "HcommCcuDfxRecordPod must be standard-layout"); | ||
| 221 | -static_assert( | ||
| 222 | - std::is_trivially_copyable<HcommCcuDfxRecordPod>::value, "HcommCcuDfxRecordPod must be trivially copyable"); | ||
| 223 | -static_assert(sizeof(HcommCcuDfxRequestPod) == 32, "HcommCcuDfxRequestPod ABI size changed"); | ||
| 224 | -static_assert( | ||
| 225 | - offsetof(HcommCcuDfxRequestPod, kernelHandle) == 16, "HcommCcuDfxRequestPod.kernelHandle ABI offset changed"); | ||
| 226 | -static_assert(offsetof(HcommCcuDfxRecordPod, msg) == 16, "HcommCcuDfxRecordPod.msg ABI offset changed"); | ||
| 227 | -static_assert(sizeof(HcommCcuDfxRecordPod) == 192, "HcommCcuDfxRecordPod ABI size changed"); | ||
| 228 | #endif | 214 | #endif |
| 229 | 215 | ||
| 230 | #endif // HCOMM_CCU_DFX_H | 216 | #endif // HCOMM_CCU_DFX_H |
| @@ -1,65 +0,0 @@ | |||
| 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_INSTRUCTION_H | ||
| 12 | -#define HCOMM_CCU_INSTRUCTION_H | ||
| 13 | - | ||
| 14 | -#include <stdint.h> | ||
| 15 | - | ||
| 16 | -#include "hcomm/hcomm_ccu_abi.h" | ||
| 17 | - | ||
| 18 | -#ifdef __cplusplus | ||
| 19 | -#include <type_traits> | ||
| 20 | -extern "C" { | ||
| 21 | -#endif | ||
| 22 | - | ||
| 23 | -enum { | ||
| 24 | - HCOMM_CCU_INSTRUCTION_ABI_VERSION = 1, // 指令下发 POD ABI 版本 | ||
| 25 | - HCOMM_CCU_INSTRUCTION_LOAD_MAGIC_WORD = 0x43494E53U, // "CINS" | ||
| 26 | -}; | ||
| 27 | - | ||
| 28 | -/** | ||
| 29 | - * 指令下发请求。 | ||
| 30 | - * | ||
| 31 | - * 调用方先将编译好的微码指令拷入设备内存,再通过本 POD 告知 hcomm 指令所在的设备地址、 | ||
| 32 | - * 目标 die、起始指令槽位与字节数;报文组装与驱动交互均在 libhcomm.so 内完成。 | ||
| 33 | - * deviceAddress 指向的内存由调用方持有,hcomm 仅在本次调用期间使用,不保存该地址。 | ||
| 34 | - * | ||
| 35 | - * @param header ABI 头:version/magic/size 校验 | ||
| 36 | - * @param deviceLogicId 目标设备逻辑 id | ||
| 37 | - * @param dieId 目标 die(< HCOMM_CCU_MAX_DIE_NUM) | ||
| 38 | - * @param startInstructionId 硬件指令槽位起始 idx | ||
| 39 | - * @param reserved 保留字段,使 deviceAddress 按 8 字节对齐 | ||
| 40 | - * @param deviceAddress 指令所在设备内存地址(调用方持有,仅本次调用借用) | ||
| 41 | - * @param byteSize 指令总字节数,hcomm 内部校验后收窄为 uint32_t | ||
| 42 | - */ | ||
| 43 | -typedef struct { | ||
| 44 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | ||
| 45 | - int32_t deviceLogicId; // 目标设备逻辑 id | ||
| 46 | - uint32_t dieId; // 目标 die(< HCOMM_CCU_MAX_DIE_NUM) | ||
| 47 | - uint32_t startInstructionId; // 硬件指令槽位起始 idx | ||
| 48 | - uint32_t reserved; // 保留字段,使 deviceAddress 按 8 字节对齐 | ||
| 49 | - uint64_t deviceAddress; // 指令所在设备内存地址 | ||
| 50 | - uint64_t byteSize; // 指令总字节数,hcomm 内部校验后收窄为 uint32_t | ||
| 51 | -} HcommCcuInstructionLoadPod; | ||
| 52 | - | ||
| 53 | -#ifdef __cplusplus | ||
| 54 | -static_assert( | ||
| 55 | - std::is_standard_layout<HcommCcuInstructionLoadPod>::value, "HcommCcuInstructionLoadPod must be standard layout"); | ||
| 56 | -static_assert( | ||
| 57 | - std::is_trivially_copyable<HcommCcuInstructionLoadPod>::value, | ||
| 58 | - "HcommCcuInstructionLoadPod must be trivially copyable"); | ||
| 59 | -#endif | ||
| 60 | - | ||
| 61 | -#ifdef __cplusplus | ||
| 62 | -} | ||
| 63 | -#endif | ||
| 64 | - | ||
| 65 | -#endif // HCOMM_CCU_INSTRUCTION_H | ||
| @@ -16,13 +16,11 @@ | |||
| 16 | #ifndef HCOMM_CCU_LAUNCH_H | 16 | #ifndef HCOMM_CCU_LAUNCH_H |
| 17 | #define HCOMM_CCU_LAUNCH_H | 17 | #define HCOMM_CCU_LAUNCH_H |
| 18 | 18 | ||
| 19 | -#include <stddef.h> | ||
| 20 | #include <stdint.h> | 19 | #include <stdint.h> |
| 21 | -#include "hcomm/hcomm_ccu_res.h" | 20 | + |
| 22 | #include "hcomm/hcomm_ccu_dfx.h" | 21 | #include "hcomm/hcomm_ccu_dfx.h" |
| 23 | 22 | ||
| 24 | #ifdef __cplusplus | 23 | #ifdef __cplusplus |
| 25 | -#include <type_traits> | ||
| 26 | extern "C" { | 24 | extern "C" { |
| 27 | #endif | 25 | #endif |
| 28 | 26 | ||
| @@ -41,14 +39,14 @@ enum { | |||
| 41 | * header 标识该结构的 ABI 布局;cycle、任务位置和 kernelHandle 由 hcomm 转换后交给原 callback。 | 39 | * header 标识该结构的 ABI 布局;cycle、任务位置和 kernelHandle 由 hcomm 转换后交给原 callback。 |
| 42 | */ | 40 | */ |
| 43 | typedef struct { | 41 | typedef struct { |
| 44 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | 42 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 |
| 45 | - uint64_t beginCycle; // task 起始 cycle(profiling 采集值) | 43 | + uint64_t beginCycle; // task 起始 cycle(profiling 采集值) |
| 46 | - uint64_t endCycle; // task 结束 cycle | 44 | + uint64_t endCycle; // task 结束 cycle |
| 47 | - uint32_t dieId; // 所在 die | 45 | + uint32_t dieId; // 所在 die |
| 48 | - uint32_t missionId; // mission id | 46 | + uint32_t missionId; // mission id |
| 49 | - uint32_t instructionId; // 指令(起始)id | 47 | + uint32_t instructionId; // 指令(起始)id |
| 50 | - uint32_t isMaster; // 是否 master 核,1 为是 | 48 | + uint32_t isMaster; // 是否 master 核,1 为是 |
| 51 | - uint64_t kernelHandle; // kernel 句柄 | 49 | + uint64_t kernelHandle; // kernel 句柄 |
| 52 | HcommCcuDiagnoseFn diagnose; // asc-comm 提供的诊断入口,hcomm 在任务异常时调用(见 HcommCcuDiagnoseFn) | 50 | HcommCcuDiagnoseFn diagnose; // asc-comm 提供的诊断入口,hcomm 在任务异常时调用(见 HcommCcuDiagnoseFn) |
| 53 | uint64_t reserved; // 预留字段,当前必须为 0 | 51 | uint64_t reserved; // 预留字段,当前必须为 0 |
| 54 | } HcommCcuTaskProfilePod; | 52 | } HcommCcuTaskProfilePod; |
| @@ -59,18 +57,18 @@ typedef struct { | |||
| 59 | * header 在读取名称和数组前完成 ABI 校验;定长字段仅用于跨动态库传值,不携带资源所有权。 | 57 | * header 在读取名称和数组前完成 ABI 校验;定长字段仅用于跨动态库传值,不携带资源所有权。 |
| 60 | */ | 58 | */ |
| 61 | typedef struct { | 59 | typedef struct { |
| 62 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | 60 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 |
| 63 | - uint32_t nameLength; // name 实际长度(必须 < HCOMM_CCU_PROFILE_NAME_CAPACITY) | 61 | + uint32_t nameLength; // name 实际长度(必须 < HCOMM_CCU_PROFILE_NAME_CAPACITY) |
| 64 | - uint32_t profilingType; // profiling 类型(L0/L1 等) | 62 | + uint32_t profilingType; // profiling 类型(L0/L1 等) |
| 65 | - uint32_t dieId; // 所在 die | 63 | + uint32_t dieId; // 所在 die |
| 66 | - uint32_t missionId; // mission id | 64 | + uint32_t missionId; // mission id |
| 67 | - uint32_t instructionId; // 指令 id | 65 | + uint32_t instructionId; // 指令 id |
| 68 | - uint32_t reduceOpType; // 归约操作类型(非归约时为无效值) | 66 | + uint32_t reduceOpType; // 归约操作类型(非归约时为无效值) |
| 69 | - uint32_t inputDataType; // 输入数据类型 | 67 | + uint32_t inputDataType; // 输入数据类型 |
| 70 | - uint32_t outputDataType; // 输出数据类型 | 68 | + uint32_t outputDataType; // 输出数据类型 |
| 71 | - uint64_t dataSize; // 搬运/归约的数据量(字节或元素数) | 69 | + uint64_t dataSize; // 搬运/归约的数据量(字节或元素数) |
| 72 | - uint32_t ckeId; // 关联信号量 CKE id | 70 | + uint32_t ckeId; // 关联信号量 CKE id |
| 73 | - uint32_t mask; // 信号掩码 | 71 | + uint32_t mask; // 信号掩码 |
| 74 | uint16_t channelId[HCOMM_CCU_PROFILE_CHANNEL_CAPACITY]; // 关联 channel id 数组 | 72 | uint16_t channelId[HCOMM_CCU_PROFILE_CHANNEL_CAPACITY]; // 关联 channel id 数组 |
| 75 | uint32_t remoteRankId[HCOMM_CCU_PROFILE_CHANNEL_CAPACITY]; // 远端 rank id 数组 | 73 | uint32_t remoteRankId[HCOMM_CCU_PROFILE_CHANNEL_CAPACITY]; // 远端 rank id 数组 |
| 76 | uint64_t channelHandle[HCOMM_CCU_PROFILE_CHANNEL_CAPACITY]; // 关联 channel 句柄数组 | 74 | uint64_t channelHandle[HCOMM_CCU_PROFILE_CHANNEL_CAPACITY]; // 关联 channel 句柄数组 |
| @@ -92,7 +90,7 @@ typedef int32_t (*HcommCcuReportTaskCallback)( | |||
| 92 | * 返回前有效。其余字段描述线程所属设备、超时、主从属性和 profiling 开关,调用方不得接管任何资源。 | 90 | * 返回前有效。其余字段描述线程所属设备、超时、主从属性和 profiling 开关,调用方不得接管任何资源。 |
| 93 | */ | 91 | */ |
| 94 | typedef struct { | 92 | typedef struct { |
| 95 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | 93 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 |
| 96 | int32_t deviceLogicId; // 线程所在设备逻辑 id | 94 | int32_t deviceLogicId; // 线程所在设备逻辑 id |
| 97 | uint32_t timeoutSec; // launch 超时秒数 | 95 | uint32_t timeoutSec; // launch 超时秒数 |
| 98 | uint64_t runtimeStream; // runtime stream 句柄(借用,不发生所有权转移) | 96 | uint64_t runtimeStream; // runtime stream 句柄(借用,不发生所有权转移) |
| @@ -109,30 +107,6 @@ typedef struct { | |||
| 109 | #ifdef __cplusplus | 107 | #ifdef __cplusplus |
| 110 | } | 108 | } |
| 111 | 109 | ||
| 112 | -static_assert( | ||
| 113 | - std::is_standard_layout<HcommCcuLaunchContextPod>::value, "HcommCcuLaunchContextPod must be standard-layout"); | ||
| 114 | -static_assert( | ||
| 115 | - std::is_trivially_copyable<HcommCcuLaunchContextPod>::value, "HcommCcuLaunchContextPod must be trivially copyable"); | ||
| 116 | -static_assert(std::is_standard_layout<HcommCcuTaskProfilePod>::value, "HcommCcuTaskProfilePod must be standard-layout"); | ||
| 117 | -static_assert( | ||
| 118 | - std::is_trivially_copyable<HcommCcuTaskProfilePod>::value, "HcommCcuTaskProfilePod must be trivially copyable"); | ||
| 119 | -static_assert( | ||
| 120 | - std::is_standard_layout<HcommCcuProfileDetailPod>::value, "HcommCcuProfileDetailPod must be standard-layout"); | ||
| 121 | -static_assert( | ||
| 122 | - std::is_trivially_copyable<HcommCcuProfileDetailPod>::value, "HcommCcuProfileDetailPod must be trivially copyable"); | ||
| 123 | -static_assert(sizeof(HcommCcuLaunchContextPod) == 88, "HcommCcuLaunchContextPod ABI size changed"); | ||
| 124 | -static_assert( | ||
| 125 | - offsetof(HcommCcuLaunchContextPod, runtimeStream) == 24, | ||
| 126 | - "HcommCcuLaunchContextPod.runtimeStream ABI offset changed"); | ||
| 127 | -static_assert( | ||
| 128 | - offsetof(HcommCcuLaunchContextPod, threadHandle) == 48, "HcommCcuLaunchContextPod.threadHandle ABI offset changed"); | ||
| 129 | -static_assert(sizeof(HcommCcuTaskProfilePod) == 72, "HcommCcuTaskProfilePod ABI size changed"); | ||
| 130 | -static_assert( | ||
| 131 | - offsetof(HcommCcuTaskProfilePod, kernelHandle) == 48, "HcommCcuTaskProfilePod.kernelHandle ABI offset changed"); | ||
| 132 | -static_assert(sizeof(HcommCcuProfileDetailPod) == 432, "HcommCcuProfileDetailPod ABI size changed"); | ||
| 133 | -static_assert( | ||
| 134 | - offsetof(HcommCcuProfileDetailPod, channelId) == 64, "HcommCcuProfileDetailPod.channelId ABI offset changed"); | ||
| 135 | -static_assert(offsetof(HcommCcuProfileDetailPod, name) == 288, "HcommCcuProfileDetailPod.name ABI offset changed"); | ||
| 136 | #endif | 110 | #endif |
| 137 | 111 | ||
| 138 | #endif // HCOMM_CCU_LAUNCH_H | 112 | #endif // HCOMM_CCU_LAUNCH_H |
| @@ -1,153 +0,0 @@ | |||
| 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 | -/** | ||
| 12 | - * @file hcomm_ccu_res.h | ||
| 13 | - * @brief CCU 资源层跨 SO POD 定义(Register Context 及相关资源 range/metadata)。 | ||
| 14 | - * | ||
| 15 | - * 用户通过只读不透明句柄借用 Register Context,具体 POD 仅由 hcomm 和 asc-comm 内部解释。 | ||
| 16 | - */ | ||
| 17 | -#ifndef HCOMM_CCU_RES_H | ||
| 18 | -#define HCOMM_CCU_RES_H | ||
| 19 | - | ||
| 20 | -#include <stddef.h> | ||
| 21 | -#include <stdint.h> | ||
| 22 | -#include "hcomm/hcomm_ccu_abi.h" | ||
| 23 | -#include "hcomm/hcomm_ccu_common.h" | ||
| 24 | -#include "hcomm/hcomm_ccu_control.h" | ||
| 25 | -#include "hcomm/hcomm_types.h" | ||
| 26 | -#ifdef __cplusplus | ||
| 27 | -#include <type_traits> | ||
| 28 | -extern "C" { | ||
| 29 | -#endif | ||
| 30 | - | ||
| 31 | -typedef const struct HcommCcuRegisterContextOpaque* HcommCcuRegisterContextHandle; | ||
| 32 | - | ||
| 33 | -enum { | ||
| 34 | - HCOMM_CCU_RES_ABI_VERSION = 7, // 资源/注册上下文 POD ABI 版本 | ||
| 35 | - HCOMM_CCU_REGISTER_CONTEXT_MAGIC_WORD = 0x43435532U, // "CCU2",RegisterContext POD 魔数 | ||
| 36 | - HCOMM_CCU_BATCH_RES_TYPE_COUNT = 11, // 批量资源类型总数(不含 INS) | ||
| 37 | - HCOMM_CCU_RES_INSTRUCTION = HCOMM_CCU_BATCH_RES_TYPE_COUNT, // INS 资源的 range 类型号 | ||
| 38 | - HCOMM_CCU_VERSION_V1 = 0, // CCU V1 版本号(ABI 内透传) | ||
| 39 | - HCOMM_CCU_VERSION_V2 = 1, // CCU V2 版本号 | ||
| 40 | - HCOMM_CCU_VERSION_INVALID = 0xFFFFFFFFU, // 无效版本哨兵 | ||
| 41 | - HCOMM_CCU_RESOURCE_XN_PER_SIZE = 8, // 单个 XN 资源占用的空间步长(地址换算用) | ||
| 42 | -}; | ||
| 43 | - | ||
| 44 | -/** 批量资源的 range 类型枚举(与 CcuResRepository 各资源组一一对应) */ | ||
| 45 | -typedef enum { | ||
| 46 | - HCOMM_CCU_BATCH_RES_LOOP = 0, | ||
| 47 | - HCOMM_CCU_BATCH_RES_BLOCK_LOOP = 1, | ||
| 48 | - HCOMM_CCU_BATCH_RES_MS = 2, | ||
| 49 | - HCOMM_CCU_BATCH_RES_BLOCK_MS = 3, | ||
| 50 | - HCOMM_CCU_BATCH_RES_CKE = 4, | ||
| 51 | - HCOMM_CCU_BATCH_RES_BLOCK_CKE = 5, | ||
| 52 | - HCOMM_CCU_BATCH_RES_BLOCK_XN = 6, | ||
| 53 | - HCOMM_CCU_BATCH_RES_XN = 7, | ||
| 54 | - HCOMM_CCU_BATCH_RES_GSA = 8, | ||
| 55 | - HCOMM_CCU_BATCH_RES_BLOCK_GSA = 9, | ||
| 56 | - HCOMM_CCU_BATCH_RES_MISSION = 10, | ||
| 57 | -} HcommCcuBatchResType; | ||
| 58 | - | ||
| 59 | -/** 一段连续资源的 range:类型 + die + 起始 id + 数量 */ | ||
| 60 | -typedef struct { | ||
| 61 | - uint32_t resourceType; // 资源类别:LOOP、MS、CKE、XN、GSA、MISSION 或 INS | ||
| 62 | - uint32_t dieId; // 该资源范围所属 die | ||
| 63 | - uint32_t startId; // 连续资源的起始 ID | ||
| 64 | - uint32_t count; // 从 startId 开始的资源数量,必须大于 0 | ||
| 65 | -} HcommCcuResRangePod; | ||
| 66 | - | ||
| 67 | -/** | ||
| 68 | - * 资源 range 数组的只读视图,由 Register Context 持有。 | ||
| 69 | - */ | ||
| 70 | -typedef struct { | ||
| 71 | - const HcommCcuResRangePod* ranges; // Register Context 持有的只读 Range 数组 | ||
| 72 | - uint32_t count; // Range 元素数量 | ||
| 73 | - uint32_t reserved; // 对齐和扩展字段,当前必须为 0 | ||
| 74 | -} HcommCcuResRangeViewPod; | ||
| 75 | - | ||
| 76 | -/** 单个 die 的元数据:回路 channel、XN 基址与资源空间 token 等 */ | ||
| 77 | -typedef struct { | ||
| 78 | - uint32_t enabled; // 该 die 是否启用 | ||
| 79 | - uint32_t missionKey; // mission 密钥 | ||
| 80 | - uint32_t innerDieLoopChannelId; // die 内回路 channel id | ||
| 81 | - uint32_t interDieLoopChannelId; // die 间回路 channel id | ||
| 82 | - uint64_t xnBaseAddr; // XN 基址 | ||
| 83 | - uint64_t resourceSpaceTokenId; // CCU 资源空间 token id | ||
| 84 | - uint64_t resourceSpaceTokenValue; // CCU 资源空间 token value | ||
| 85 | - uint32_t instructionCapacity; // 已分配的指令容量 | ||
| 86 | - uint32_t reserved; // 预留字段,当前必须为 0 | ||
| 87 | -} HcommCcuDieMetadataPod; | ||
| 88 | - | ||
| 89 | -/** 通信域注册上下文:一次 Create 后快照的全部数据面所需信息 */ | ||
| 90 | -typedef struct { | ||
| 91 | - HcommCcuAbiHeaderPod header; // ABI 头:version/magic/size 校验 | ||
| 92 | - uint64_t generation; // 资源世代号(用于句柄校验) | ||
| 93 | - int32_t deviceLogicId; // 注册上下文所属设备逻辑 ID | ||
| 94 | - uint32_t ccuVersion; // 当前设备的 CCU 版本 | ||
| 95 | - uint32_t dieNum; // POD 中 die 槽位数,当前固定为 2 | ||
| 96 | - uint32_t validDieMask; // 有效 die 位图 | ||
| 97 | - CcuInsHandle instanceHandle; // 对应 hcomm 侧 instance/资源句柄 | ||
| 98 | - uint32_t instanceType; // 本上下文申请的 CCU Instance 类型 | ||
| 99 | - HcommCcuControlOpsPod controlOps; // 控制面注入的函数表(channelQuery 等) | ||
| 100 | - HcommCcuResRangeViewPod instanceResources; // Context 持有的只读资源 range 视图 | ||
| 101 | - HcommCcuDieMetadataPod die[HCOMM_CCU_MAX_DIE_NUM]; // 每个 die 的能力、基址、Token 和指令容量 | ||
| 102 | - uint64_t reserved[2]; // 预留扩展空间,当前必须清零 | ||
| 103 | -} HcommCcuRegisterContextPod; | ||
| 104 | - | ||
| 105 | -/** | ||
| 106 | - * @brief 查询 HCCL 通信域持有的 CCU Register context。 | ||
| 107 | - * @param[in] comm HCCL 通信域句柄,不可为 nullptr。 | ||
| 108 | - * @param[out] context hcomm 持有的只读 Register Context 借用指针。 | ||
| 109 | - * @return HcclResult。 | ||
| 110 | - * @note context 从通信域初始化成功后有效,到 HcclCommDestroy 开始销毁前失效; | ||
| 111 | - * RegisterStart 不得与通信域销毁并发,RegisterStart 返回前由 asc-comm 深拷贝。 | ||
| 112 | - */ | ||
| 113 | -extern HcclResult HcclCommQueryCcuRegisterContext(HcclComm comm, HcommCcuRegisterContextHandle* context); | ||
| 114 | - | ||
| 115 | -#ifdef __cplusplus | ||
| 116 | -} | ||
| 117 | - | ||
| 118 | -static_assert(std::is_standard_layout<HcommCcuResRangePod>::value, "HcommCcuResRangePod must be standard-layout"); | ||
| 119 | -static_assert(std::is_trivially_copyable<HcommCcuResRangePod>::value, "HcommCcuResRangePod must be trivially copyable"); | ||
| 120 | -static_assert( | ||
| 121 | - std::is_standard_layout<HcommCcuResRangeViewPod>::value, "HcommCcuResRangeViewPod must be standard-layout"); | ||
| 122 | -static_assert( | ||
| 123 | - std::is_trivially_copyable<HcommCcuResRangeViewPod>::value, "HcommCcuResRangeViewPod must be trivially copyable"); | ||
| 124 | -static_assert(std::is_standard_layout<HcommCcuDieMetadataPod>::value, "HcommCcuDieMetadataPod must be standard-layout"); | ||
| 125 | -static_assert( | ||
| 126 | - std::is_trivially_copyable<HcommCcuDieMetadataPod>::value, "HcommCcuDieMetadataPod must be trivially copyable"); | ||
| 127 | -static_assert( | ||
| 128 | - std::is_standard_layout<HcommCcuRegisterContextPod>::value, "HcommCcuRegisterContextPod must be standard-layout"); | ||
| 129 | -static_assert( | ||
| 130 | - std::is_trivially_copyable<HcommCcuRegisterContextPod>::value, | ||
| 131 | - "HcommCcuRegisterContextPod must be trivially copyable"); | ||
| 132 | -static_assert(sizeof(HcommCcuResRangePod) == 16, "HcommCcuResRangePod ABI size changed"); | ||
| 133 | -static_assert(offsetof(HcommCcuResRangePod, count) == 12, "HcommCcuResRangePod.count ABI offset changed"); | ||
| 134 | -static_assert(sizeof(HcommCcuResRangeViewPod) == 16, "HcommCcuResRangeViewPod ABI size changed"); | ||
| 135 | -static_assert(offsetof(HcommCcuResRangeViewPod, count) == 8, "HcommCcuResRangeViewPod.count ABI offset changed"); | ||
| 136 | -static_assert(sizeof(HcommCcuDieMetadataPod) == 48, "HcommCcuDieMetadataPod ABI size changed"); | ||
| 137 | -static_assert( | ||
| 138 | - offsetof(HcommCcuDieMetadataPod, xnBaseAddr) == 16, "HcommCcuDieMetadataPod.xnBaseAddr ABI offset changed"); | ||
| 139 | -static_assert(sizeof(HcommCcuRegisterContextPod) == 264, "HcommCcuRegisterContextPod ABI size changed"); | ||
| 140 | -static_assert( | ||
| 141 | - offsetof(HcommCcuRegisterContextPod, generation) == 16, "HcommCcuRegisterContextPod.generation ABI offset changed"); | ||
| 142 | -static_assert( | ||
| 143 | - offsetof(HcommCcuRegisterContextPod, instanceHandle) == 40, | ||
| 144 | - "HcommCcuRegisterContextPod.instanceHandle ABI offset changed"); | ||
| 145 | -static_assert( | ||
| 146 | - offsetof(HcommCcuRegisterContextPod, controlOps) == 56, "HcommCcuRegisterContextPod.controlOps ABI offset changed"); | ||
| 147 | -static_assert( | ||
| 148 | - offsetof(HcommCcuRegisterContextPod, instanceResources) == 136, | ||
| 149 | - "HcommCcuRegisterContextPod.instanceResources ABI offset changed"); | ||
| 150 | -static_assert(offsetof(HcommCcuRegisterContextPod, die) == 152, "HcommCcuRegisterContextPod.die ABI offset changed"); | ||
| 151 | -#endif | ||
| 152 | - | ||
| 153 | -#endif // HCOMM_CCU_RES_H | ||
| @@ -0,0 +1,306 @@ | |||
| 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 | +/** | ||
| 12 | + * @file hcomm_ccu_resource.h | ||
| 13 | + * @brief CCU instance、resource、channel 跨 SO POD 定义。 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef HCOMM_CCU_RESOURCE_H | ||
| 17 | +#define HCOMM_CCU_RESOURCE_H | ||
| 18 | + | ||
| 19 | +#include <stdint.h> | ||
| 20 | +#include "hcomm/hcomm_ccu_base.h" | ||
| 21 | +#include "hcomm/hcomm_res_entity_defs.h" | ||
| 22 | +#include "hcomm/hcomm_types.h" | ||
| 23 | + | ||
| 24 | +#ifdef __cplusplus | ||
| 25 | +extern "C" { | ||
| 26 | +#endif | ||
| 27 | + | ||
| 28 | +/** CCU Instance 类型:注册上下文申请的实例类型;hcomm 创建 RegisterContext 时校验,并据此分配资源句柄 */ | ||
| 29 | +typedef enum { CCU_DEFAULT = 0, CCU_SCHED = 1, CCU_MS = 2, CCU_UNUSED = 254, CCU_RESERVED = 255 } CcuInstanceType; | ||
| 30 | + | ||
| 31 | +struct HcommCcuInstance; | ||
| 32 | + | ||
| 33 | +enum { | ||
| 34 | + HCOMM_CCU_INSTANCE_HANDLE_ABI_VERSION = 1, // CcuInsHandle ABI 版本 | ||
| 35 | + HCOMM_CCU_INSTANCE_HANDLE_MAGIC_WORD = 0x43435548U, // CcuInsHandle 类型魔数,值即 ASCII "CCUH"(CCU Handle), | ||
| 36 | + // 接收方校验 header.magicWord 确认传入 POD 类型正确 | ||
| 37 | +}; | ||
| 38 | + | ||
| 39 | +/** | ||
| 40 | + * CCU Instance 句柄(CommAbiHeader + ccuInsKey + ccuInsPtr 三字段): | ||
| 41 | + * header 为 ABI 头:version/magic/size 校验,防两仓布局不一致时按值传递越界读; | ||
| 42 | + * ccuInsKey 为 hcomm 位编码的不透明键(generation<<32 | slot+1),用于跨 SO 传递与查找; | ||
| 43 | + * ccuInsPtr 指向 hcomm 持有的 HcommCcuInstance(只读借用,随 RegisterContext 生命周期有效)。 | ||
| 44 | + * hcomm 负责编码、校验、销毁,asc-comm 只能按值保存和回传,不得解引用 ccuInsPtr 之外的成员。 | ||
| 45 | + */ | ||
| 46 | +typedef struct { | ||
| 47 | + CommAbiHeader header; // ABI 头:version/magic/size 校验. | ||
| 48 | + uint64_t ccuInsKey; // 不透明实例键(0 为无效句柄哨兵) | ||
| 49 | + const struct HcommCcuInstance* ccuInsPtr; // hcomm 持有的 CCU Instance 借用指针 | ||
| 50 | +} CcuInsHandle; | ||
| 51 | + | ||
| 52 | +#ifdef __cplusplus | ||
| 53 | +} | ||
| 54 | +#endif | ||
| 55 | + | ||
| 56 | +#ifndef CHANNEL_HANDLE_DEFINED | ||
| 57 | +#define CHANNEL_HANDLE_DEFINED | ||
| 58 | +// 通道句柄:不透明唯一标识,跨 SO 以整型值传递 | ||
| 59 | +typedef uint64_t ChannelHandle; | ||
| 60 | +#endif | ||
| 61 | + | ||
| 62 | +#ifdef __cplusplus | ||
| 63 | +extern "C" { | ||
| 64 | +#endif | ||
| 65 | + | ||
| 66 | +enum { | ||
| 67 | + HCOMM_CCU_CHANNEL_ABI_VERSION = 4, // 当前 Channel Entity ABI 版本 | ||
| 68 | + HCOMM_CCU_CHANNEL_MAGIC_WORD = 0x43435543U, // "CCUC",标识 Channel Entity 类型 | ||
| 69 | + HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY = 16, // 每个 channel 持有的 XN/CKE 资源槽位数 | ||
| 70 | +}; | ||
| 71 | + | ||
| 72 | +/** | ||
| 73 | + * @brief CCU Channel 单次查询快照实体(16 槽 + 计数 + 事件掩码 + 远端 buffer 数组)。 | ||
| 74 | + * | ||
| 75 | + * localVarIds/remoteVarIds 为本/远端 XN 槽,localEventIds/remoteEventIds 为本/远端 CKE 槽, | ||
| 76 | + * 实际有效数量由 localVarNum/remoteVarNum/localEventNum/remoteEventNum 给出(<= 容量)。 | ||
| 77 | + * localEventMasks/remoteEventMasks 为预留槽位:mask 是 kernel 构建期的按次参数, | ||
| 78 | + * 非 channel 属性,当前固定填 0。 | ||
| 79 | + * rmtCcuResBuffer 为对端 CCU 资源空间(RegedBufferEntity 口径,取代旧散字段)。 | ||
| 80 | + * remoteBuffers 为 hcomm channel 内部远端 buffer 列表的借用指针,channel 销毁后失效; | ||
| 81 | + * 当前数据面未消费(翻译器仍按单 CCU 资源空间假设),为形状兼容预留。 | ||
| 82 | + * 调用方提供存储并填好 ABI 头,hcomm 持锁一次填满快照,之后数据面只读该实体。 | ||
| 83 | + */ | ||
| 84 | +typedef struct { | ||
| 85 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 | ||
| 86 | + | ||
| 87 | + int32_t deviceLogicId; // 所在设备逻辑 id | ||
| 88 | + uint32_t ccuVersion; // CCU 版本(V1/V2) | ||
| 89 | + uint32_t dieId; // die id | ||
| 90 | + uint32_t channelId; // channel id(DFX 记录用) | ||
| 91 | + | ||
| 92 | + RegedBufferEntity rmtCcuResBuffer; // 对端 CCU 资源空间(基址/大小/token 折叠为 buffer 实体) | ||
| 93 | + | ||
| 94 | + uint32_t localVarNum; // 本端 XN 有效数量(<= HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY) | ||
| 95 | + uint32_t remoteVarNum; // 远端 XN 有效数量 | ||
| 96 | + uint32_t localEventNum; // 本端 CKE 有效数量 | ||
| 97 | + uint32_t remoteEventNum; // 远端 CKE 有效数量 | ||
| 98 | + uint32_t remoteBufferNum; // 远端 buffer 数量(remoteBuffers 数组长度) | ||
| 99 | + const RegedBufferEntity* remoteBuffers; // 远端 buffer 数组借用指针(hcomm 持有,当前数据面不消费) | ||
| 100 | + | ||
| 101 | + uint32_t localVarIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 本端 XN id 槽 | ||
| 102 | + uint32_t remoteVarIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 远端 XN id 槽 | ||
| 103 | + uint32_t localEventIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 本端 CKE id 槽 | ||
| 104 | + uint32_t remoteEventIds[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 远端 CKE id 槽 | ||
| 105 | + uint32_t localEventMasks[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 本端 CKE 掩码槽(预留,填 0) | ||
| 106 | + uint32_t remoteEventMasks[HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY]; // 远端 CKE 掩码槽(预留,填 0) | ||
| 107 | + | ||
| 108 | +} HcommCcuChannelEntity; | ||
| 109 | + | ||
| 110 | +#ifdef __cplusplus | ||
| 111 | +} // extern "C" | ||
| 112 | + | ||
| 113 | +#endif | ||
| 114 | + | ||
| 115 | +/** | ||
| 116 | + * @brief CCU 资源描述符(ResDesc)跨 SO POD 定义。 | ||
| 117 | + * | ||
| 118 | + * hcomm 和 asc-comm 各自保留一份同布局的 HcommCcuResDesc POD 定义。 | ||
| 119 | + * HcommCcuResDesc 不对用户暴露,用户只感知 HcommCcuResDescHandle; | ||
| 120 | + * asc-comm 侧由 handle table 解析出实际 POD。 | ||
| 121 | + */ | ||
| 122 | +#ifdef __cplusplus | ||
| 123 | +extern "C" { | ||
| 124 | +#endif | ||
| 125 | + | ||
| 126 | +enum { | ||
| 127 | + HCOMM_CCU_RES_DESC_ABI_VERSION = 1, // ResDesc POD ABI 版本 | ||
| 128 | + HCOMM_CCU_RES_DESC_MAGIC_WORD = 0x43524453U, // "CRDS",ResDesc POD 魔数 | ||
| 129 | + HCOMM_CCU_RES_DESC_TYPE_COUNT = 32, // 资源类型槽位数(预留到 32,现用 0-7) | ||
| 130 | +}; | ||
| 131 | + | ||
| 132 | +/** 资源描述符统计口径的类型枚举(block/非 block 在此合并计数;值域为跨 SO ABI,不可改动) */ | ||
| 133 | +typedef enum { | ||
| 134 | + CCU_RES_DESC_LOOP = 0, // LoopEngine(loop + block loop 之和) | ||
| 135 | + CCU_RES_DESC_MS = 1, // Memory Slice(ms + block ms 之和) | ||
| 136 | + CCU_RES_DESC_CKE = 2, // 完成事件/信号量(cke + block cke 之和) | ||
| 137 | + CCU_RES_DESC_XN = 3, // 变量(xn + block xn 之和) | ||
| 138 | + CCU_RES_DESC_COUNT_XN = 4, // 计数变量(预留,当前恒为 0) | ||
| 139 | + CCU_RES_DESC_GSA = 5, // 通用存储地址(gsa + block gsa 之和) | ||
| 140 | + CCU_RES_DESC_INS = 6, // 指令空间(指令条数) | ||
| 141 | + CCU_RES_DESC_MISSION = 7, // mission 数 | ||
| 142 | +} CcuResDescType; | ||
| 143 | + | ||
| 144 | +/** CCU 资源描述符 POD:按资源类型统计的申请数量(创建时设 dieId,查询后填数量) */ | ||
| 145 | +typedef struct { | ||
| 146 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 | ||
| 147 | + uint32_t dieId; // 资源归属的 die id(创建描述符时设置) | ||
| 148 | + uint32_t resLength; // resNum 数组的有效长度(<= HCOMM_CCU_RES_DESC_TYPE_COUNT) | ||
| 149 | + uint32_t resNum[HCOMM_CCU_RES_DESC_TYPE_COUNT]; // 按资源类型索引的数量 | ||
| 150 | +} HcommCcuResDesc; | ||
| 151 | + | ||
| 152 | +/** 资源描述符句柄:不对用户暴露 POD,由 asc-comm 侧 handle table 解析 */ | ||
| 153 | +typedef uint64_t HcommCcuResDescHandle; | ||
| 154 | + | ||
| 155 | +/** | ||
| 156 | + * @brief 反查资源描述符内容,hcomm 侧据此获取实际需要的 CCU 资源。 | ||
| 157 | + * | ||
| 158 | + * 按 handle 值拷贝返回描述符当前内容(dieId + 各资源类型数量)。 | ||
| 159 | + * 供 hcomm 按需建实例(HcommCcuInsCreate by ResDesc)等控制面消费;用户不直接调用。 | ||
| 160 | + * | ||
| 161 | + * @param[in] resDesc 资源描述符句柄 | ||
| 162 | + * @param[out] out 输出描述符内容(值拷贝,调用方持有存储) | ||
| 163 | + * @return CcuResult | ||
| 164 | + */ | ||
| 165 | +extern CcuResult HcommCcuInsResDescQuery(HcommCcuResDescHandle resDesc, HcommCcuResDesc* out); | ||
| 166 | + | ||
| 167 | +#ifdef __cplusplus | ||
| 168 | +} // extern "C" | ||
| 169 | + | ||
| 170 | +#endif | ||
| 171 | + | ||
| 172 | +/** | ||
| 173 | + * @brief CCU 资源层跨 SO POD 定义(CCU Instance / Register Context)。 | ||
| 174 | + * | ||
| 175 | + * 资源按 die × 资源类型两级嵌套组织,每类持多段连续 range; | ||
| 176 | + * die 元数据(回路 channel、CCU 资源空间 buffer)由 HcommCcuDieMetadata 承载; | ||
| 177 | + * 控制面注入 hcomm 实现的函数表 ascCustom(槽 0/1/2 + DFX 查询链)。 | ||
| 178 | + * asc-comm 在 register_start 时对整个 Instance 做一次性深拷贝快照。 | ||
| 179 | + */ | ||
| 180 | +#ifdef __cplusplus | ||
| 181 | +extern "C" { | ||
| 182 | +#endif | ||
| 183 | + | ||
| 184 | +struct HcommCcuInstance; | ||
| 185 | +typedef const struct HcommCcuInstance* HcommCcuInstanceHandle; | ||
| 186 | +enum { | ||
| 187 | + HCOMM_CCU_RES_ABI_VERSION = 8, // 资源/CCU Instance POD ABI 版本 | ||
| 188 | + HCOMM_CCU_INSTANCE_MAGIC_WORD = 0x43435549U, // HcommCcuInstance 类型魔数,值即 ASCII "CCUI"(CCU Instance), | ||
| 189 | + // 接收方校验 header.magicWord 确认传入 POD 类型正确 | ||
| 190 | + HCOMM_CCU_DIE_METADATA_MAGIC_WORD = 0x4343444DU, // HcommCcuDieMetadata 类型魔数,值即 ASCII "CCDM"(CCU Die | ||
| 191 | + // Metadata), 接收方校验 header.magicWord 确认传入 POD 类型正确 | ||
| 192 | + HCOMM_CCU_RES_TYPE_COUNT = 32, // 单 die 预留的资源类型槽位数(现用 0-10,11-31 预留) | ||
| 193 | + HCOMM_CCU_BATCH_RES_TYPE_COUNT = 11, // HcommCcuBatchResType 枚举值数量(数组维度用) | ||
| 194 | + HCOMM_CCU_INSTANCE_DIE_CAPACITY = 8, // Instance 预留的 die 槽位数(现网 2 个) | ||
| 195 | + HCOMM_CCU_INSTR_WIDTH_BYTES = 32, // 单条 CCU 微码指令宽度(sizeof(asc ccu_instr)),SubmitInsts 换算用 | ||
| 196 | + HCOMM_CCU_VERSION_V1 = 0, // CCU V1 版本号(ABI 内透传) | ||
| 197 | + HCOMM_CCU_VERSION_V2 = 1, // CCU V2 版本号 | ||
| 198 | + HCOMM_CCU_VERSION_INVALID = 0xFFFFFFFFU, // 无效版本哨兵 | ||
| 199 | + HCOMM_CCU_RESOURCE_XN_PER_SIZE = 8, // 单个 XN 资源占用的空间步长(地址换算用) | ||
| 200 | + HCOMM_CCU_ASC_CUSTOM_CHANNEL_ENTITY = 0, // ascCustom 槽 0:获取 ChannelEntity 接口 | ||
| 201 | + HCOMM_CCU_ASC_CUSTOM_ALLOC_INST_SPACE = 1, // ascCustom 槽 1:申请 CCU 指令空间资源的接口 | ||
| 202 | + HCOMM_CCU_ASC_CUSTOM_SUBMIT_INSTS = 2, // ascCustom 槽 2:下发 CCU 指令接口 | ||
| 203 | + HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT = 8, // ascCustom 槽位总数(3-7 预留) | ||
| 204 | +}; | ||
| 205 | + | ||
| 206 | +/** 批量资源的 range 类型枚举(resTypes 数组按该枚举值索引;block/非 block 在 range 视图分开,ResDesc 统计口径才合并) | ||
| 207 | + */ | ||
| 208 | +typedef enum { | ||
| 209 | + HCOMM_CCU_BATCH_RES_LOOP = 0, | ||
| 210 | + HCOMM_CCU_BATCH_RES_BLOCK_LOOP = 1, | ||
| 211 | + HCOMM_CCU_BATCH_RES_MS = 2, | ||
| 212 | + HCOMM_CCU_BATCH_RES_BLOCK_MS = 3, | ||
| 213 | + HCOMM_CCU_BATCH_RES_CKE = 4, | ||
| 214 | + HCOMM_CCU_BATCH_RES_BLOCK_CKE = 5, | ||
| 215 | + HCOMM_CCU_BATCH_RES_BLOCK_XN = 6, | ||
| 216 | + HCOMM_CCU_BATCH_RES_XN = 7, | ||
| 217 | + HCOMM_CCU_BATCH_RES_GSA = 8, | ||
| 218 | + HCOMM_CCU_BATCH_RES_BLOCK_GSA = 9, | ||
| 219 | + HCOMM_CCU_BATCH_RES_MISSION = 10, | ||
| 220 | +} HcommCcuBatchResType; | ||
| 221 | + | ||
| 222 | +/** | ||
| 223 | + * 一段连续资源:起始 id + 数量。所属资源类型与 die 由外层 HcommCcuResRanges / HcommCcuDieRes 表达。 | ||
| 224 | + */ | ||
| 225 | +typedef struct { | ||
| 226 | + uint32_t startId; // 连续资源的起始 ID | ||
| 227 | + uint32_t count; // 从 startId 开始的资源数量,必须大于 0 | ||
| 228 | + uint64_t reserved; // 预留字段,当前必须为 0 | ||
| 229 | +} HcommCcuResRange; | ||
| 230 | + | ||
| 231 | +/** | ||
| 232 | + * 一类资源的全部 range 段(按资源类型枚举值挂在 HcommCcuDieRes.resTypes[type] 上)。 | ||
| 233 | + * resRanges 指向 hcomm RegisterContext 持有的只读数组,asc-comm 在 register_start 期间深拷贝。 | ||
| 234 | + */ | ||
| 235 | +typedef struct { | ||
| 236 | + uint32_t resourceType; // 资源类别(HcommCcuBatchResType) | ||
| 237 | + const HcommCcuResRange* resRanges; // 该类型的 range 数组(只读借用) | ||
| 238 | + uint32_t resRangeNum; // range 数组元素数量 | ||
| 239 | + uint64_t reserved; // 预留字段,当前必须为 0 | ||
| 240 | +} HcommCcuResRanges; | ||
| 241 | + | ||
| 242 | +/** | ||
| 243 | + * 单个 die 的元数据:回路 channel 与 CCU 资源空间 buffer。 | ||
| 244 | + * ccuResBuffer 按 {REGED_BUFFER_RMA, addr=XN 基址, ProtectionInfo.ub{tokenId, tokenValue}} 装配; | ||
| 245 | + * loopChannelId 为该 die 唯一的环回 channel(硬件上 die 内/间访问共用同一条,见 ccu_comp.cc "不区分die内die间")。 | ||
| 246 | + */ | ||
| 247 | +typedef struct { | ||
| 248 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 | ||
| 249 | + uint32_t enabled; // 该 die 是否启用(0/1) | ||
| 250 | + uint32_t missionKey; // mission 密钥 | ||
| 251 | + uint32_t loopChannelId; // 环回 channel id(每 die 一条,die 内/间访问共用) | ||
| 252 | + RegedBufferEntity ccuResBuffer; // CCU 资源空间(XN 基址 + token)映射后的 buffer 信息 | ||
| 253 | + uint32_t reserved; // 预留字段,当前必须为 0 | ||
| 254 | +} HcommCcuDieMetadata; | ||
| 255 | + | ||
| 256 | +/** 单个 die 的全部资源视图:按资源类型索引的 range 段数组 + die 元数据指针 */ | ||
| 257 | +typedef struct { | ||
| 258 | + uint32_t dieId; // 该资源视图所属 die | ||
| 259 | + uint32_t resTypeNum; // 已使用的资源类型数(<= HCOMM_CCU_RES_TYPE_COUNT) | ||
| 260 | + HcommCcuResRanges resTypes[HCOMM_CCU_RES_TYPE_COUNT]; // 按资源类型枚举值索引 | ||
| 261 | + const HcommCcuDieMetadata* dieMetadata; // hcomm 持有的 die 元数据(只读借用) | ||
| 262 | + uint64_t reserved[16]; // 预留字段,当前必须清零 | ||
| 263 | +} HcommCcuDieRes; | ||
| 264 | + | ||
| 265 | +// ascCustom 槽 0:获取 Channel Entity(返回 hcomm 持有的实体借用指针,调用方深拷贝后使用) | ||
| 266 | +typedef int32_t (*HcommCcuGetChannelEntityFn)(ChannelHandle channel, uint64_t* channelEntityPtr); | ||
| 267 | +// ascCustom 槽 1:申请 CCU 指令空间(从当前 Instance 的指令池切分) | ||
| 268 | +typedef int32_t (*HcommCcuAllocInstSpaceFn)( | ||
| 269 | + int32_t deviceLogicId, uint32_t dieId, uint32_t instNum, uint32_t* startInstId); | ||
| 270 | +// ascCustom 槽 2:下发 CCU 指令(data 为 host 指针,hcomm 负责拷入设备内存并经驱动下发) | ||
| 271 | +typedef int32_t (*HcommCcuSubmitInstsFn)( | ||
| 272 | + int32_t deviceLogicId, uint32_t dieId, uint32_t startInstructionId, const void* data, uint32_t instNum); | ||
| 273 | + | ||
| 274 | +/** | ||
| 275 | + * CCU Instance(Register Context):一次 Create 后快照的全部数据面所需信息。 | ||
| 276 | + * 资源按 die × 类型嵌套组织;指令空间不再走 range 视图,改由 ascCustom.allocInstSpace 按需申请。 | ||
| 277 | + * 不携带设备号(调用线程经 aclrtGetDevice 取)、die 启用位图(由 dieMetadata.enabled 推导)与 | ||
| 278 | + * 句柄代际(由 ccuInsKey 槽位代际承担);ccuVersion 为翻译器初始化所需的设备级版本(定稿 2026-09-10 修订:放 Instance | ||
| 279 | + * 顶层)。 ascCustom 为函数指针槽位数组(值按槽位含义强转对应 Fn 类型),由 hcomm 在创建时填充。 | ||
| 280 | + */ | ||
| 281 | +typedef struct HcommCcuInstance { | ||
| 282 | + CommAbiHeader header; // ABI 头:version/magic/size 校验 | ||
| 283 | + uint32_t ccuDieNum; // POD 中 die 槽位数(<= HCOMM_CCU_INSTANCE_DIE_CAPACITY) | ||
| 284 | + uint32_t ccuVersion; // 当前设备的 CCU 版本(V1/V2) | ||
| 285 | + HcommCcuDieRes ccuDieReses[HCOMM_CCU_INSTANCE_DIE_CAPACITY]; // 按 die 组织的资源视图(预留 8 槽) | ||
| 286 | + uint64_t | ||
| 287 | + ascCustom[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]; // 槽 0: 获取ChannelEntity接口;1:申请指令空间;2:下发指令;3-7 | ||
| 288 | + // 预留 | ||
| 289 | +} HcommCcuInstance; | ||
| 290 | + | ||
| 291 | +/** | ||
| 292 | + * @brief 查询 HCCL 通信域持有的 CCU Instance。 | ||
| 293 | + * @param[in] comm HCCL 通信域句柄,不可为 nullptr。 | ||
| 294 | + * @param[out] instance hcomm 持有的只读 CCU Instance 借用指针。 | ||
| 295 | + * @return HcclResult。 | ||
| 296 | + * @note instance 从通信域初始化成功后有效,到 HcclCommDestroy 开始销毁前失效; | ||
| 297 | + * RegisterStart 不得与通信域销毁并发,RegisterStart 返回前由 asc-comm 深拷贝。 | ||
| 298 | + */ | ||
| 299 | +extern HcclResult HcclCommQueryCcuRegisterContext(HcclComm comm, HcommCcuInstanceHandle* instance); | ||
| 300 | + | ||
| 301 | +#ifdef __cplusplus | ||
| 302 | +} // extern "C" | ||
| 303 | + | ||
| 304 | +#endif // __cplusplus | ||
| 305 | + | ||
| 306 | +#endif // HCOMM_CCU_RESOURCE_H | ||
| @@ -207,6 +207,7 @@ typedef enum { | |||
| 207 | COMM_MEM_TYPE_INVALID = -1, ///< 无效的内存类别 | 207 | COMM_MEM_TYPE_INVALID = -1, ///< 无效的内存类别 |
| 208 | COMM_MEM_TYPE_DEVICE = 0, ///< 设备侧内存(如NPU等) | 208 | COMM_MEM_TYPE_DEVICE = 0, ///< 设备侧内存(如NPU等) |
| 209 | COMM_MEM_TYPE_HOST = 1, ///< 主机侧内存 | 209 | COMM_MEM_TYPE_HOST = 1, ///< 主机侧内存 |
| 210 | + COMM_MEM_TYPE_CCU = 2, ///< CCU资源空间 | ||
| 210 | } CommMemType; | 211 | } CommMemType; |
| 211 | 212 | ||
| 212 | /** | 213 | /** |
| @@ -19,11 +19,31 @@ | |||
| 19 | extern "C" { | 19 | extern "C" { |
| 20 | #endif // __cplusplus | 20 | #endif // __cplusplus |
| 21 | 21 | ||
| 22 | +/* HcommTeam / HcommWindow 结构体的 ABI 头部常量 */ | ||
| 23 | +static const uint32_t HCOMM_TEAM_MAGIC_WORD = 0x0f0f0f20U; | ||
| 24 | +static const uint32_t HCOMM_TEAM_VERSION = 1U; | ||
| 25 | +static const uint32_t HCOMM_WINDOW_MAGIC_WORD = 0x0f0f0f21U; | ||
| 26 | +static const uint32_t HCOMM_WINDOW_VERSION = 2U; | ||
| 27 | + | ||
| 22 | typedef struct { | 28 | typedef struct { |
| 23 | CommAbiHeader header; | 29 | CommAbiHeader header; |
| 24 | - uint32_t memsNum; | 30 | + struct { |
| 25 | - CommMem* mems; // 长度是memsNum | 31 | + uint64_t baseRemoteMemAddr; /* 远端内存addr数组基地址,按(worldTeamAccumulateId[netLayer] + worldTeamId) * |
| 26 | - HcommTeamHandle worldTeam; // 该window所属的worldTeam,给数据面做校验 | 32 | + sizeof(uint64_t)偏移访问 */ |
| 33 | + uint64_t windowSize; /* window大小 */ | ||
| 34 | + uint32_t* worldTeamAccumulateId; /* 数组,表示sum(worldTeamSizePerNetLayer[0..netLayerNum-1]) */ | ||
| 35 | + uint32_t netLayerNum; /* netLayer的数量 */ | ||
| 36 | + uint32_t reserved[8]; | ||
| 37 | + } netWin; | ||
| 38 | + | ||
| 39 | + struct { | ||
| 40 | + uint64_t baseVa; | ||
| 41 | + uint64_t stride; | ||
| 42 | + uint64_t userSize; | ||
| 43 | + uint32_t reserved[8]; | ||
| 44 | + } lsaWin; | ||
| 45 | + | ||
| 46 | + uint64_t legacySymWindow; // SymmetricWindow结构体device侧指针 | ||
| 27 | uint32_t reserved[8]; | 47 | uint32_t reserved[8]; |
| 28 | } HcommWindow; | 48 | } HcommWindow; |
| 29 | 49 | ||
| @@ -44,10 +64,10 @@ typedef struct { | |||
| 44 | CommEngine engine; /* COMM_ENGINE_AICPU_TS / CCU 等 */ | 64 | CommEngine engine; /* COMM_ENGINE_AICPU_TS / CCU 等 */ |
| 45 | uint32_t memberNum; | 65 | uint32_t memberNum; |
| 46 | uint32_t selfMemberId; | 66 | uint32_t selfMemberId; |
| 47 | - uint64_t channelsBaseAddr; /* 连续ChannelEntity数组的基地址,按(sum(channelNumPerMember[0..peer-1]) + channelIdx) * | 67 | + uint64_t channelsBaseAddr; /* 连续ChannelEntity数组的基地址,按(channelCntAccumulatePerMember[peer] + channelIdx) * |
| 48 | sizeof(ChannelEntity)偏移访问 */ | 68 | sizeof(ChannelEntity)偏移访问 */ |
| 49 | - uint32_t* channelNumPerMember; /* 长度为memberNum,表示每个成员的channel数量 */ | 69 | + uint32_t* channelCntAccumulatePerMember; /* 长度为memberNum,表示sum(channelNumPerMember[0..peer-1]) */ |
| 50 | - uint32_t netLayer; /* 用户希望使用的网络层,0表示默认选择 */ | 70 | + uint32_t netLayer; /* 用户希望使用的网络层,0表示默认选择 */ |
| 51 | uint32_t* worldTeamIds; | 71 | uint32_t* worldTeamIds; |
| 52 | HcommTeamSyncMem syncMem; | 72 | HcommTeamSyncMem syncMem; |
| 53 | uint32_t reserved[8]; | 73 | uint32_t reserved[8]; |
| @@ -17,7 +17,7 @@ namespace asc { | |||
| 17 | 17 | ||
| 18 | #ifndef ASCCOMM_CCU_MAX_IODIE_NUM_DEFINED | 18 | #ifndef ASCCOMM_CCU_MAX_IODIE_NUM_DEFINED |
| 19 | #define ASCCOMM_CCU_MAX_IODIE_NUM_DEFINED | 19 | #define ASCCOMM_CCU_MAX_IODIE_NUM_DEFINED |
| 20 | -constexpr uint8_t ccu_max_iodie_num = 2; | 20 | +constexpr uint8_t CCU_MAX_IODIE_NUM = 2; |
| 21 | #endif | 21 | #endif |
| 22 | 22 | ||
| 23 | } // namespace asc | 23 | } // namespace asc |
| @@ -10,18 +10,29 @@ | |||
| 10 | 10 | ||
| 11 | #include "hcomm/common/ccu_device_context.h" | 11 | #include "hcomm/common/ccu_device_context.h" |
| 12 | 12 | ||
| 13 | +#include "acl/acl_rt.h" | ||
| 14 | + | ||
| 13 | namespace asc { | 15 | namespace asc { |
| 14 | namespace { | 16 | namespace { |
| 15 | -thread_local int32_t current_ccu_device_logic_id = -1; | 17 | +thread_local uint64_t current_ccu_control_ops[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]{}; |
| 16 | -thread_local HcommCcuControlOpsPod current_ccu_control_ops{}; | 18 | +} |
| 17 | -} // namespace | ||
| 18 | 19 | ||
| 19 | -void set_current_ccu_device_logic_id(int32_t device_logic_id) { current_ccu_device_logic_id = device_logic_id; } | 20 | +int32_t get_current_ccu_device_logic_id() |
| 21 | +{ | ||
| 22 | + int32_t device_logic_id = -1; | ||
| 23 | + if (aclrtGetDevice(&device_logic_id) != ACL_SUCCESS) { | ||
| 24 | + return -1; | ||
| 25 | + } | ||
| 26 | + return device_logic_id; | ||
| 27 | +} | ||
| 20 | 28 | ||
| 21 | -int32_t get_current_ccu_device_logic_id() { return current_ccu_device_logic_id; } | 29 | +void set_current_ccu_control_ops(const uint64_t (&asc_custom)[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]) |
| 30 | +{ | ||
| 31 | + for (uint32_t i = 0; i < HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT; ++i) { | ||
| 32 | + current_ccu_control_ops[i] = asc_custom[i]; | ||
| 33 | + } | ||
| 34 | +} | ||
| 22 | 35 | ||
| 23 | -void set_current_ccu_control_ops(const HcommCcuControlOpsPod& control_ops) { current_ccu_control_ops = control_ops; } | 36 | +const uint64_t* get_current_ccu_control_ops() { return current_ccu_control_ops; } |
| 24 | - | ||
| 25 | -const HcommCcuControlOpsPod& get_current_ccu_control_ops() { return current_ccu_control_ops; } | ||
| 26 | 37 | ||
| 27 | } // namespace asc | 38 | } // namespace asc |
| @@ -13,16 +13,20 @@ | |||
| 13 | 13 | ||
| 14 | #include <cstdint> | 14 | #include <cstdint> |
| 15 | 15 | ||
| 16 | -#include "hcomm/hcomm_ccu_control.h" | 16 | +#include "hcomm/hcomm_ccu_resource.h" |
| 17 | 17 | ||
| 18 | namespace asc { | 18 | namespace asc { |
| 19 | 19 | ||
| 20 | constexpr uint32_t ccu_max_device_num = 64; | 20 | constexpr uint32_t ccu_max_device_num = 64; |
| 21 | 21 | ||
| 22 | -void set_current_ccu_device_logic_id(int32_t device_logic_id); | 22 | +/** |
| 23 | + * 当前线程设备逻辑 id:直接取 runtime 的 aclrtGetDevice。 | ||
| 24 | + * 要求调用线程已设置设备(HCCL 数据面调用线程由上层保证);未设置时返回 -1,调用方按错误处理。 | ||
| 25 | + */ | ||
| 23 | int32_t get_current_ccu_device_logic_id(); | 26 | int32_t get_current_ccu_device_logic_id(); |
| 24 | -void set_current_ccu_control_ops(const HcommCcuControlOpsPod& control_ops); | 27 | +// ascCustom 槽位数组的线程级借用快照(值按槽位含义强转对应 Fn 类型使用) |
| 25 | -const HcommCcuControlOpsPod& get_current_ccu_control_ops(); | 28 | +void set_current_ccu_control_ops(const uint64_t (&asc_custom)[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]); |
| 29 | +const uint64_t* get_current_ccu_control_ops(); | ||
| 26 | 30 | ||
| 27 | } // namespace asc | 31 | } // namespace asc |
| 28 | 32 | ||
| @@ -29,35 +29,39 @@ | |||
| 29 | 29 | ||
| 30 | #include "hcomm/resource/microcode/ccu_assist_v1.h" | 30 | #include "hcomm/resource/microcode/ccu_assist_v1.h" |
| 31 | 31 | ||
| 32 | -CcuResult asccomm_ccu_kernel_register_start(CcuInsHandle ins_handle, HcommCcuRegisterContextHandle context_handle) | 32 | +CcuResult asccomm_ccu_kernel_register_start(CcuInsHandle ins_handle) |
| 33 | { | 33 | { |
| 34 | - CCU_CHK_PTR_NULL(context_handle); | 34 | + if (ins_handle.ccuInsKey == 0 || ins_handle.ccuInsPtr == nullptr) { |
| 35 | - const auto* context = reinterpret_cast<const HcommCcuRegisterContextPod*>(context_handle); | ||
| 36 | - if (context->instanceHandle != 0 && context->instanceHandle != ins_handle) { | ||
| 37 | HCCL_ERROR( | 35 | HCCL_ERROR( |
| 38 | - "[%s] failed, context instanceHandle[%llu] mismatches input insHandle[%llu].", __func__, | 36 | + "[%s] failed, invalid instance handle: key[%llx], pod[%p].", __func__, |
| 39 | - static_cast<unsigned long long>(context->instanceHandle), static_cast<unsigned long long>(ins_handle)); | 37 | + static_cast<unsigned long long>(ins_handle.ccuInsKey), static_cast<const void*>(ins_handle.ccuInsPtr)); |
| 40 | return CcuResult::CCU_E_PARA; | 38 | return CcuResult::CCU_E_PARA; |
| 41 | } | 39 | } |
| 40 | + const auto* instance = ins_handle.ccuInsPtr; | ||
| 41 | + // Instance 不再携带设备号:以当前线程设备定位 per-device registry/kernel mgr | ||
| 42 | + const int32_t dev_logic_id = asc::get_current_ccu_device_logic_id(); | ||
| 43 | + if (dev_logic_id < 0) { | ||
| 44 | + HCCL_ERROR("[%s] failed, current thread has no device set.", __func__); | ||
| 45 | + return CcuResult::CCU_E_UNAVAIL; | ||
| 46 | + } | ||
| 42 | asc::ccu_kernel_registry* ccu_ins = nullptr; | 47 | asc::ccu_kernel_registry* ccu_ins = nullptr; |
| 43 | - CCU_CHK_RET(asc::ccu_kernel_registry_mgr::get_instance(context->deviceLogicId) | 48 | + CCU_CHK_RET( |
| 44 | - .get_or_create(context->deviceLogicId, ins_handle, ccu_ins)); | 49 | + asc::ccu_kernel_registry_mgr::get_instance(dev_logic_id).get_or_create(dev_logic_id, ins_handle, ccu_ins)); |
| 45 | CCU_CHK_PTR_NULL(ccu_ins); | 50 | CCU_CHK_PTR_NULL(ccu_ins); |
| 46 | CCU_CHK_RET(ccu_ins->begin_register()); | 51 | CCU_CHK_RET(ccu_ins->begin_register()); |
| 47 | 52 | ||
| 48 | - CcuResult ret = ccu_ins->load_register_context(*context); | 53 | + CcuResult ret = ccu_ins->load_register_context(*instance); |
| 49 | if (ret == CcuResult::CCU_SUCCESS) { | 54 | if (ret == CcuResult::CCU_SUCCESS) { |
| 50 | auto* res_snapshot = ccu_ins->get_res_snapshot(); | 55 | auto* res_snapshot = ccu_ins->get_res_snapshot(); |
| 51 | CCU_CHK_PTR_NULL(res_snapshot); | 56 | CCU_CHK_PTR_NULL(res_snapshot); |
| 52 | - ret = asc::ccu_kernel_mgr::get_instance(context->deviceLogicId).configure(*res_snapshot); | 57 | + ret = asc::ccu_kernel_mgr::get_instance(dev_logic_id).configure(*res_snapshot); |
| 53 | } | 58 | } |
| 54 | if (ret != CcuResult::CCU_SUCCESS) { | 59 | if (ret != CcuResult::CCU_SUCCESS) { |
| 55 | (void)ccu_ins->end_register(); | 60 | (void)ccu_ins->end_register(); |
| 56 | HCCL_ERROR("[%s] failed to load register context, ret[%d].", __func__, ret); | 61 | HCCL_ERROR("[%s] failed to load register context, ret[%d].", __func__, ret); |
| 57 | return ret; | 62 | return ret; |
| 58 | } | 63 | } |
| 59 | - asc::set_current_ccu_device_logic_id(context->deviceLogicId); | 64 | + asc::set_current_ccu_control_ops(instance->ascCustom); |
| 60 | - asc::set_current_ccu_control_ops(ccu_ins->get_res_snapshot()->get_control_ops()); | ||
| 61 | return CcuResult::CCU_SUCCESS; | 65 | return CcuResult::CCU_SUCCESS; |
| 62 | } | 66 | } |
| 63 | 67 | ||
| @@ -11,7 +11,7 @@ | |||
| 11 | // 数据面 primitive C ABI 实现入口。 | 11 | // 数据面 primitive C ABI 实现入口。 |
| 12 | // 头部统一走 hcomm 包内 header(asccomm_ccu_channel.h / hcomm_types.h), | 12 | // 头部统一走 hcomm 包内 header(asccomm_ccu_channel.h / hcomm_types.h), |
| 13 | // 不再 include hccl 私有头,从源码层面落实控制面/数据面边界。 | 13 | // 不再 include hccl 私有头,从源码层面落实控制面/数据面边界。 |
| 14 | -#include "hcomm/hcomm_ccu_channel.h" | 14 | +#include "hcomm/hcomm_ccu_resource.h" |
| 15 | #include "hcomm/hcomm_types.h" | 15 | #include "hcomm/hcomm_types.h" |
| 16 | #include "ccu/hcomm/ccu_primitives_impl.h" | 16 | #include "ccu/hcomm/ccu_primitives_impl.h" |
| 17 | 17 | ||
| @@ -24,32 +24,40 @@ const ccu_channel* ccu_channel::operator->() const { return this; } | |||
| 24 | 24 | ||
| 25 | HcclResult ccu_channel::init(ChannelHandle channel) | 25 | HcclResult ccu_channel::init(ChannelHandle channel) |
| 26 | { | 26 | { |
| 27 | - // 组装带 ABI 头的查询 POD,通知 hcomm 按当前 ABI 版本填写快照 | 27 | + // getChannelEntity 返回 hcomm 持有的 Channel Entity 借用指针(不透明 uint64_t 地址) |
| 28 | - HcommCcuChannelPod query_pod{}; | 28 | + uint64_t channel_entity_addr = 0; |
| 29 | - query_pod.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; | 29 | + const auto channel_query = reinterpret_cast<HcommCcuGetChannelEntityFn>( |
| 30 | - query_pod.header.magicWord = HCOMM_CCU_CHANNEL_POD_MAGIC_WORD; | 30 | + get_current_ccu_control_ops()[HCOMM_CCU_ASC_CUSTOM_CHANNEL_ENTITY]); |
| 31 | - query_pod.header.size = sizeof(HcommCcuChannelPod); | ||
| 32 | - | ||
| 33 | - // 通过控制面注入的函数表发起单次查询(不再分两阶段传数组地址) | ||
| 34 | - const auto channel_query = get_current_ccu_control_ops().channelQuery; | ||
| 35 | if (channel_query == nullptr) { | 31 | if (channel_query == nullptr) { |
| 36 | return HCCL_E_INTERNAL; | 32 | return HCCL_E_INTERNAL; |
| 37 | } | 33 | } |
| 38 | - int32_t ret = channel_query(channel, &query_pod); | 34 | + int32_t ret = channel_query(channel, &channel_entity_addr); |
| 39 | if (ret != HCCL_SUCCESS) { | 35 | if (ret != HCCL_SUCCESS) { |
| 40 | return static_cast<HcclResult>(ret); | 36 | return static_cast<HcclResult>(ret); |
| 41 | } | 37 | } |
| 42 | - // 远端 CCU buffer 尚未就绪时拒绝使用该 Channel | 38 | + if (channel_entity_addr == 0) { |
| 43 | - if (query_pod.rmtCcuBufSize == 0) { | ||
| 44 | return HCCL_E_INTERNAL; | 39 | return HCCL_E_INTERNAL; |
| 45 | } | 40 | } |
| 46 | - // 快照整体拷贝到本地,后续算法只读这份 POD,不再触碰 hcomm 对象 | 41 | + // 借用期内深拷贝快照,此后不再触碰 hcomm 内存 |
| 47 | - channel_pod_ = query_pod; | 42 | + const auto* entity = reinterpret_cast<const HcommCcuChannelEntity*>(channel_entity_addr); |
| 43 | + // ABI 头校验:实体必须是当前版本布局 | ||
| 44 | + if (entity->header.version != HCOMM_CCU_CHANNEL_ABI_VERSION || | ||
| 45 | + entity->header.magicWord != HCOMM_CCU_CHANNEL_MAGIC_WORD || | ||
| 46 | + entity->header.size != sizeof(HcommCcuChannelEntity)) { | ||
| 47 | + return HCCL_E_INTERNAL; | ||
| 48 | + } | ||
| 49 | + // 远端 CCU 资源空间尚未就绪时拒绝使用该 Channel(定档:RegedBufferEntity 口径) | ||
| 50 | + if (entity->rmtCcuResBuffer.type != REGED_BUFFER_RMA || entity->rmtCcuResBuffer.bufferInfo.rma.addr == 0 || | ||
| 51 | + entity->rmtCcuResBuffer.bufferInfo.rma.size == 0) { | ||
| 52 | + return HCCL_E_INTERNAL; | ||
| 53 | + } | ||
| 54 | + // 快照整体拷贝到本地,后续算法只读这份实体,不再触碰 hcomm 对象 | ||
| 55 | + channel_entity_ = *entity; | ||
| 48 | return HCCL_SUCCESS; | 56 | return HCCL_SUCCESS; |
| 49 | } | 57 | } |
| 50 | 58 | ||
| 51 | -// 从 POD 定长数组取第 index 个资源 id:先校验快照查询结果,再校验数组与下标 | 59 | +// 从实体数组取第 index 个资源 id:先校验快照查询结果,再按有效数量(而非定长容量)校验下标 |
| 52 | -HcclResult ccu_channel::get_id_by_array(const uint32_t* ids, uint32_t index, uint32_t& id) const | 60 | +HcclResult ccu_channel::get_id_by_array(const uint32_t* ids, uint32_t valid_num, uint32_t index, uint32_t& id) const |
| 53 | { | 61 | { |
| 54 | if (result_ != HCCL_SUCCESS) { | 62 | if (result_ != HCCL_SUCCESS) { |
| 55 | return result_; | 63 | return result_; |
| @@ -57,7 +65,7 @@ HcclResult ccu_channel::get_id_by_array(const uint32_t* ids, uint32_t index, uin | |||
| 57 | if (ids == nullptr) { | 65 | if (ids == nullptr) { |
| 58 | return HCCL_E_PTR; | 66 | return HCCL_E_PTR; |
| 59 | } | 67 | } |
| 60 | - if (index >= HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY) { | 68 | + if (index >= valid_num) { |
HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY为什么要删除 ![]() ![]() | |||
| 61 | return HCCL_E_PARA; | 69 | return HCCL_E_PARA; |
| 62 | } | 70 | } |
| 63 | id = ids[index]; | 71 | id = ids[index]; |
| @@ -66,28 +74,28 @@ HcclResult ccu_channel::get_id_by_array(const uint32_t* ids, uint32_t index, uin | |||
| 66 | 74 | ||
| 67 | HcclResult ccu_channel::get_result() const { return result_; } | 75 | HcclResult ccu_channel::get_result() const { return result_; } |
| 68 | 76 | ||
| 69 | -uint32_t ccu_channel::get_die_id() const { return channel_pod_.dieId; } | 77 | +uint32_t ccu_channel::get_die_id() const { return channel_entity_.dieId; } |
| 70 | 78 | ||
| 71 | -uint32_t ccu_channel::get_channel_id() const { return channel_pod_.channelId; } | 79 | +uint32_t ccu_channel::get_channel_id() const { return channel_entity_.channelId; } |
| 72 | 80 | ||
| 73 | HcclResult ccu_channel::get_loc_cke_by_index(uint32_t index, uint32_t& local_cke_id) const | 81 | HcclResult ccu_channel::get_loc_cke_by_index(uint32_t index, uint32_t& local_cke_id) const |
| 74 | { | 82 | { |
| 75 | - return get_id_by_array(channel_pod_.localCkeIds, index, local_cke_id); | 83 | + return get_id_by_array(channel_entity_.localEventIds, channel_entity_.localEventNum, index, local_cke_id); |
| 76 | } | 84 | } |
| 77 | 85 | ||
| 78 | HcclResult ccu_channel::get_loc_xn_by_index(uint32_t index, uint32_t& local_xn_id) const | 86 | HcclResult ccu_channel::get_loc_xn_by_index(uint32_t index, uint32_t& local_xn_id) const |
| 79 | { | 87 | { |
| 80 | - return get_id_by_array(channel_pod_.localXnIds, index, local_xn_id); | 88 | + return get_id_by_array(channel_entity_.localVarIds, channel_entity_.localVarNum, index, local_xn_id); |
| 81 | } | 89 | } |
| 82 | 90 | ||
| 83 | HcclResult ccu_channel::get_rmt_cke_by_index(uint32_t index, uint32_t& remote_cke_id) const | 91 | HcclResult ccu_channel::get_rmt_cke_by_index(uint32_t index, uint32_t& remote_cke_id) const |
| 84 | { | 92 | { |
| 85 | - return get_id_by_array(channel_pod_.remoteCkeIds, index, remote_cke_id); | 93 | + return get_id_by_array(channel_entity_.remoteEventIds, channel_entity_.remoteEventNum, index, remote_cke_id); |
| 86 | } | 94 | } |
| 87 | 95 | ||
| 88 | HcclResult ccu_channel::get_rmt_xn_by_index(uint32_t index, uint32_t& remote_xn_id) const | 96 | HcclResult ccu_channel::get_rmt_xn_by_index(uint32_t index, uint32_t& remote_xn_id) const |
| 89 | { | 97 | { |
| 90 | - return get_id_by_array(channel_pod_.remoteXnIds, index, remote_xn_id); | 98 | + return get_id_by_array(channel_entity_.remoteVarIds, channel_entity_.remoteVarNum, index, remote_xn_id); |
| 91 | } | 99 | } |
| 92 | 100 | ||
| 93 | HcclResult ccu_channel::get_rmt_buffer(uint64_t& addr, uint32_t& size, uint32_t& token_id, uint32_t& token_value) const | 101 | HcclResult ccu_channel::get_rmt_buffer(uint64_t& addr, uint32_t& size, uint32_t& token_id, uint32_t& token_value) const |
| @@ -95,11 +103,11 @@ HcclResult ccu_channel::get_rmt_buffer(uint64_t& addr, uint32_t& size, uint32_t& | |||
| 95 | if (result_ != HCCL_SUCCESS) { | 103 | if (result_ != HCCL_SUCCESS) { |
| 96 | return result_; | 104 | return result_; |
| 97 | } | 105 | } |
| 98 | - // 远端 CCU 资源 buffer 的基址、长度与 token 已由 hcomm 在快照中按设备规格算好,这里直接返回 | 106 | + // 远端 CCU 资源空间的基址、长度与 token 已由 hcomm 装配为 RegedBufferEntity,这里拆解返回 |
| 99 | - addr = channel_pod_.rmtCcuBufAddr; | 107 | + addr = channel_entity_.rmtCcuResBuffer.bufferInfo.rma.addr; |
| 100 | - size = channel_pod_.rmtCcuBufSize; | 108 | + size = static_cast<uint32_t>(channel_entity_.rmtCcuResBuffer.bufferInfo.rma.size); |
| 101 | - token_id = channel_pod_.rmtCcuBufTokenId; | 109 | + token_id = channel_entity_.rmtCcuResBuffer.bufferInfo.rma.protectionInfo.memInfo.ub.tokenId; |
| 102 | - token_value = channel_pod_.rmtCcuBufTokenValue; | 110 | + token_value = channel_entity_.rmtCcuResBuffer.bufferInfo.rma.protectionInfo.memInfo.ub.tokenValue; |
| 103 | return HCCL_SUCCESS; | 111 | return HCCL_SUCCESS; |
| 104 | } | 112 | } |
| 105 | 113 | ||
| @@ -13,13 +13,13 @@ | |||
| 13 | 13 | ||
| 14 | #include <cstdint> | 14 | #include <cstdint> |
| 15 | 15 | ||
| 16 | -#include "hcomm/hcomm_ccu_control.h" | 16 | +#include "hcomm/hcomm_ccu_resource.h" |
| 17 | #include "hcomm/hcomm_types.h" | 17 | #include "hcomm/hcomm_types.h" |
| 18 | 18 | ||
| 19 | namespace asc { | 19 | namespace asc { |
| 20 | 20 | ||
| 21 | // CcuChannel:CCU Channel 在 asc-comm 数据面侧的本地值对象。 | 21 | // CcuChannel:CCU Channel 在 asc-comm 数据面侧的本地值对象。 |
| 22 | -// 构造时通过 hcomm 注入的 channelQuery 一次性获取定长 POD 快照(HcommCcuChannelPod), | 22 | +// 构造时通过 hcomm 注入的 channelQuery 一次性获取定长实体快照(HcommCcuChannelEntity), |
| 23 | // 之后所有资源访问均基于该本地快照,不再触碰 hcomm 的 Channel 对象。 | 23 | // 之后所有资源访问均基于该本地快照,不再触碰 hcomm 的 Channel 对象。 |
| 24 | // 该对象被设计为不可拷贝的包装语义:operator-> 直接解引用自身(保留迁移前 channel->GetXxx() 的调用形式)。 | 24 | // 该对象被设计为不可拷贝的包装语义:operator-> 直接解引用自身(保留迁移前 channel->GetXxx() 的调用形式)。 |
| 25 | class ccu_channel { | 25 | class ccu_channel { |
| @@ -41,11 +41,11 @@ public: | |||
| 41 | 41 | ||
| 42 | private: | 42 | private: |
| 43 | HcclResult init(ChannelHandle channel); | 43 | HcclResult init(ChannelHandle channel); |
| 44 | - // 从 POD 定长数组安全读取第 index 个资源 id(含空指针/越界校验) | 44 | + // 从实体定长数组安全读取第 index 个资源 id(含空指针/越界校验) |
| 45 | - HcclResult get_id_by_array(const uint32_t* ids, uint32_t index, uint32_t& id) const; | 45 | + HcclResult get_id_by_array(const uint32_t* ids, uint32_t valid_num, uint32_t index, uint32_t& id) const; |
| 46 | 46 | ||
| 47 | - // 单次查询得到的完整 POD 快照;不再持有变长容器,CcuChannel 生命周期与 hcomm 完全解耦 | 47 | + // 单次查询得到的完整实体快照;不再持有变长容器,CcuChannel 生命周期与 hcomm 完全解耦 |
| 48 | - HcommCcuChannelPod channel_pod_{}; | 48 | + HcommCcuChannelEntity channel_entity_{}; |
| 49 | // Init 的结果缓存,初始为内部错误,避免未初始化即被使用 | 49 | // Init 的结果缓存,初始为内部错误,避免未初始化即被使用 |
| 50 | HcclResult result_{HCCL_E_INTERNAL}; | 50 | HcclResult result_{HCCL_E_INTERNAL}; |
| 51 | }; | 51 | }; |
| @@ -9,16 +9,15 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | #include "hcomm/resource/common/asc_ccu_res_snapshot.h" | 11 | #include "hcomm/resource/common/asc_ccu_res_snapshot.h" |
| 12 | +#include "hcomm/common/ccu_log.h" | ||
| 12 | 13 | ||
| 13 | #include <algorithm> | 14 | #include <algorithm> |
| 14 | #include <limits> | 15 | #include <limits> |
| 15 | -#include <vector> | ||
| 16 | 16 | ||
| 17 | namespace asc { | 17 | namespace asc { |
| 18 | namespace { | 18 | namespace { |
| 19 | 19 | ||
| 20 | -std::vector<HcommCcuResRangePod>* get_ranges( | 20 | +std::vector<asc_ccu_res_range>* get_ranges(asc_ccu_res_repository& repository, uint32_t resource_type, uint32_t die_id) |
公共类型是大驼峰、内部snake ![]() ![]() | |||
| 21 | - asc_ccu_res_repository& repository, uint32_t resource_type, uint32_t die_id) | ||
| 22 | { | 21 | { |
| 23 | switch (resource_type) { | 22 | switch (resource_type) { |
| 24 | case HCOMM_CCU_BATCH_RES_LOOP: | 23 | case HCOMM_CCU_BATCH_RES_LOOP: |
| @@ -43,133 +42,168 @@ std::vector<HcommCcuResRangePod>* get_ranges( | |||
| 43 | return &repository.block_gsa[die_id]; | 42 | return &repository.block_gsa[die_id]; |
| 44 | case HCOMM_CCU_BATCH_RES_MISSION: | 43 | case HCOMM_CCU_BATCH_RES_MISSION: |
| 45 | return &repository.mission[die_id]; | 44 | return &repository.mission[die_id]; |
| 46 | - case HCOMM_CCU_RES_INSTRUCTION: | ||
| 47 | - return &repository.instruction[die_id]; | ||
| 48 | default: | 45 | default: |
| 49 | - return nullptr; | 46 | + return nullptr; // INS 不走 range 视图,由 ascCustom.allocInstSpace 按需申请 |
| 50 | } | 47 | } |
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | -bool is_header_valid(const HcommCcuRegisterContextPod& context) | 50 | +bool is_instance_header_valid(const HcommCcuInstance& instance) |
| 54 | { | 51 | { |
| 55 | - return context.header.version == HCOMM_CCU_RES_ABI_VERSION && | 52 | + return instance.header.version == HCOMM_CCU_RES_ABI_VERSION && |
| 56 | - context.header.magicWord == HCOMM_CCU_REGISTER_CONTEXT_MAGIC_WORD && | 53 | + instance.header.magicWord == HCOMM_CCU_INSTANCE_MAGIC_WORD && |
| 57 | - context.header.size == sizeof(HcommCcuRegisterContextPod) && context.header.reserved == 0; | 54 | + instance.header.size == sizeof(HcommCcuInstance) && instance.header.reserved == 0; |
| 58 | } | 55 | } |
| 59 | 56 | ||
| 60 | -bool is_view_shape_valid(const HcommCcuResRangeViewPod& view) | 57 | +bool is_die_metadata_valid(const HcommCcuDieMetadata& metadata) |
| 61 | { | 58 | { |
| 62 | - return view.reserved == 0 && (view.count == 0 || view.ranges != nullptr); | 59 | + return metadata.header.version == HCOMM_CCU_RES_ABI_VERSION && |
| 60 | + metadata.header.magicWord == HCOMM_CCU_DIE_METADATA_MAGIC_WORD && | ||
| 61 | + metadata.header.size == sizeof(HcommCcuDieMetadata) && metadata.header.reserved == 0 && | ||
| 62 | + metadata.reserved == 0; | ||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | -bool is_control_ops_valid(const HcommCcuControlOpsPod& ops) | 65 | +// 从 die 元数据推导有效 die 位图 |
| 66 | +uint32_t derive_valid_die_mask(const HcommCcuInstance& instance) | ||
退回至单die,看下在哪调用 ![]() ![]() | |||
| 66 | { | 67 | { |
| 67 | - return ops.header.version == HCOMM_CCU_CONTROL_ABI_VERSION && | 68 | + uint32_t mask = 0; |
| 68 | - ops.header.magicWord == HCOMM_CCU_CONTROL_OPS_MAGIC_WORD && | 69 | + for (uint32_t slot = 0; slot < instance.ccuDieNum && slot < HCOMM_CCU_INSTANCE_DIE_CAPACITY; ++slot) { |
| 69 | - ops.header.size == sizeof(HcommCcuControlOpsPod) && ops.header.reserved == 0 && | 70 | + const HcommCcuDieMetadata* metadata = instance.ccuDieReses[slot].dieMetadata; |
| 70 | - ops.channelQuery != nullptr && ops.loadInstruction != nullptr && ops.missionContextQuery != nullptr && | 71 | + if (metadata != nullptr && metadata->enabled != 0) { |
| 71 | - ops.loopContextQuery != nullptr && ops.ckeQuery != nullptr && ops.xnQuery != nullptr && | 72 | + mask |= 1U << slot; |
| 72 | - ops.gsaQuery != nullptr && ops.reserved == 0; | 73 | + } |
| 74 | + } | ||
| 75 | + return mask; | ||
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | -bool is_disabled_die_metadata_valid(const HcommCcuDieMetadataPod& metadata) | 78 | +// ascCustom 校验:槽 0-2 (ChannelEntity/AllocInstSpace/SubmitInsts) |
| 79 | +bool is_asc_custom_valid(const uint64_t (&asc_custom)[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]) | ||
| 76 | { | 80 | { |
| 77 | - return metadata.enabled == 0 && metadata.missionKey == 0 && metadata.innerDieLoopChannelId == 0 && | 81 | + return asc_custom[HCOMM_CCU_ASC_CUSTOM_CHANNEL_ENTITY] != 0 && |
| 78 | - metadata.interDieLoopChannelId == 0 && metadata.xnBaseAddr == 0 && metadata.resourceSpaceTokenId == 0 && | 82 | + asc_custom[HCOMM_CCU_ASC_CUSTOM_ALLOC_INST_SPACE] != 0 && asc_custom[HCOMM_CCU_ASC_CUSTOM_SUBMIT_INSTS] != 0; |
| 79 | - metadata.resourceSpaceTokenValue == 0 && metadata.instructionCapacity == 0 && metadata.reserved == 0; | ||
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | -bool ranges_overlap(const HcommCcuResRangePod& left, const HcommCcuResRangePod& right) | 85 | +bool ranges_overlap(const asc_ccu_res_range& left, const asc_ccu_res_range& right) |
| 83 | { | 86 | { |
| 84 | - if (left.resourceType != right.resourceType || left.dieId != right.dieId) { | 87 | + if (left.resource_type != right.resource_type || left.die_id != right.die_id) { |
| 85 | return false; | 88 | return false; |
| 86 | } | 89 | } |
| 87 | - const uint64_t left_end = static_cast<uint64_t>(left.startId) + left.count; | 90 | + const uint64_t left_end = static_cast<uint64_t>(left.start_id) + left.count; |
| 88 | - const uint64_t right_end = static_cast<uint64_t>(right.startId) + right.count; | 91 | + const uint64_t right_end = static_cast<uint64_t>(right.start_id) + right.count; |
| 89 | - return static_cast<uint64_t>(left.startId) < right_end && static_cast<uint64_t>(right.startId) < left_end; | 92 | + return static_cast<uint64_t>(left.start_id) < right_end && static_cast<uint64_t>(right.start_id) < left_end; |
| 90 | } | 93 | } |
| 91 | 94 | ||
| 92 | -CcuResult validate_and_append( | 95 | +// 把一段 wire range(类型与 die 来自外层索引)追加进本地仓储,并做形状与重叠校验 |
| 93 | - const HcommCcuResRangeViewPod& view, uint32_t valid_die_mask, std::vector<HcommCcuResRangePod>& all_ranges, | 96 | +CcuResult append_wire_ranges( |
| 94 | - asc_ccu_res_repository& repository) | 97 | + const HcommCcuResRanges& type_view, uint32_t resource_type, uint32_t die_id, uint32_t valid_die_mask, |
| 98 | + std::vector<asc_ccu_res_range>& all_ranges, asc_ccu_res_repository& repository) | ||
| 95 | { | 99 | { |
| 96 | - if (!is_view_shape_valid(view)) { | 100 | + if (type_view.resourceType != resource_type || type_view.reserved != 0) { |
| 97 | return CcuResult::CCU_E_PARA; | 101 | return CcuResult::CCU_E_PARA; |
| 98 | } | 102 | } |
| 99 | - for (uint32_t index = 0; index < view.count; ++index) { | 103 | + if (type_view.resRangeNum > 0 && type_view.resRanges == nullptr) { |
| 100 | - const HcommCcuResRangePod& range = view.ranges[index]; | 104 | + return CcuResult::CCU_E_PARA; |
| 101 | - if (range.dieId >= HCOMM_CCU_MAX_DIE_NUM || (valid_die_mask & (1U << range.dieId)) == 0 || range.count == 0 || | 105 | + } |
| 106 | + for (uint32_t index = 0; index < type_view.resRangeNum; ++index) { | ||
| 107 | + const HcommCcuResRange& range = type_view.resRanges[index]; | ||
| 108 | + if (range.reserved != 0 || (valid_die_mask & (1U << die_id)) == 0 || range.count == 0 || | ||
| 102 | static_cast<uint64_t>(range.startId) + range.count > | 109 | static_cast<uint64_t>(range.startId) + range.count > |
| 103 | static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1U) { | 110 | static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1U) { |
| 104 | return CcuResult::CCU_E_PARA; | 111 | return CcuResult::CCU_E_PARA; |
| 105 | } | 112 | } |
| 106 | - if (range.resourceType > HCOMM_CCU_RES_INSTRUCTION) { | 113 | + asc_ccu_res_range local{resource_type, die_id, range.startId, range.count}; |
| 107 | - return CcuResult::CCU_E_PARA; | ||
| 108 | - } | ||
| 109 | for (const auto& existing : all_ranges) { | 114 | for (const auto& existing : all_ranges) { |
| 110 | - if (ranges_overlap(existing, range)) { | 115 | + if (ranges_overlap(existing, local)) { |
| 111 | return CcuResult::CCU_E_PARA; | 116 | return CcuResult::CCU_E_PARA; |
| 112 | } | 117 | } |
| 113 | } | 118 | } |
| 114 | - all_ranges.push_back(range); | 119 | + all_ranges.push_back(local); |
| 115 | - auto* destination = get_ranges(repository, range.resourceType, range.dieId); | 120 | + auto* destination = get_ranges(repository, resource_type, die_id); |
| 116 | if (destination == nullptr) { | 121 | if (destination == nullptr) { |
| 117 | return CcuResult::CCU_E_PARA; | 122 | return CcuResult::CCU_E_PARA; |
| 118 | } | 123 | } |
| 119 | - destination->push_back(range); | 124 | + destination->push_back(local); |
| 120 | } | 125 | } |
| 121 | return CcuResult::CCU_SUCCESS; | 126 | return CcuResult::CCU_SUCCESS; |
| 122 | } | 127 | } |
| 123 | - | ||
| 124 | } // namespace | 128 | } // namespace |
| 125 | 129 | ||
| 126 | -CcuResult asc_ccu_res_snapshot::load(const HcommCcuRegisterContextPod& context) | 130 | +CcuResult asc_ccu_res_snapshot::load(const HcommCcuInstance& instance) |
回退至单die ![]() ![]() | |||
| 127 | { | 131 | { |
| 128 | - if (!is_header_valid(context) || context.generation == 0 || context.deviceLogicId < 0 || context.ccuVersion > 1 || | 132 | + if (!is_instance_header_valid(instance) || instance.ccuDieNum > HCOMM_CCU_INSTANCE_DIE_CAPACITY || |
| 129 | - context.dieNum != HCOMM_CCU_MAX_DIE_NUM || context.validDieMask == 0 || | 133 | + instance.ccuDieNum != HCOMM_CCU_MAX_DIE_NUM || // 现网 2 die;硬件扩展后放开 |
| 130 | - (context.validDieMask & ~((1U << HCOMM_CCU_MAX_DIE_NUM) - 1U)) != 0 || context.reserved[0] != 0 || | 134 | + instance.ccuVersion > HCOMM_CCU_VERSION_V2 || !is_asc_custom_valid(instance.ascCustom)) { |
| 131 | - context.reserved[1] != 0 || !is_control_ops_valid(context.controlOps) || | ||
| 132 | - !is_view_shape_valid(context.instanceResources)) { | ||
| 133 | - return CcuResult::CCU_E_PARA; | ||
| 134 | - } | ||
| 135 | - if (generation_ != 0 && generation_ != context.generation) { | ||
| 136 | return CcuResult::CCU_E_PARA; | 135 | return CcuResult::CCU_E_PARA; |
| 137 | } | 136 | } |
| 138 | 137 | ||
| 139 | asc_ccu_res_repository instance_snapshot{}; | 138 | asc_ccu_res_repository instance_snapshot{}; |
| 140 | - std::vector<HcommCcuResRangePod> all_ranges; | 139 | + std::vector<asc_ccu_res_range> all_ranges{}; |
| 141 | - all_ranges.reserve(context.instanceResources.count); | 140 | + std::array<HcommCcuDieMetadata, HCOMM_CCU_MAX_DIE_NUM> die_metadata{}; |
| 142 | 141 | ||
| 143 | - CcuResult ret = validate_and_append(context.instanceResources, context.validDieMask, all_ranges, instance_snapshot); | 142 | + // 先按 dieId 顺序装载各 die;有效位图从 dieMetadata.enabled 推导 |
| 144 | - if (ret != CcuResult::CCU_SUCCESS) { | 143 | + uint32_t derived_die_mask = 0; |
| 145 | - return ret; | 144 | + for (uint32_t slot = 0; slot < HCOMM_CCU_INSTANCE_DIE_CAPACITY; ++slot) { |
| 145 | + const HcommCcuDieRes& die_res = instance.ccuDieReses[slot]; | ||
| 146 | + if (slot < instance.ccuDieNum) { | ||
| 147 | + if (die_res.dieId != slot) { | ||
| 148 | + return CcuResult::CCU_E_PARA; | ||
| 149 | + } | ||
| 150 | + // 两遍装载:第一遍取元数据(enabled 决定位图),第二遍按位图校验 range 视图 | ||
| 151 | + if (die_res.dieMetadata == nullptr) { | ||
| 152 | + // 未启用 die:视图必须为空 | ||
| 153 | + if (die_res.resTypeNum != 0) { | ||
| 154 | + return CcuResult::CCU_E_PARA; | ||
| 155 | + } | ||
| 156 | + continue; | ||
| 157 | + } | ||
| 158 | + if (!is_die_metadata_valid(*die_res.dieMetadata) || die_res.dieMetadata->enabled > 1) { | ||
| 159 | + return CcuResult::CCU_E_PARA; | ||
| 160 | + } | ||
| 161 | + die_metadata[slot] = *die_res.dieMetadata; // 深拷贝元数据,此后不再触碰 hcomm 内存 | ||
| 162 | + if (die_metadata[slot].enabled != 0) { | ||
| 163 | + derived_die_mask |= 1U << slot; | ||
| 164 | + } | ||
| 165 | + } else if ( | ||
| 166 | + die_res.dieId != 0 || die_res.resTypeNum != 0 || die_res.dieMetadata != nullptr || | ||
| 167 | + std::any_of(die_res.reserved, die_res.reserved + 16, [](uint64_t field) { return field != 0; })) { | ||
| 168 | + // 超出 ccuDieNum 的预留槽位必须整体为零 | ||
| 169 | + return CcuResult::CCU_E_PARA; | ||
| 170 | + } | ||
| 146 | } | 171 | } |
| 147 | - | 172 | + if (derived_die_mask == 0 || (derived_die_mask & ~((1U << HCOMM_CCU_MAX_DIE_NUM) - 1U)) != 0) { |
| 148 | - for (uint32_t die_id = 0; die_id < HCOMM_CCU_MAX_DIE_NUM; ++die_id) { | 173 | + return CcuResult::CCU_E_PARA; |
| 149 | - const bool enabled = (context.validDieMask & (1U << die_id)) != 0; | 174 | + } |
| 150 | - const HcommCcuDieMetadataPod& metadata = context.die[die_id]; | 175 | + // 第二遍:按推导位图校验并装载 range(启用 die 必须有元数据;未启用 die 不得携带元数据) |
| 151 | - if (metadata.enabled > 1 || (metadata.enabled != 0) != enabled || metadata.reserved != 0 || | 176 | + for (uint32_t slot = 0; slot < instance.ccuDieNum; ++slot) { |
| 152 | - (!enabled && !is_disabled_die_metadata_valid(metadata))) { | 177 | + const HcommCcuDieRes& die_res = instance.ccuDieReses[slot]; |
| 178 | + const bool enabled = (derived_die_mask & (1U << slot)) != 0; | ||
| 179 | + if (enabled) { | ||
| 180 | + if (die_res.dieMetadata == nullptr) { | ||
| 181 | + return CcuResult::CCU_E_PARA; | ||
| 182 | + } | ||
| 183 | + for (uint32_t type = 0; type < HCOMM_CCU_BATCH_RES_TYPE_COUNT; ++type) { | ||
| 184 | + CCU_CHK_RET(append_wire_ranges( | ||
| 185 | + die_res.resTypes[type], type, die_res.dieId, derived_die_mask, all_ranges, instance_snapshot)); | ||
| 186 | + } | ||
| 187 | + } else if (die_res.dieMetadata != nullptr || die_res.resTypeNum != 0) { | ||
| 153 | return CcuResult::CCU_E_PARA; | 188 | return CcuResult::CCU_E_PARA; |
| 154 | } | 189 | } |
| 155 | } | 190 | } |
| 156 | 191 | ||
| 157 | asc_ccu_res_repository current_repo = instance_snapshot; | 192 | asc_ccu_res_repository current_repo = instance_snapshot; |
| 158 | - generation_ = context.generation; | 193 | + ccu_version_ = instance.ccuVersion; |
| 159 | - device_logic_id_ = context.deviceLogicId; | 194 | + valid_die_mask_ = derived_die_mask; |
| 160 | - ccu_version_ = context.ccuVersion; | 195 | + for (uint32_t i = 0; i < HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT; ++i) { |
| 161 | - valid_die_mask_ = context.validDieMask; | 196 | + control_ops_[i] = instance.ascCustom[i]; |
| 162 | - control_ops_ = context.controlOps; | 197 | + } |
| 163 | initial_repo_ = std::move(instance_snapshot); | 198 | initial_repo_ = std::move(instance_snapshot); |
| 164 | res_repo_ = std::move(current_repo); | 199 | res_repo_ = std::move(current_repo); |
| 165 | - die_metadata_[0] = context.die[0]; | 200 | + die_metadata_ = die_metadata; |
| 166 | - die_metadata_[1] = context.die[1]; | ||
| 167 | return CcuResult::CCU_SUCCESS; | 201 | return CcuResult::CCU_SUCCESS; |
| 168 | } | 202 | } |
| 169 | 203 | ||
| 170 | CcuResult asc_ccu_res_snapshot::reset() | 204 | CcuResult asc_ccu_res_snapshot::reset() |
| 171 | { | 205 | { |
| 172 | - if (generation_ == 0) { | 206 | + if (valid_die_mask_ == 0) { |
| 173 | return CcuResult::CCU_E_UNAVAIL; | 207 | return CcuResult::CCU_E_UNAVAIL; |
| 174 | } | 208 | } |
| 175 | res_repo_ = initial_repo_; | 209 | res_repo_ = initial_repo_; |
| @@ -178,19 +212,15 @@ CcuResult asc_ccu_res_snapshot::reset() | |||
| 178 | 212 | ||
| 179 | asc_ccu_res_repository& asc_ccu_res_snapshot::get_ccu_res_repo() { return res_repo_; } | 213 | asc_ccu_res_repository& asc_ccu_res_snapshot::get_ccu_res_repo() { return res_repo_; } |
| 180 | 214 | ||
| 181 | -const HcommCcuDieMetadataPod* asc_ccu_res_snapshot::get_die_metadata(uint32_t die_id) const | 215 | +const HcommCcuDieMetadata* asc_ccu_res_snapshot::get_die_metadata(uint32_t die_id) const |
| 182 | { | 216 | { |
| 183 | return die_id < HCOMM_CCU_MAX_DIE_NUM && (valid_die_mask_ & (1U << die_id)) != 0 ? &die_metadata_[die_id] : nullptr; | 217 | return die_id < HCOMM_CCU_MAX_DIE_NUM && (valid_die_mask_ & (1U << die_id)) != 0 ? &die_metadata_[die_id] : nullptr; |
| 184 | } | 218 | } |
| 185 | 219 | ||
| 186 | -uint64_t asc_ccu_res_snapshot::get_generation() const { return generation_; } | ||
| 187 | - | ||
| 188 | -int32_t asc_ccu_res_snapshot::get_device_logic_id() const { return device_logic_id_; } | ||
| 189 | - | ||
| 190 | uint32_t asc_ccu_res_snapshot::get_ccu_version() const { return ccu_version_; } | 220 | uint32_t asc_ccu_res_snapshot::get_ccu_version() const { return ccu_version_; } |
| 191 | 221 | ||
| 192 | uint32_t asc_ccu_res_snapshot::get_valid_die_mask() const { return valid_die_mask_; } | 222 | uint32_t asc_ccu_res_snapshot::get_valid_die_mask() const { return valid_die_mask_; } |
| 193 | 223 | ||
| 194 | -const HcommCcuControlOpsPod& asc_ccu_res_snapshot::get_control_ops() const { return control_ops_; } | 224 | +const uint64_t* asc_ccu_res_snapshot::get_control_ops() const { return control_ops_; } |
| 195 | 225 | ||
| 196 | } // namespace asc | 226 | } // namespace asc |
| @@ -15,13 +15,13 @@ | |||
| 15 | #include <cstdint> | 15 | #include <cstdint> |
| 16 | 16 | ||
| 17 | #include "ccu/hcomm/ccu_api_types.h" | 17 | #include "ccu/hcomm/ccu_api_types.h" |
| 18 | -#include "hcomm/hcomm_ccu_res.h" | 18 | +#include "hcomm/hcomm_ccu_resource.h" |
| 19 | #include "hcomm/resource/common/asc_ccu_resource_local.h" | 19 | #include "hcomm/resource/common/asc_ccu_resource_local.h" |
| 20 | 20 | ||
| 21 | namespace asc { | 21 | namespace asc { |
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | - * @note 职责:RegisterContext 的 asc 侧本地快照。 | 24 | + * @note 职责:CCU Instance(Register Context)的 asc 侧本地快照。 |
| 25 | * | 25 | * |
| 26 | * instance 资源实体由 hcomm 的 RegisterContext 持有与释放,本类只保存其快照,不持有任何跨 SO 句柄。 | 26 | * instance 资源实体由 hcomm 的 RegisterContext 持有与释放,本类只保存其快照,不持有任何跨 SO 句柄。 |
| 27 | * resRepo_ 是被 kernel 注册消耗的余量池(见 MoveResInfo)。 | 27 | * resRepo_ 是被 kernel 注册消耗的余量池(见 MoveResInfo)。 |
| @@ -34,16 +34,14 @@ public: | |||
| 34 | asc_ccu_res_snapshot() = default; | 34 | asc_ccu_res_snapshot() = default; |
| 35 | ~asc_ccu_res_snapshot() = default; | 35 | ~asc_ccu_res_snapshot() = default; |
| 36 | 36 | ||
| 37 | - CcuResult load(const HcommCcuRegisterContextPod& context); | 37 | + CcuResult load(const HcommCcuInstance& instance); |
| 38 | CcuResult reset(); | 38 | CcuResult reset(); |
| 39 | 39 | ||
| 40 | asc_ccu_res_repository& get_ccu_res_repo(); | 40 | asc_ccu_res_repository& get_ccu_res_repo(); |
| 41 | - const HcommCcuDieMetadataPod* get_die_metadata(uint32_t die_id) const; | 41 | + const HcommCcuDieMetadata* get_die_metadata(uint32_t die_id) const; |
| 42 | - uint64_t get_generation() const; | ||
| 43 | - int32_t get_device_logic_id() const; | ||
| 44 | uint32_t get_ccu_version() const; | 42 | uint32_t get_ccu_version() const; |
| 45 | uint32_t get_valid_die_mask() const; | 43 | uint32_t get_valid_die_mask() const; |
| 46 | - const HcommCcuControlOpsPod& get_control_ops() const; | 44 | + const uint64_t* get_control_ops() const; // ascCustom 槽位数组(值需按槽位含义强转) |
| 47 | 45 | ||
| 48 | private: | 46 | private: |
| 49 | asc_ccu_res_snapshot(const asc_ccu_res_snapshot& that) = delete; | 47 | asc_ccu_res_snapshot(const asc_ccu_res_snapshot& that) = delete; |
| @@ -51,14 +49,12 @@ private: | |||
| 51 | asc_ccu_res_snapshot(asc_ccu_res_snapshot&& that) = delete; | 49 | asc_ccu_res_snapshot(asc_ccu_res_snapshot&& that) = delete; |
| 52 | asc_ccu_res_snapshot& operator=(asc_ccu_res_snapshot&& that) = delete; | 50 | asc_ccu_res_snapshot& operator=(asc_ccu_res_snapshot&& that) = delete; |
| 53 | 51 | ||
| 54 | - uint64_t generation_{0}; | ||
| 55 | - int32_t device_logic_id_{0}; | ||
| 56 | uint32_t ccu_version_{0}; | 52 | uint32_t ccu_version_{0}; |
| 57 | uint32_t valid_die_mask_{0}; | 53 | uint32_t valid_die_mask_{0}; |
| 58 | - HcommCcuControlOpsPod control_ops_{}; | 54 | + uint64_t control_ops_[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]{}; |
| 59 | asc_ccu_res_repository initial_repo_{}; | 55 | asc_ccu_res_repository initial_repo_{}; |
| 60 | asc_ccu_res_repository res_repo_{}; | 56 | asc_ccu_res_repository res_repo_{}; |
| 61 | - std::array<HcommCcuDieMetadataPod, HCOMM_CCU_MAX_DIE_NUM> die_metadata_{}; | 57 | + std::array<HcommCcuDieMetadata, HCOMM_CCU_MAX_DIE_NUM> die_metadata_{}; |
| 62 | }; | 58 | }; |
| 63 | 59 | ||
| 64 | } // namespace asc | 60 | } // namespace asc |
| @@ -15,18 +15,24 @@ | |||
| 15 | #include <cstdint> | 15 | #include <cstdint> |
| 16 | #include <vector> | 16 | #include <vector> |
| 17 | 17 | ||
| 18 | -#include "hcomm/hcomm_ccu_res.h" | 18 | +#include "hcomm/hcomm_ccu_resource.h" |
| 19 | 19 | ||
| 20 | namespace asc { | 20 | namespace asc { |
| 21 | 21 | ||
| 22 | -using asc_ccu_res_ranges = std::array<std::vector<HcommCcuResRangePod>, HCOMM_CCU_MAX_DIE_NUM>; | 22 | +/** asc 本地 range 记录:wire POD(HcommCcuResRange 只有 startId/count)加上归属的类型与 die */ |
| 23 | +struct asc_ccu_res_range { | ||
| 24 | + uint32_t resource_type{0}; // HcommCcuBatchResType | ||
| 25 | + uint32_t die_id{0}; | ||
| 26 | + uint32_t start_id{0}; | ||
| 27 | + uint32_t count{0}; | ||
| 28 | +}; | ||
| 29 | + | ||
| 30 | +using asc_ccu_res_ranges = std::array<std::vector<asc_ccu_res_range>, HCOMM_CCU_MAX_DIE_NUM>; | ||
| 23 | 31 | ||
| 24 | struct asc_ccu_res_request { | 32 | struct asc_ccu_res_request { |
| 25 | uint32_t count[HCOMM_CCU_BATCH_RES_TYPE_COUNT][HCOMM_CCU_MAX_DIE_NUM]{}; | 33 | uint32_t count[HCOMM_CCU_BATCH_RES_TYPE_COUNT][HCOMM_CCU_MAX_DIE_NUM]{}; |
| 26 | - uint32_t instruction[HCOMM_CCU_MAX_DIE_NUM]{}; | ||
| 27 | }; | 34 | }; |
| 28 | 35 | ||
| 29 | -// This aggregate is local to asc-comm. Cross-SO transfer only uses range POD elements, not std::vector. | ||
| 30 | struct asc_ccu_res_repository { | 36 | struct asc_ccu_res_repository { |
| 31 | asc_ccu_res_ranges loop_engine{}; | 37 | asc_ccu_res_ranges loop_engine{}; |
| 32 | asc_ccu_res_ranges block_loop_engine{}; | 38 | asc_ccu_res_ranges block_loop_engine{}; |
| @@ -39,7 +45,7 @@ struct asc_ccu_res_repository { | |||
| 39 | asc_ccu_res_ranges gsa{}; | 45 | asc_ccu_res_ranges gsa{}; |
| 40 | asc_ccu_res_ranges block_gsa{}; | 46 | asc_ccu_res_ranges block_gsa{}; |
| 41 | asc_ccu_res_ranges mission{}; | 47 | asc_ccu_res_ranges mission{}; |
| 42 | - asc_ccu_res_ranges instruction{}; | 48 | + // INS 不再入本地资源池:指令空间经 ascCustom.allocInstSpace 向 hcomm 按需申请,随 RegisterContext 归还 |
| 43 | }; | 49 | }; |
| 44 | 50 | ||
| 45 | } // namespace asc | 51 | } // namespace asc |
| @@ -20,17 +20,17 @@ | |||
| 20 | namespace asc { | 20 | namespace asc { |
| 21 | 21 | ||
| 22 | struct ccu_rep_resource { | 22 | struct ccu_rep_resource { |
| 23 | - std::array<std::vector<ccu_rep::ccu_buf>, ccu_max_iodie_num> ccubufs; | 23 | + std::array<std::vector<ccu_rep::ccu_buf>, CCU_MAX_IODIE_NUM> ccubufs; |
| 24 | - std::array<std::vector<ccu_rep::ccu_buf>, ccu_max_iodie_num> block_ccubufs; | 24 | + std::array<std::vector<ccu_rep::ccu_buf>, CCU_MAX_IODIE_NUM> block_ccubufs; |
| 25 | - std::array<std::vector<ccu_rep::executor>, ccu_max_iodie_num> executor; | 25 | + std::array<std::vector<ccu_rep::executor>, CCU_MAX_IODIE_NUM> executor; |
| 26 | - std::array<std::vector<ccu_rep::executor>, ccu_max_iodie_num> block_executor; | 26 | + std::array<std::vector<ccu_rep::executor>, CCU_MAX_IODIE_NUM> block_executor; |
| 27 | - std::array<std::vector<ccu_rep::completed_event>, ccu_max_iodie_num> completed_event; | 27 | + std::array<std::vector<ccu_rep::completed_event>, CCU_MAX_IODIE_NUM> completed_event; |
| 28 | - std::array<std::vector<ccu_rep::completed_event>, ccu_max_iodie_num> block_completed_event; | 28 | + std::array<std::vector<ccu_rep::completed_event>, CCU_MAX_IODIE_NUM> block_completed_event; |
| 29 | - std::array<std::vector<ccu_rep::address>, ccu_max_iodie_num> address; | 29 | + std::array<std::vector<ccu_rep::address>, CCU_MAX_IODIE_NUM> address; |
| 30 | - std::array<std::vector<ccu_rep::address>, ccu_max_iodie_num> block_address; | 30 | + std::array<std::vector<ccu_rep::address>, CCU_MAX_IODIE_NUM> block_address; |
| 31 | - std::array<std::vector<ccu_rep::variable>, ccu_max_iodie_num> continuous_variable; | 31 | + std::array<std::vector<ccu_rep::variable>, CCU_MAX_IODIE_NUM> continuous_variable; |
| 32 | - std::array<std::vector<ccu_rep::variable>, ccu_max_iodie_num> variable; | 32 | + std::array<std::vector<ccu_rep::variable>, CCU_MAX_IODIE_NUM> variable; |
| 33 | - std::array<std::vector<ccu_rep::local_notify>, ccu_max_iodie_num> local_notify; | 33 | + std::array<std::vector<ccu_rep::local_notify>, CCU_MAX_IODIE_NUM> local_notify; |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | // Context共享资源 | 36 | // Context共享资源 |
| @@ -38,7 +38,7 @@ ccu_var_event_res_mgr& ccu_var_event_res_mgr::get_instance(const int32_t device_ | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | CcuResult ccu_var_event_res_mgr::alloc_from_pool( | 40 | CcuResult ccu_var_event_res_mgr::alloc_from_pool( |
| 41 | - std::vector<HcommCcuResRangePod>& pool, uint32_t num, std::vector<HcommCcuResRangePod>& out) | 41 | + std::vector<asc_ccu_res_range>& pool, uint32_t num, std::vector<asc_ccu_res_range>& out) |
| 42 | { | 42 | { |
| 43 | for (auto it = pool.begin(); it != pool.end(); ++it) { | 43 | for (auto it = pool.begin(); it != pool.end(); ++it) { |
| 44 | if (it->count < num) { | 44 | if (it->count < num) { |
| @@ -46,12 +46,12 @@ CcuResult ccu_var_event_res_mgr::alloc_from_pool( | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | out.clear(); | 48 | out.clear(); |
| 49 | - out.emplace_back(HcommCcuResRangePod{it->resourceType, it->dieId, it->startId, num}); | 49 | + out.emplace_back(asc_ccu_res_range{it->resource_type, it->die_id, it->start_id, num}); |
| 50 | 50 | ||
| 51 | if (it->count == num) { | 51 | if (it->count == num) { |
| 52 | pool.erase(it); | 52 | pool.erase(it); |
| 53 | } else { | 53 | } else { |
| 54 | - it->startId += num; | 54 | + it->start_id += num; |
| 55 | it->count -= num; | 55 | it->count -= num; |
| 56 | } | 56 | } |
| 57 | return CCU_SUCCESS; | 57 | return CCU_SUCCESS; |
| @@ -61,7 +61,7 @@ CcuResult ccu_var_event_res_mgr::alloc_from_pool( | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | void ccu_var_event_res_mgr::return_to_pool( | 63 | void ccu_var_event_res_mgr::return_to_pool( |
| 64 | - std::vector<HcommCcuResRangePod>& pool, const std::vector<HcommCcuResRangePod>& ranges) | 64 | + std::vector<asc_ccu_res_range>& pool, const std::vector<asc_ccu_res_range>& ranges) |
| 65 | { | 65 | { |
| 66 | for (const auto& range : ranges) { | 66 | for (const auto& range : ranges) { |
| 67 | if (range.count == 0) { | 67 | if (range.count == 0) { |
| @@ -71,7 +71,7 @@ void ccu_var_event_res_mgr::return_to_pool( | |||
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | -static std::vector<HcommCcuResRangePod>* select_pool( | 74 | +static std::vector<asc_ccu_res_range>* select_pool( |
| 75 | asc_ccu_res_repository& res_repo, ccu_var_event_type type, uint8_t die_id) | 75 | asc_ccu_res_repository& res_repo, ccu_var_event_type type, uint8_t die_id) |
| 76 | { | 76 | { |
| 77 | switch (type) { | 77 | switch (type) { |
| @@ -232,24 +232,24 @@ CcuResult ccu_var_event_res_mgr::alloc_and_record( | |||
| 232 | return CCU_E_PARA; | 232 | return CCU_E_PARA; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | - std::vector<HcommCcuResRangePod>* pool = select_pool(res_repo, type, die_id); | 235 | + std::vector<asc_ccu_res_range>* pool = select_pool(res_repo, type, die_id); |
| 236 | if (pool == nullptr) { | 236 | if (pool == nullptr) { |
| 237 | HCCL_ERROR("[CcuVarEventResMgr][%s] failed, unsupported type[%d].", __func__, static_cast<int32_t>(type)); | 237 | HCCL_ERROR("[CcuVarEventResMgr][%s] failed, unsupported type[%d].", __func__, static_cast<int32_t>(type)); |
| 238 | return CCU_E_PARA; | 238 | return CCU_E_PARA; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | - std::vector<HcommCcuResRangePod> res_ranges{}; | 241 | + std::vector<asc_ccu_res_range> res_ranges{}; |
| 242 | CcuResult ret = alloc_from_pool(*pool, num, res_ranges); | 242 | CcuResult ret = alloc_from_pool(*pool, num, res_ranges); |
| 243 | if (ret != CCU_SUCCESS) { | 243 | if (ret != CCU_SUCCESS) { |
| 244 | HCCL_ERROR( | 244 | HCCL_ERROR( |
| 245 | "[CcuVarEventResMgr][%s] failed, no consecutive block of num[%u] in ins_handle[0x%llx] " | 245 | "[CcuVarEventResMgr][%s] failed, no consecutive block of num[%u] in ins_handle[0x%llx] " |
| 246 | "resource pool, die_id[%u] type[%d].", | 246 | "resource pool, die_id[%u] type[%d].", |
| 247 | - __func__, num, ins_handle, die_id, static_cast<int32_t>(type)); | 247 | + __func__, num, static_cast<unsigned long long>(ins_handle.ccuInsKey), die_id, static_cast<int32_t>(type)); |
| 248 | return ret; | 248 | return ret; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | ccu_var_event_res res{}; | 251 | ccu_var_event_res res{}; |
| 252 | - res.ins_handle = ins_handle; | 252 | + res.ins_key = ins_handle.ccuInsKey; |
| 253 | res.dev_logic_id = dev_logic_id_; | 253 | res.dev_logic_id = dev_logic_id_; |
| 254 | res.die_id = die_id; | 254 | res.die_id = die_id; |
| 255 | res.type = type; | 255 | res.type = type; |
| @@ -279,7 +279,8 @@ CcuResult ccu_var_event_res_mgr::acquire( | |||
| 279 | HCCL_RUN_WARNING( | 279 | HCCL_RUN_WARNING( |
| 280 | "[CcuVarEventResMgr][%s] register addrs failed[%d], release acquired " | 280 | "[CcuVarEventResMgr][%s] register addrs failed[%d], release acquired " |
| 281 | "handle[0x%llx] ins_handle[0x%llx] die_id[%u] type[%d] num[%u].", | 281 | "handle[0x%llx] ins_handle[0x%llx] die_id[%u] type[%d] num[%u].", |
| 282 | - __func__, static_cast<int32_t>(reg_ret), new_handle, ins_handle, die_id, static_cast<int32_t>(type), num); | 282 | + __func__, static_cast<int32_t>(reg_ret), new_handle, static_cast<unsigned long long>(ins_handle.ccuInsKey), |
| 283 | + die_id, static_cast<int32_t>(type), num); | ||
| 283 | (void)release_by_handle(new_handle); | 284 | (void)release_by_handle(new_handle); |
| 284 | return reg_ret; | 285 | return reg_ret; |
| 285 | } | 286 | } |
| @@ -288,7 +289,8 @@ CcuResult ccu_var_event_res_mgr::acquire( | |||
| 288 | HCCL_RUN_INFO( | 289 | HCCL_RUN_INFO( |
| 289 | "[CcuVarEventResMgr][%s] success, devLogicId[%d] ins_handle[0x%llx] die_id[%u] " | 290 | "[CcuVarEventResMgr][%s] success, devLogicId[%d] ins_handle[0x%llx] die_id[%u] " |
| 290 | "type[%d] num[%u] handle[0x%llx].", | 291 | "type[%d] num[%u] handle[0x%llx].", |
| 291 | - __func__, dev_logic_id_, ins_handle, die_id, static_cast<int32_t>(type), num, handle); | 292 | + __func__, dev_logic_id_, static_cast<unsigned long long>(ins_handle.ccuInsKey), die_id, |
| 293 | + static_cast<int32_t>(type), num, handle); | ||
| 292 | return CCU_SUCCESS; | 294 | return CCU_SUCCESS; |
| 293 | } | 295 | } |
| 294 | 296 | ||
| @@ -314,7 +316,7 @@ CcuResult ccu_var_event_res_mgr::get_variable_xn_id( | |||
| 314 | return CCU_E_NOT_SUPPORT; | 316 | return CCU_E_NOT_SUPPORT; |
| 315 | } | 317 | } |
| 316 | 318 | ||
| 317 | - const HcommCcuResRangePod& range = res.res_ranges[0]; | 319 | + const asc_ccu_res_range& range = res.res_ranges[0]; |
| 318 | if (index >= range.count) { | 320 | if (index >= range.count) { |
| 319 | HCCL_ERROR( | 321 | HCCL_ERROR( |
| 320 | "[CcuVarEventResMgr][%s] get variable resource id failed, index[%u] out of range, block count[%u].", | 322 | "[CcuVarEventResMgr][%s] get variable resource id failed, index[%u] out of range, block count[%u].", |
| @@ -323,7 +325,7 @@ CcuResult ccu_var_event_res_mgr::get_variable_xn_id( | |||
| 323 | } | 325 | } |
| 324 | 326 | ||
| 325 | die_id = res.die_id; | 327 | die_id = res.die_id; |
| 326 | - xn_id = range.startId + index; | 328 | + xn_id = range.start_id + index; |
| 327 | return CCU_SUCCESS; | 329 | return CCU_SUCCESS; |
| 328 | } | 330 | } |
| 329 | 331 | ||
| @@ -351,7 +353,7 @@ CcuResult ccu_var_event_res_mgr::get_event_cke_id( | |||
| 351 | return CCU_E_NOT_SUPPORT; | 353 | return CCU_E_NOT_SUPPORT; |
| 352 | } | 354 | } |
| 353 | 355 | ||
| 354 | - const HcommCcuResRangePod& range = res.res_ranges[0]; | 356 | + const asc_ccu_res_range& range = res.res_ranges[0]; |
| 355 | if (index >= range.count) { | 357 | if (index >= range.count) { |
| 356 | HCCL_ERROR( | 358 | HCCL_ERROR( |
| 357 | "[CcuVarEventResMgr][%s] failed, index[%u] out of range, block count[%u].", __func__, index, range.count); | 359 | "[CcuVarEventResMgr][%s] failed, index[%u] out of range, block count[%u].", __func__, index, range.count); |
| @@ -359,7 +361,7 @@ CcuResult ccu_var_event_res_mgr::get_event_cke_id( | |||
| 359 | } | 361 | } |
| 360 | 362 | ||
| 361 | die_id = res.die_id; | 363 | die_id = res.die_id; |
| 362 | - cke_id = range.startId + index; | 364 | + cke_id = range.start_id + index; |
| 363 | return CCU_SUCCESS; | 365 | return CCU_SUCCESS; |
| 364 | } | 366 | } |
| 365 | 367 | ||
| @@ -430,7 +432,7 @@ CcuResult ccu_var_event_res_mgr::unmap_saved_addrs(const ccu_var_event_res& res) | |||
| 430 | { | 432 | { |
| 431 | // 仅 unmap Alloc 阶段已成功映射并保存 VA 的资源;错误回滚路径中 va_list 为空,天然跳过。 | 433 | // 仅 unmap Alloc 阶段已成功映射并保存 VA 的资源;错误回滚路径中 va_list 为空,天然跳过。 |
| 432 | // 不变量:va_list 非空 <=> SaveAddrs 已成功,而 SaveAddrs 强校验 res_ranges 为单个连续块且 | 434 | // 不变量:va_list 非空 <=> SaveAddrs 已成功,而 SaveAddrs 强校验 res_ranges 为单个连续块且 |
| 433 | - // va_list.size() == res_ranges[0].count,故下面用 res_ranges[0].startId + index 反推 res_id 恒成立 | 435 | + // va_list.size() == res_ranges[0].count,故下面用 res_ranges[0].start_id + index 反推 res_id 恒成立 |
| 434 | if (res.va_list.empty() || res.res_ranges.empty()) { | 436 | if (res.va_list.empty() || res.res_ranges.empty()) { |
| 435 | return CCU_SUCCESS; | 437 | return CCU_SUCCESS; |
| 436 | } | 438 | } |
| @@ -450,7 +452,7 @@ CcuResult ccu_var_event_res_mgr::unmap_saved_addrs(const ccu_var_event_res& res) | |||
| 450 | } | 452 | } |
| 451 | 453 | ||
| 452 | CcuResult first_err = CCU_SUCCESS; | 454 | CcuResult first_err = CCU_SUCCESS; |
| 453 | - const uint32_t start_id = res.res_ranges[0].startId; | 455 | + const uint32_t start_id = res.res_ranges[0].start_id; |
| 454 | for (uint32_t index = 0; index < res.va_list.size(); index++) { | 456 | for (uint32_t index = 0; index < res.va_list.size(); index++) { |
| 455 | CcuResult ret = unmap_dev_res_address(res.die_id, res_type, start_id + index); | 457 | CcuResult ret = unmap_dev_res_address(res.die_id, res_type, start_id + index); |
| 456 | if (ret != CCU_SUCCESS && first_err == CCU_SUCCESS) { | 458 | if (ret != CCU_SUCCESS && first_err == CCU_SUCCESS) { |
| @@ -487,7 +489,7 @@ CcuResult ccu_var_event_res_mgr::release_by_handle(uint64_t handle) | |||
| 487 | if (res.res_repo == nullptr) { | 489 | if (res.res_repo == nullptr) { |
| 488 | return unmap_ret; | 490 | return unmap_ret; |
| 489 | } | 491 | } |
| 490 | - std::vector<HcommCcuResRangePod>* pool = select_pool(*res.res_repo, res.type, res.die_id); | 492 | + std::vector<asc_ccu_res_range>* pool = select_pool(*res.res_repo, res.type, res.die_id); |
| 491 | if (pool == nullptr) { | 493 | if (pool == nullptr) { |
| 492 | HCCL_ERROR( | 494 | HCCL_ERROR( |
| 493 | "[CcuVarEventResMgr][%s] failed to return, handle[0x%llx] type[%d].", __func__, handle, | 495 | "[CcuVarEventResMgr][%s] failed to return, handle[0x%llx] type[%d].", __func__, handle, |
| @@ -504,7 +506,7 @@ CcuResult ccu_var_event_res_mgr::release_by_instance(CcuInsHandle ins_handle) | |||
| 504 | { | 506 | { |
| 505 | std::unique_lock<std::shared_timed_mutex> lock(map_mutex_); | 507 | std::unique_lock<std::shared_timed_mutex> lock(map_mutex_); |
| 506 | for (auto it = res_map_.begin(); it != res_map_.end();) { | 508 | for (auto it = res_map_.begin(); it != res_map_.end();) { |
| 507 | - if (it->second.ins_handle == ins_handle) { | 509 | + if (it->second.ins_key == ins_handle.ccuInsKey) { |
| 508 | to_release.push_back(std::move(it->second)); | 510 | to_release.push_back(std::move(it->second)); |
| 509 | it = res_map_.erase(it); | 511 | it = res_map_.erase(it); |
| 510 | } else { | 512 | } else { |
| @@ -525,11 +527,11 @@ CcuResult ccu_var_event_res_mgr::release_by_instance(CcuInsHandle ins_handle) | |||
| 525 | if (res.res_repo == nullptr) { | 527 | if (res.res_repo == nullptr) { |
| 526 | continue; | 528 | continue; |
| 527 | } | 529 | } |
| 528 | - std::vector<HcommCcuResRangePod>* pool = select_pool(*res.res_repo, res.type, res.die_id); | 530 | + std::vector<asc_ccu_res_range>* pool = select_pool(*res.res_repo, res.type, res.die_id); |
| 529 | if (pool == nullptr) { | 531 | if (pool == nullptr) { |
| 530 | HCCL_ERROR( | 532 | HCCL_ERROR( |
| 531 | - "[CcuVarEventResMgr][%s] failed to return, ins_handle[0x%llx] type[%d].", __func__, ins_handle, | 533 | + "[CcuVarEventResMgr][%s] failed to return, ins_handle[0x%llx] type[%d].", __func__, |
| 532 | - static_cast<int32_t>(res.type)); | 534 | + static_cast<unsigned long long>(ins_handle.ccuInsKey), static_cast<int32_t>(res.type)); |
| 533 | if (first_err == CCU_SUCCESS) { | 535 | if (first_err == CCU_SUCCESS) { |
| 534 | first_err = CCU_E_INTERNAL; | 536 | first_err = CCU_E_INTERNAL; |
| 535 | } | 537 | } |
| @@ -541,26 +543,26 @@ CcuResult ccu_var_event_res_mgr::release_by_instance(CcuInsHandle ins_handle) | |||
| 541 | } | 543 | } |
| 542 | 544 | ||
| 543 | // 从空闲块列表 pool 中扣除区间 [start, start+count)必要时把命中的空闲块拆分成左右两段。 | 545 | // 从空闲块列表 pool 中扣除区间 [start, start+count)必要时把命中的空闲块拆分成左右两段。 |
| 544 | -static void remove_range_from_pool(std::vector<HcommCcuResRangePod>& pool, uint32_t start, uint32_t count) | 546 | +static void remove_range_from_pool(std::vector<asc_ccu_res_range>& pool, uint32_t start, uint32_t count) |
| 545 | { | 547 | { |
| 546 | if (count == 0) { | 548 | if (count == 0) { |
| 547 | return; | 549 | return; |
| 548 | } | 550 | } |
| 549 | const uint32_t end = start + count; | 551 | const uint32_t end = start + count; |
| 550 | - std::vector<HcommCcuResRangePod> result{}; | 552 | + std::vector<asc_ccu_res_range> result{}; |
| 551 | result.reserve(pool.size() + 1); | 553 | result.reserve(pool.size() + 1); |
| 552 | for (const auto& block : pool) { | 554 | for (const auto& block : pool) { |
| 553 | - const uint32_t blockStart = block.startId; | 555 | + const uint32_t blockStart = block.start_id; |
| 554 | - const uint32_t blockEnd = block.startId + block.count; | 556 | + const uint32_t blockEnd = block.start_id + block.count; |
| 555 | if (end <= blockStart || start >= blockEnd) { | 557 | if (end <= blockStart || start >= blockEnd) { |
| 556 | result.push_back(block); | 558 | result.push_back(block); |
| 557 | continue; | 559 | continue; |
| 558 | } | 560 | } |
| 559 | if (blockStart < start) { | 561 | if (blockStart < start) { |
| 560 | - result.emplace_back(HcommCcuResRangePod{block.resourceType, block.dieId, blockStart, start - blockStart}); | 562 | + result.emplace_back(asc_ccu_res_range{block.resource_type, block.die_id, blockStart, start - blockStart}); |
| 561 | } | 563 | } |
| 562 | if (end < blockEnd) { | 564 | if (end < blockEnd) { |
| 563 | - result.emplace_back(HcommCcuResRangePod{block.resourceType, block.dieId, end, blockEnd - end}); | 565 | + result.emplace_back(asc_ccu_res_range{block.resource_type, block.die_id, end, blockEnd - end}); |
| 564 | } | 566 | } |
| 565 | } | 567 | } |
| 566 | pool.swap(result); | 568 | pool.swap(result); |
| @@ -573,22 +575,23 @@ CcuResult ccu_var_event_res_mgr::exclude_allocated_from_repo(CcuInsHandle ins_ha | |||
| 573 | std::shared_lock<std::shared_timed_mutex> lock(map_mutex_); | 575 | std::shared_lock<std::shared_timed_mutex> lock(map_mutex_); |
| 574 | for (const auto& kv : res_map_) { | 576 | for (const auto& kv : res_map_) { |
| 575 | const ccu_var_event_res& res = kv.second; | 577 | const ccu_var_event_res& res = kv.second; |
| 576 | - if (res.ins_handle != ins_handle || res.res_repo == nullptr) { | 578 | + if (res.ins_key != ins_handle.ccuInsKey || res.res_repo == nullptr) { |
| 577 | continue; | 579 | continue; |
| 578 | } | 580 | } |
| 579 | - std::vector<HcommCcuResRangePod>* pool = select_pool(*res.res_repo, res.type, res.die_id); | 581 | + std::vector<asc_ccu_res_range>* pool = select_pool(*res.res_repo, res.type, res.die_id); |
| 580 | if (pool == nullptr) { | 582 | if (pool == nullptr) { |
| 581 | HCCL_ERROR( | 583 | HCCL_ERROR( |
| 582 | - "[CcuVarEventResMgr][%s] failed, ins_handle[0x%llx] type[%d].", __func__, ins_handle, | 584 | + "[CcuVarEventResMgr][%s] failed, ins_handle[0x%llx] type[%d].", __func__, |
| 583 | - static_cast<int32_t>(res.type)); | 585 | + static_cast<unsigned long long>(ins_handle.ccuInsKey), static_cast<int32_t>(res.type)); |
| 584 | continue; | 586 | continue; |
| 585 | } | 587 | } |
| 586 | for (const auto& range : res.res_ranges) { | 588 | for (const auto& range : res.res_ranges) { |
| 587 | - remove_range_from_pool(*pool, range.startId, range.count); | 589 | + remove_range_from_pool(*pool, range.start_id, range.count); |
| 588 | HCCL_INFO( | 590 | HCCL_INFO( |
| 589 | "[CcuVarEventResMgr][%s] exclude acquired res, ins_handle[0x%llx] type[%d] " | 591 | "[CcuVarEventResMgr][%s] exclude acquired res, ins_handle[0x%llx] type[%d] " |
| 590 | "die_id[%u] start_id[%u] count[%u].", | 592 | "die_id[%u] start_id[%u] count[%u].", |
| 591 | - __func__, ins_handle, static_cast<int32_t>(res.type), res.die_id, range.startId, range.count); | 593 | + __func__, static_cast<unsigned long long>(ins_handle.ccuInsKey), static_cast<int32_t>(res.type), |
| 594 | + res.die_id, range.start_id, range.count); | ||
| 592 | } | 595 | } |
| 593 | } | 596 | } |
| 594 | return CCU_SUCCESS; | 597 | return CCU_SUCCESS; |
| @@ -27,11 +27,12 @@ enum class ccu_var_event_type { | |||
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | struct ccu_var_event_res { | 29 | struct ccu_var_event_res { |
| 30 | - CcuInsHandle ins_handle{0}; | 30 | + // 仅保存实例身份;资源记录不需要持有 CcuInsHandle 中的借用指针。 |
已过期 这里为什么要挂一个handle ![]() ![]() | |||
| 31 | + uint64_t ins_key{0}; | ||
| 31 | int32_t dev_logic_id{-1}; | 32 | int32_t dev_logic_id{-1}; |
| 32 | uint8_t die_id{0}; | 33 | uint8_t die_id{0}; |
| 33 | ccu_var_event_type type{ccu_var_event_type::variable}; | 34 | ccu_var_event_type type{ccu_var_event_type::variable}; |
| 34 | - std::vector<HcommCcuResRangePod> res_ranges{}; | 35 | + std::vector<asc_ccu_res_range> res_ranges{}; |
| 35 | // 借用指针,指向发起预约的 CcuKernelRegistry 名下 AscCcuResSnapshot 持有的资源仓,本类不持有所有权。 | 36 | // 借用指针,指向发起预约的 CcuKernelRegistry 名下 AscCcuResSnapshot 持有的资源仓,本类不持有所有权。 |
| 36 | // 有效性依赖既定时序:~CcuKernelRegistry 中 ReleaseByInstance 先于 resSnapshot_ 置空执行, | 37 | // 有效性依赖既定时序:~CcuKernelRegistry 中 ReleaseByInstance 先于 resSnapshot_ 置空执行, |
| 37 | // CcuKernelRegistry::Reset 调 ExcludeAllocatedFromRepo 时资源仓亦仍存活。 | 38 | // CcuKernelRegistry::Reset 调 ExcludeAllocatedFromRepo 时资源仓亦仍存活。 |
| @@ -95,8 +96,8 @@ private: | |||
| 95 | CcuResult register_addrs(ccu_var_event_type type, uint64_t handle, uint32_t num); | 96 | CcuResult register_addrs(ccu_var_event_type type, uint64_t handle, uint32_t num); |
| 96 | 97 | ||
| 97 | static CcuResult alloc_from_pool( | 98 | static CcuResult alloc_from_pool( |
| 98 | - std::vector<HcommCcuResRangePod>& pool, uint32_t num, std::vector<HcommCcuResRangePod>& out); | 99 | + std::vector<asc_ccu_res_range>& pool, uint32_t num, std::vector<asc_ccu_res_range>& out); |
| 99 | - static void return_to_pool(std::vector<HcommCcuResRangePod>& pool, const std::vector<HcommCcuResRangePod>& ranges); | 100 | + static void return_to_pool(std::vector<asc_ccu_res_range>& pool, const std::vector<asc_ccu_res_range>& ranges); |
| 100 | // 释放资源前,将 Alloc 阶段映射的进程可访问 VA 逐个 unmap(仅处理已保存 VA 的资源); | 101 | // 释放资源前,将 Alloc 阶段映射的进程可访问 VA 逐个 unmap(仅处理已保存 VA 的资源); |
| 101 | // 返回首个 unmap 失败的错误码,失败不中断,其余资源继续 unmap | 102 | // 返回首个 unmap 失败的错误码,失败不中断,其余资源继续 unmap |
| 102 | static CcuResult unmap_saved_addrs(const ccu_var_event_res& res); | 103 | static CcuResult unmap_saved_addrs(const ccu_var_event_res& res); |
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <memory> | 16 | #include <memory> |
| 17 | 17 | ||
| 18 | #include "hcomm/resource/representation/ccu_rep_v1.h" | 18 | #include "hcomm/resource/representation/ccu_rep_v1.h" |
| 19 | +#include "hcomm/hcomm_ccu_dfx.h" | ||
| 19 | 20 | ||
| 20 | namespace asc { | 21 | namespace asc { |
| 21 | namespace { | 22 | namespace { |
| @@ -48,9 +49,8 @@ union loop_group_xn { | |||
| 48 | // 再一条条通过 emit 回调发出去;数据面自己不直接碰驱动。 | 49 | // 再一条条通过 emit 回调发出去;数据面自己不直接碰驱动。 |
| 49 | class dfx_builder { | 50 | class dfx_builder { |
| 50 | public: | 51 | public: |
| 51 | - dfx_builder( | 52 | + dfx_builder(const HcommCcuDfxRequest& request, HcommCcuDfxEmitFn emit, void* context, const uint64_t* asc_custom) |
| 52 | - const HcommCcuDfxRequestPod& request, HcommCcuDfxEmitFn emit, void* context, const HcommCcuControlOpsPod& ops) | 53 | + : request_(request), emit_(emit), context_(context), asc_custom_(asc_custom) |
| 53 | - : request_(request), emit_(emit), context_(context), ops_(ops) | ||
| 54 | {} | 54 | {} |
| 55 | 55 | ||
| 56 | // 诊断主流程:查任务现场 → 找到内核 → 先发一条 MISSION 记录, | 56 | // 诊断主流程:查任务现场 → 找到内核 → 先发一条 MISSION 记录, |
| @@ -58,55 +58,19 @@ public: | |||
| 58 | // 指令的 REP 也逐条发出去;返回第一个错误码(没出错返回 0,找不到 REP 返回 CCU_E_NOT_FOUND) | 58 | // 指令的 REP 也逐条发出去;返回第一个错误码(没出错返回 0,找不到 REP 返回 CCU_E_NOT_FOUND) |
| 59 | int32_t run() | 59 | int32_t run() |
| 60 | { | 60 | { |
| 61 | - HcommCcuMissionContextPod mission{}; | 61 | + // 诊断链降级:定位不到故障指令,直接返回不支持(hcomm 侧打印 "diagnose failed" 即可)。 |
| 62 | - if (ops_.missionContextQuery == nullptr || | 62 | + HCCL_WARNING( |
| 63 | - ops_.missionContextQuery(request_.deviceId, request_.dieId, request_.execMissionId, &mission) != 0) { | 63 | + "[CcuDfx][%s] mission context query is not available in ascCustom slots, hardware-fault " |
| 64 | - return static_cast<int32_t>(CcuResult::CCU_E_INTERNAL); | 64 | + "localization is degraded. devLogicId[%d] dieId[%u] kernelHandle[%llu].", |
| 65 | - } | 65 | + __func__, request_.deviceId, request_.dieId, static_cast<unsigned long long>(request_.kernelHandle)); |
| 66 | - ccu_kernel* kernel = ccu_kernel_mgr::get_instance(request_.deviceId).get_kernel(request_.kernelHandle); | 66 | + return static_cast<int32_t>(CcuResult::CCU_E_NOT_SUPPORT); |
| 67 | - if (kernel == nullptr) { | ||
| 68 | - return static_cast<int32_t>(CcuResult::CCU_E_NOT_FOUND); | ||
| 69 | - } | ||
| 70 | - emit_mission(mission.currentInstructionId); | ||
| 71 | - auto current = resolve_rep(*kernel, mission.currentInstructionId); | ||
| 72 | - if (current == nullptr) { | ||
| 73 | - return static_cast<int32_t>(CcuResult::CCU_E_NOT_FOUND); | ||
| 74 | - } | ||
| 75 | - auto previous = | ||
| 76 | - mission.currentInstructionId == 0 ? nullptr : kernel->get_rep_by_instr_id(mission.currentInstructionId - 1); | ||
| 77 | - if ((previous != nullptr && previous->type() == ccu_rep_type::loop_group) || | ||
| 78 | - current->type() == ccu_rep_type::loop_group) { | ||
| 79 | - emit_loop_group( | ||
| 80 | - *kernel, previous != nullptr && previous->type() == ccu_rep_type::loop_group ? previous : current); | ||
| 81 | - } else { | ||
| 82 | - emit_rep(current); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - // 只回看故障前的 10 条指令,且不能越过本条任务开始的位置 | ||
| 86 | - const uint16_t distance = 10; | ||
| 87 | - uint16_t begin = mission.currentInstructionId > distance ? mission.currentInstructionId - distance : 0; | ||
| 88 | - begin = std::max(begin, mission.startInstructionId); | ||
| 89 | - for (int32_t id = mission.currentInstructionId; id >= begin; --id) { | ||
| 90 | - if (kernel->get_rep_by_instr_id(static_cast<uint16_t>(id)) == nullptr) { | ||
| 91 | - // 这个编号没有对应的 REP(指令中间有空档),窗口就缩短到这里 | ||
| 92 | - begin = static_cast<uint16_t>(id + 1); | ||
| 93 | - break; | ||
| 94 | - } | ||
| 95 | - } | ||
| 96 | - for (uint32_t id = begin; id <= mission.currentInstructionId; ++id) { | ||
| 97 | - auto rep = kernel->get_rep_by_instr_id(static_cast<uint16_t>(id)); | ||
| 98 | - if (rep != nullptr) { | ||
| 99 | - emit_rep(rep); | ||
| 100 | - } | ||
| 101 | - } | ||
| 102 | - return first_error_; | ||
| 103 | } | 67 | } |
| 104 | 68 | ||
| 105 | private: | 69 | private: |
| 106 | // 填记录里公共的部分:记录类型、REP 类型、die/任务编号、指令编号(REP 第一条指令所在位置) | 70 | // 填记录里公共的部分:记录类型、REP 类型、die/任务编号、指令编号(REP 第一条指令所在位置) |
| 107 | - HcommCcuDfxRecordPod make_base_record(const std::shared_ptr<ccu_rep_base>& rep, uint32_t type) const | 71 | + HcommCcuDfxRecord make_base_record(const std::shared_ptr<ccu_rep_base>& rep, uint32_t type) const |
| 108 | { | 72 | { |
| 109 | - HcommCcuDfxRecordPod record{}; | 73 | + HcommCcuDfxRecord record{}; |
| 110 | record.type = type; | 74 | record.type = type; |
| 111 | record.repType = static_cast<int32_t>(rep->type()); | 75 | record.repType = static_cast<int32_t>(rep->type()); |
| 112 | record.dieId = static_cast<uint8_t>(request_.dieId); | 76 | record.dieId = static_cast<uint8_t>(request_.dieId); |
| @@ -116,40 +80,46 @@ private: | |||
| 116 | } | 80 | } |
| 117 | 81 | ||
| 118 | // 发一条记录;只记第一次失败,保证错误码稳定 | 82 | // 发一条记录;只记第一次失败,保证错误码稳定 |
| 119 | - void emit(HcommCcuDfxRecordPod& record) | 83 | + void emit(HcommCcuDfxRecord& record) |
| 120 | { | 84 | { |
| 121 | if (first_error_ == 0) { | 85 | if (first_error_ == 0) { |
| 122 | first_error_ = emit_(context_, &record); | 86 | first_error_ = emit_(context_, &record); |
| 123 | } | 87 | } |
| 124 | } | 88 | } |
| 125 | 89 | ||
| 126 | - // 按编号查 XN/CKE/GSA 资源当时的数值;查不到返回 UINT64_MAX,并把错误记为内部错误 | 90 | + // 按编号查 XN/CKE/GSA 资源当时的数值;硬件现场查询未注入(定档槽 3-7 预留),恒返回 UINT64_MAX |
| 127 | uint64_t resource(HcommCcuResourceQueryFn query, uint32_t id) | 91 | uint64_t resource(HcommCcuResourceQueryFn query, uint32_t id) |
| 128 | { | 92 | { |
| 129 | - uint64_t value = UINT64_MAX; | 93 | + (void)query; |
| 130 | - if (query == nullptr || query(request_.deviceId, request_.dieId, id, &value) != 0) { | 94 | + (void)id; |
| 131 | - first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_INTERNAL) : first_error_; | 95 | + return UINT64_MAX; |
| 132 | - } | ||
| 133 | - return value; | ||
| 134 | } | 96 | } |
| 135 | 97 | ||
| 136 | - // 单阶段查询 Channel POD 快照:先填充 ABI 头,再调用控制面注入的 channelQuery | 98 | + // 单阶段查询 Channel 实体:getChannelEntity 返回 hcomm 持有的借用指针,按值拷贝后使用 |
| 137 | - bool query_channel(ChannelHandle handle, HcommCcuChannelPod& channel) | 99 | + bool query_channel(ChannelHandle handle, HcommCcuChannelEntity& channel) |
| 138 | { | 100 | { |
| 139 | - channel.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; | 101 | + uint64_t entity_addr = 0; |
| 140 | - channel.header.magicWord = HCOMM_CCU_CHANNEL_POD_MAGIC_WORD; | 102 | + const auto get_channel_entity = |
| 141 | - channel.header.size = sizeof(HcommCcuChannelPod); | 103 | + reinterpret_cast<HcommCcuGetChannelEntityFn>(asc_custom_[HCOMM_CCU_ASC_CUSTOM_CHANNEL_ENTITY]); |
| 142 | - if (ops_.channelQuery == nullptr || ops_.channelQuery(handle, &channel) != 0) { | 104 | + if (get_channel_entity == nullptr || get_channel_entity(handle, &entity_addr) != 0 || entity_addr == 0) { |
| 143 | first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_INTERNAL) : first_error_; | 105 | first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_INTERNAL) : first_error_; |
| 144 | return false; | 106 | return false; |
| 145 | } | 107 | } |
| 108 | + const auto* entity = reinterpret_cast<const HcommCcuChannelEntity*>(entity_addr); | ||
| 109 | + if (entity->header.version != HCOMM_CCU_CHANNEL_ABI_VERSION || | ||
| 110 | + entity->header.magicWord != HCOMM_CCU_CHANNEL_MAGIC_WORD || | ||
| 111 | + entity->header.size != sizeof(HcommCcuChannelEntity)) { | ||
| 112 | + first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_PARA) : first_error_; | ||
| 113 | + return false; | ||
| 114 | + } | ||
| 115 | + channel = *entity; | ||
| 146 | return true; | 116 | return true; |
| 147 | } | 117 | } |
| 148 | 118 | ||
| 149 | // 把通道句柄转成记录里要填的通道编号;解析失败就保持 UINT16_MAX(表示无效通道) | 119 | // 把通道句柄转成记录里要填的通道编号;解析失败就保持 UINT16_MAX(表示无效通道) |
| 150 | void set_channel(ChannelHandle handle, uint16_t& id, ChannelHandle& record_handle) | 120 | void set_channel(ChannelHandle handle, uint16_t& id, ChannelHandle& record_handle) |
| 151 | { | 121 | { |
| 152 | - HcommCcuChannelPod channel{}; | 122 | + HcommCcuChannelEntity channel{}; |
| 153 | record_handle = handle; | 123 | record_handle = handle; |
| 154 | id = UINT16_MAX; | 124 | id = UINT16_MAX; |
| 155 | // 查询失败时保留哨兵值 id=UINT16_MAX,交由上层按无效 channel 处理 | 125 | // 查询失败时保留哨兵值 id=UINT16_MAX,交由上层按无效 channel 处理 |
| @@ -164,11 +134,10 @@ private: | |||
| 164 | id = static_cast<uint16_t>(channel.channelId); | 134 | id = static_cast<uint16_t>(channel.channelId); |
| 165 | } | 135 | } |
| 166 | 136 | ||
| 167 | - // 从 POD 定长数组取第 index 个资源 id,收窄为 uint16_t 前做指针/越界/溢出校验 | 137 | + // 从实体数组取第 index 个资源 id:按有效数量(而非定长容量)校验下标,收窄 uint16_t 前做溢出校验 |
| 168 | - uint16_t id_by_array(const uint32_t* ids, uint16_t index) | 138 | + uint16_t id_by_array(const uint32_t* ids, uint32_t valid_num, uint16_t index) |
| 169 | { | 139 | { |
| 170 | - if (ids == nullptr || index >= HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY || | 140 | + if (ids == nullptr || index >= valid_num || ids[index] > std::numeric_limits<uint16_t>::max()) { |
| 171 | - ids[index] > std::numeric_limits<uint16_t>::max()) { | ||
| 172 | first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_PARA) : first_error_; | 141 | first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_PARA) : first_error_; |
| 173 | return UINT16_MAX; | 142 | return UINT16_MAX; |
| 174 | } | 143 | } |
| @@ -178,21 +147,23 @@ private: | |||
| 178 | // 取本端/远端 CKE(信号量)id:remote 为 true 时读远端数组,否则读本端数组 | 147 | // 取本端/远端 CKE(信号量)id:remote 为 true 时读远端数组,否则读本端数组 |
| 179 | uint16_t channel_signal(ChannelHandle handle, uint16_t index, bool remote) | 148 | uint16_t channel_signal(ChannelHandle handle, uint16_t index, bool remote) |
| 180 | { | 149 | { |
| 181 | - HcommCcuChannelPod channel{}; | 150 | + HcommCcuChannelEntity channel{}; |
| 182 | if (!query_channel(handle, channel)) { | 151 | if (!query_channel(handle, channel)) { |
| 183 | return UINT16_MAX; | 152 | return UINT16_MAX; |
| 184 | } | 153 | } |
| 185 | - return id_by_array(remote ? channel.remoteCkeIds : channel.localCkeIds, index); | 154 | + return id_by_array( |
| 155 | + remote ? channel.remoteEventIds : channel.localEventIds, | ||
| 156 | + remote ? channel.remoteEventNum : channel.localEventNum, index); | ||
| 186 | } | 157 | } |
| 187 | 158 | ||
| 188 | // 取远端 XN(变量槽)id,用于分析 RV 类远程 POST 的变量地址 | 159 | // 取远端 XN(变量槽)id,用于分析 RV 类远程 POST 的变量地址 |
| 189 | uint16_t channel_remote_xn(ChannelHandle handle, uint16_t index) | 160 | uint16_t channel_remote_xn(ChannelHandle handle, uint16_t index) |
| 190 | { | 161 | { |
| 191 | - HcommCcuChannelPod channel{}; | 162 | + HcommCcuChannelEntity channel{}; |
| 192 | if (!query_channel(handle, channel)) { | 163 | if (!query_channel(handle, channel)) { |
| 193 | return UINT16_MAX; | 164 | return UINT16_MAX; |
| 194 | } | 165 | } |
| 195 | - return id_by_array(channel.remoteXnIds, index); | 166 | + return id_by_array(channel.remoteVarIds, channel.remoteVarNum, index); |
| 196 | } | 167 | } |
| 197 | 168 | ||
| 198 | // 按指令编号找到这条指令属于哪条 REP:先在整个内核里找, | 169 | // 按指令编号找到这条指令属于哪条 REP:先在整个内核里找, |
| @@ -211,7 +182,7 @@ private: | |||
| 211 | // 发 MISSION 记录:说明这次诊断的任务和当前指令编号 | 182 | // 发 MISSION 记录:说明这次诊断的任务和当前指令编号 |
| 212 | void emit_mission(uint16_t instruction_id) | 183 | void emit_mission(uint16_t instruction_id) |
| 213 | { | 184 | { |
| 214 | - HcommCcuDfxRecordPod record{}; | 185 | + HcommCcuDfxRecord record{}; |
| 215 | record.type = HCOMM_CCU_DFX_RECORD_MISSION; | 186 | record.type = HCOMM_CCU_DFX_RECORD_MISSION; |
| 216 | record.repType = static_cast<int32_t>(ccu_rep_type::base); | 187 | record.repType = static_cast<int32_t>(ccu_rep_type::base); |
| 217 | record.dieId = static_cast<uint8_t>(request_.dieId); | 188 | record.dieId = static_cast<uint8_t>(request_.dieId); |
| @@ -226,7 +197,7 @@ private: | |||
| 226 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_WAIT_SIGNAL); | 197 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_WAIT_SIGNAL); |
| 227 | record.msg.waitSignal.signalId = signal; | 198 | record.msg.waitSignal.signalId = signal; |
| 228 | record.msg.waitSignal.signalMask = mask; | 199 | record.msg.waitSignal.signalMask = mask; |
| 229 | - record.msg.waitSignal.signalValue = read_value ? static_cast<uint16_t>(resource(ops_.ckeQuery, signal)) : 0; | 200 | + record.msg.waitSignal.signalValue = read_value ? static_cast<uint16_t>(resource(nullptr, signal)) : 0; |
| 230 | // 用不到的通道位置先填无效值 UINT16_MAX,方便 hcomm 那边识别 | 201 | // 用不到的通道位置先填无效值 UINT16_MAX,方便 hcomm 那边识别 |
| 231 | std::fill(std::begin(record.msg.waitSignal.channelId), std::end(record.msg.waitSignal.channelId), UINT16_MAX); | 202 | std::fill(std::begin(record.msg.waitSignal.channelId), std::end(record.msg.waitSignal.channelId), UINT16_MAX); |
| 232 | emit(record); | 203 | emit(record); |
| @@ -243,7 +214,7 @@ private: | |||
| 243 | record.msg.waitSignal.signalId = channel_signal(rep->get_channel(), rep->get_sem_index(), !read_value); | 214 | record.msg.waitSignal.signalId = channel_signal(rep->get_channel(), rep->get_sem_index(), !read_value); |
| 244 | record.msg.waitSignal.signalMask = rep->get_mask(); | 215 | record.msg.waitSignal.signalMask = rep->get_mask(); |
| 245 | record.msg.waitSignal.signalValue = | 216 | record.msg.waitSignal.signalValue = |
| 246 | - read_value ? static_cast<uint16_t>(resource(ops_.ckeQuery, record.msg.waitSignal.signalId)) : 0; | 217 | + read_value ? static_cast<uint16_t>(resource(nullptr, record.msg.waitSignal.signalId)) : 0; |
| 247 | std::fill( | 218 | std::fill( |
| 248 | std::begin(record.msg.waitSignal.channelId) + 1, std::end(record.msg.waitSignal.channelId), UINT16_MAX); | 219 | std::begin(record.msg.waitSignal.channelId) + 1, std::end(record.msg.waitSignal.channelId), UINT16_MAX); |
| 249 | emit(record); | 220 | emit(record); |
| @@ -261,7 +232,7 @@ private: | |||
| 261 | record.msg.waitSignal.signalMask = rep->get_mask(); | 232 | record.msg.waitSignal.signalMask = rep->get_mask(); |
| 262 | // 变量编号存在对端通道的 XN 数组里,变量的当前值再从 XN 里查出来 | 233 | // 变量编号存在对端通道的 XN 数组里,变量的当前值再从 XN 里查出来 |
| 263 | record.msg.waitSignal.paramId = channel_remote_xn(rep->get_channel(), rep->get_param_index()); | 234 | record.msg.waitSignal.paramId = channel_remote_xn(rep->get_channel(), rep->get_param_index()); |
| 264 | - record.msg.waitSignal.paramValue = resource(ops_.xnQuery, rep->get_param().id()); | 235 | + record.msg.waitSignal.paramValue = resource(nullptr, rep->get_param().id()); |
| 265 | emit(record); | 236 | emit(record); |
| 266 | } | 237 | } |
| 267 | 238 | ||
| @@ -271,11 +242,11 @@ private: | |||
| 271 | { | 242 | { |
| 272 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_TRANSFER); | 243 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_TRANSFER); |
| 273 | // 地址从 GSA 查、token 和长度从 XN 查,把资源编号还原成真正的数值 | 244 | // 地址从 GSA 查、token 和长度从 XN 查,把资源编号还原成真正的数值 |
| 274 | - record.msg.transMem.locAddr = resource(ops_.gsaQuery, rep->get_loc_addr_id()); | 245 | + record.msg.transMem.locAddr = resource(nullptr, rep->get_loc_addr_id()); |
| 275 | - record.msg.transMem.locToken = resource(ops_.xnQuery, rep->get_loc_token_id()); | 246 | + record.msg.transMem.locToken = resource(nullptr, rep->get_loc_token_id()); |
| 276 | - record.msg.transMem.rmtAddr = resource(ops_.gsaQuery, rep->get_rem_addr_id()); | 247 | + record.msg.transMem.rmtAddr = resource(nullptr, rep->get_rem_addr_id()); |
| 277 | - record.msg.transMem.rmtToken = resource(ops_.xnQuery, rep->get_rem_token_id()); | 248 | + record.msg.transMem.rmtToken = resource(nullptr, rep->get_rem_token_id()); |
| 278 | - record.msg.transMem.len = resource(ops_.xnQuery, rep->get_len_id()); | 249 | + record.msg.transMem.len = resource(nullptr, rep->get_len_id()); |
| 279 | record.msg.transMem.signalId = rep->get_sem_id(); | 250 | record.msg.transMem.signalId = rep->get_sem_id(); |
| 280 | record.msg.transMem.signalMask = rep->get_mask(); | 251 | record.msg.transMem.signalMask = rep->get_mask(); |
| 281 | set_channel(rep->get_channel(), record.msg.transMem.channelId, record.msg.transMem.channelHandle); | 252 | set_channel(rep->get_channel(), record.msg.transMem.channelId, record.msg.transMem.channelHandle); |
| @@ -290,11 +261,11 @@ private: | |||
| 290 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_loc_cpy>(base); | 261 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_loc_cpy>(base); |
| 291 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_TRANSFER); | 262 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_TRANSFER); |
| 292 | // 本地复制也复用 TRANSFER 记录的格式(所谓“对端”其实还是本端内存) | 263 | // 本地复制也复用 TRANSFER 记录的格式(所谓“对端”其实还是本端内存) |
| 293 | - record.msg.transMem.locAddr = resource(ops_.gsaQuery, rep->get_src_addr_id()); | 264 | + record.msg.transMem.locAddr = resource(nullptr, rep->get_src_addr_id()); |
| 294 | - record.msg.transMem.locToken = resource(ops_.xnQuery, rep->get_src_token_id()); | 265 | + record.msg.transMem.locToken = resource(nullptr, rep->get_src_token_id()); |
| 295 | - record.msg.transMem.rmtAddr = resource(ops_.gsaQuery, rep->get_dst_addr_id()); | 266 | + record.msg.transMem.rmtAddr = resource(nullptr, rep->get_dst_addr_id()); |
| 296 | - record.msg.transMem.rmtToken = resource(ops_.xnQuery, rep->get_dst_token_id()); | 267 | + record.msg.transMem.rmtToken = resource(nullptr, rep->get_dst_token_id()); |
| 297 | - record.msg.transMem.len = resource(ops_.xnQuery, rep->get_len_id()); | 268 | + record.msg.transMem.len = resource(nullptr, rep->get_len_id()); |
| 298 | record.msg.transMem.signalId = rep->get_sem_id(); | 269 | record.msg.transMem.signalId = rep->get_sem_id(); |
| 299 | record.msg.transMem.signalMask = rep->get_mask(); | 270 | record.msg.transMem.signalMask = rep->get_mask(); |
| 300 | record.msg.transMem.dataType = rep->get_data_type(); | 271 | record.msg.transMem.dataType = rep->get_data_type(); |
| @@ -308,9 +279,9 @@ private: | |||
| 308 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_read>(base); | 279 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_read>(base); |
| 309 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); | 280 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); |
| 310 | record.msg.bufTransMem.bufId = rep->get_dst_addr_id() & 0x7fffU; // 去掉 bit15(IO Die 标志位),只留缓冲区编号 | 281 | record.msg.bufTransMem.bufId = rep->get_dst_addr_id() & 0x7fffU; // 去掉 bit15(IO Die 标志位),只留缓冲区编号 |
| 311 | - record.msg.bufTransMem.addr = resource(ops_.gsaQuery, rep->get_src_addr_id()); | 282 | + record.msg.bufTransMem.addr = resource(nullptr, rep->get_src_addr_id()); |
| 312 | - record.msg.bufTransMem.token = resource(ops_.xnQuery, rep->get_src_token_id()); | 283 | + record.msg.bufTransMem.token = resource(nullptr, rep->get_src_token_id()); |
| 313 | - record.msg.bufTransMem.len = resource(ops_.xnQuery, rep->get_len_id()); | 284 | + record.msg.bufTransMem.len = resource(nullptr, rep->get_len_id()); |
| 314 | record.msg.bufTransMem.signalId = rep->get_sem_id(); | 285 | record.msg.bufTransMem.signalId = rep->get_sem_id(); |
| 315 | record.msg.bufTransMem.signalMask = rep->get_mask(); | 286 | record.msg.bufTransMem.signalMask = rep->get_mask(); |
| 316 | set_channel(rep->get_channel(), record.msg.bufTransMem.channelId, record.msg.bufTransMem.channelHandle); | 287 | set_channel(rep->get_channel(), record.msg.bufTransMem.channelId, record.msg.bufTransMem.channelHandle); |
| @@ -323,9 +294,9 @@ private: | |||
| 323 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_write>(base); | 294 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_write>(base); |
| 324 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); | 295 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); |
| 325 | record.msg.bufTransMem.bufId = rep->get_src_id() & 0x7fffU; // 同上:去掉 bit15 标志位 | 296 | record.msg.bufTransMem.bufId = rep->get_src_id() & 0x7fffU; // 同上:去掉 bit15 标志位 |
| 326 | - record.msg.bufTransMem.addr = resource(ops_.gsaQuery, rep->get_dst_addr_id()); | 297 | + record.msg.bufTransMem.addr = resource(nullptr, rep->get_dst_addr_id()); |
| 327 | - record.msg.bufTransMem.token = resource(ops_.xnQuery, rep->get_dst_token_id()); | 298 | + record.msg.bufTransMem.token = resource(nullptr, rep->get_dst_token_id()); |
| 328 | - record.msg.bufTransMem.len = resource(ops_.xnQuery, rep->get_len_id()); | 299 | + record.msg.bufTransMem.len = resource(nullptr, rep->get_len_id()); |
| 329 | record.msg.bufTransMem.signalId = rep->get_sem_id(); | 300 | record.msg.bufTransMem.signalId = rep->get_sem_id(); |
| 330 | record.msg.bufTransMem.signalMask = rep->get_mask(); | 301 | record.msg.bufTransMem.signalMask = rep->get_mask(); |
| 331 | set_channel(rep->get_channel(), record.msg.bufTransMem.channelId, record.msg.bufTransMem.channelHandle); | 302 | set_channel(rep->get_channel(), record.msg.bufTransMem.channelId, record.msg.bufTransMem.channelHandle); |
| @@ -338,9 +309,9 @@ private: | |||
| 338 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_loc_read>(base); | 309 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_loc_read>(base); |
| 339 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); | 310 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); |
| 340 | record.msg.bufTransMem.bufId = rep->get_dst_id() & 0x7fffU; // 同上:去掉 bit15 标志位 | 311 | record.msg.bufTransMem.bufId = rep->get_dst_id() & 0x7fffU; // 同上:去掉 bit15 标志位 |
| 341 | - record.msg.bufTransMem.addr = resource(ops_.gsaQuery, rep->get_src_addr_id()); | 312 | + record.msg.bufTransMem.addr = resource(nullptr, rep->get_src_addr_id()); |
| 342 | - record.msg.bufTransMem.token = resource(ops_.xnQuery, rep->get_src_token_id()); | 313 | + record.msg.bufTransMem.token = resource(nullptr, rep->get_src_token_id()); |
| 343 | - record.msg.bufTransMem.len = resource(ops_.xnQuery, rep->get_len_id()); | 314 | + record.msg.bufTransMem.len = resource(nullptr, rep->get_len_id()); |
| 344 | record.msg.bufTransMem.signalId = rep->get_sem_id(); | 315 | record.msg.bufTransMem.signalId = rep->get_sem_id(); |
| 345 | record.msg.bufTransMem.signalMask = rep->get_mask(); | 316 | record.msg.bufTransMem.signalMask = rep->get_mask(); |
| 346 | record.msg.bufTransMem.channelId = UINT16_MAX; | 317 | record.msg.bufTransMem.channelId = UINT16_MAX; |
| @@ -353,9 +324,9 @@ private: | |||
| 353 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_loc_write>(base); | 324 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_buf_loc_write>(base); |
| 354 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); | 325 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_BUFFER_TRANSFER); |
| 355 | record.msg.bufTransMem.bufId = rep->get_src_addr_id() & 0x7fffU; // 同上:去掉 bit15 标志位 | 326 | record.msg.bufTransMem.bufId = rep->get_src_addr_id() & 0x7fffU; // 同上:去掉 bit15 标志位 |
| 356 | - record.msg.bufTransMem.addr = resource(ops_.gsaQuery, rep->get_dst_addr_id()); | 327 | + record.msg.bufTransMem.addr = resource(nullptr, rep->get_dst_addr_id()); |
| 357 | - record.msg.bufTransMem.token = resource(ops_.xnQuery, rep->get_dst_token_id()); | 328 | + record.msg.bufTransMem.token = resource(nullptr, rep->get_dst_token_id()); |
| 358 | - record.msg.bufTransMem.len = resource(ops_.xnQuery, rep->get_len_id()); | 329 | + record.msg.bufTransMem.len = resource(nullptr, rep->get_len_id()); |
| 359 | record.msg.bufTransMem.signalId = rep->get_sem_id(); | 330 | record.msg.bufTransMem.signalId = rep->get_sem_id(); |
| 360 | record.msg.bufTransMem.signalMask = rep->get_mask(); | 331 | record.msg.bufTransMem.signalMask = rep->get_mask(); |
| 361 | record.msg.bufTransMem.channelId = UINT16_MAX; | 332 | record.msg.bufTransMem.channelId = UINT16_MAX; |
| @@ -397,13 +368,9 @@ private: | |||
| 397 | uint64_t value; | 368 | uint64_t value; |
| 398 | loop_xm fields; | 369 | loop_xm fields; |
| 399 | } loop{}; | 370 | } loop{}; |
| 400 | - loop.value = resource(ops_.xnQuery, rep->get_loop_param()->id()); | 371 | + loop.value = resource(nullptr, rep->get_loop_param()->id()); |
| 401 | - HcommCcuLoopContextPod context{}; | 372 | + // loop 上下文硬件现场查询未注入(ascCustom 槽 3-7 预留),降级填零 |
| 402 | - if (ops_.loopContextQuery == nullptr || | 373 | + HcommCcuLoopContext context{}; |
| 403 | - ops_.loopContextQuery(request_.deviceId, request_.dieId, loop.fields.loop_ctx_id, &context) != 0) { | ||
| 404 | - first_error_ = first_error_ == 0 ? static_cast<int32_t>(CcuResult::CCU_E_INTERNAL) : first_error_; | ||
| 405 | - return; | ||
| 406 | - } | ||
| 407 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_LOOP); | 374 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_LOOP); |
| 408 | record.msg.loop.startInstrId = rep->get_loop_block()->start_instr_id(); | 375 | record.msg.loop.startInstrId = rep->get_loop_block()->start_instr_id(); |
| 409 | record.msg.loop.endInstrId = record.msg.loop.startInstrId + rep->get_loop_block()->instr_count() - 1; | 376 | record.msg.loop.endInstrId = record.msg.loop.startInstrId + rep->get_loop_block()->instr_count() - 1; |
| @@ -427,7 +394,7 @@ private: | |||
| 427 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_loop_group_bundle>(base); | 394 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_loop_group_bundle>(base); |
| 428 | // 循环组参数也在 XN 变量里(组内循环数、展开偏移、展开次数) | 395 | // 循环组参数也在 XN 变量里(组内循环数、展开偏移、展开次数) |
| 429 | loop_group_xn group{}; | 396 | loop_group_xn group{}; |
| 430 | - group.value = resource(ops_.xnQuery, rep->get_offset_param().id()); | 397 | + group.value = resource(nullptr, rep->get_offset_param().id()); |
| 431 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_LOOP_GROUP); | 398 | auto record = make_base_record(base, HCOMM_CCU_DFX_RECORD_LOOP_GROUP); |
| 432 | record.msg.loopGroup.startLoopInsId = rep->get_start_loop_instr_id(); | 399 | record.msg.loopGroup.startLoopInsId = rep->get_start_loop_instr_id(); |
| 433 | record.msg.loopGroup.loopInsCnt = group.fields.loop_ins_cnt; | 400 | record.msg.loopGroup.loopInsCnt = group.fields.loop_ins_cnt; |
| @@ -454,7 +421,7 @@ private: | |||
| 454 | } | 421 | } |
| 455 | case ccu_rep_type::loc_wait_event: { | 422 | case ccu_rep_type::loc_wait_event: { |
| 456 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_loc_wait_event>(base); | 423 | auto rep = std::static_pointer_cast<ccu_rep::ccu_rep_loc_wait_event>(base); |
| 457 | - const uint16_t actual = static_cast<uint16_t>(resource(ops_.ckeQuery, rep->get_event_id())); | 424 | + const uint16_t actual = static_cast<uint16_t>(resource(nullptr, rep->get_event_id())); |
| 458 | emit_wait(base, rep->get_event_id(), rep->get_mask(), true); | 425 | emit_wait(base, rep->get_event_id(), rep->get_mask(), true); |
| 459 | for (uint32_t bit = 1; bit != 0 && bit <= UINT16_MAX; bit <<= 1U) { | 426 | for (uint32_t bit = 1; bit != 0 && bit <= UINT16_MAX; bit <<= 1U) { |
| 460 | // 还有信号位没被置上,故障很可能就卡在等这些信号上,把它们依赖的 REP 也补发出来 | 427 | // 还有信号位没被置上,故障很可能就卡在等这些信号上,把它们依赖的 REP 也补发出来 |
| @@ -518,10 +485,10 @@ private: | |||
| 518 | } | 485 | } |
| 519 | } | 486 | } |
| 520 | 487 | ||
| 521 | - const HcommCcuDfxRequestPod& request_; | 488 | + const HcommCcuDfxRequest& request_; |
| 522 | HcommCcuDfxEmitFn emit_; | 489 | HcommCcuDfxEmitFn emit_; |
| 523 | void* context_; | 490 | void* context_; |
| 524 | - const HcommCcuControlOpsPod& ops_; | 491 | + const uint64_t* asc_custom_; // ascCustom 槽位数组(槽 0: getChannelEntity;硬件现场查询槽未注入) |
| 525 | int32_t first_error_{0}; | 492 | int32_t first_error_{0}; |
| 526 | }; | 493 | }; |
| 527 | 494 | ||
| @@ -530,7 +497,7 @@ private: | |||
| 530 | // 诊断入口(hcomm 控制面在任务异常时跨 SO 调过来):先校验参数, | 497 | // 诊断入口(hcomm 控制面在任务异常时跨 SO 调过来):先校验参数, |
| 531 | // 再取本设备的内核管理器和 hcomm 注入的查询接口,交给 DfxBuilder 生成全部记录, | 498 | // 再取本设备的内核管理器和 hcomm 注入的查询接口,交给 DfxBuilder 生成全部记录, |
| 532 | // 逐条经 emit 回调发出;出错一律返回内部错误,参数不对返回参数错误 | 499 | // 逐条经 emit 回调发出;出错一律返回内部错误,参数不对返回参数错误 |
| 533 | -int32_t asccomm_ccu_diagnose(const HcommCcuDfxRequestPod* request, HcommCcuDfxEmitFn emit, void* context) | 500 | +int32_t asccomm_ccu_diagnose(const HcommCcuDfxRequest* request, HcommCcuDfxEmitFn emit, void* context) |
| 534 | { | 501 | { |
| 535 | if (request == nullptr || emit == nullptr || request->deviceId < 0 || request->kernelHandle == 0) { | 502 | if (request == nullptr || emit == nullptr || request->deviceId < 0 || request->kernelHandle == 0) { |
| 536 | return static_cast<int32_t>(CcuResult::CCU_E_PARA); | 503 | return static_cast<int32_t>(CcuResult::CCU_E_PARA); |
| @@ -48,7 +48,7 @@ using ccu_rep::ccu_ins_generater_base; | |||
| 48 | using ccu_rep::ccu_ins_generater_v1; | 48 | using ccu_rep::ccu_ins_generater_v1; |
| 49 | 49 | ||
| 50 | template <typename t> | 50 | template <typename t> |
| 51 | -t ccu_kernel::create_res_assist(std::array<std::vector<t>, ccu_max_iodie_num>& res_record) | 51 | +t ccu_kernel::create_res_assist(std::array<std::vector<t>, CCU_MAX_IODIE_NUM>& res_record) |
| 52 | { | 52 | { |
| 53 | // kernel确认die之前默认为0,需要刷新资源 | 53 | // kernel确认die之前默认为0,需要刷新资源 |
| 54 | // 确认die之后按实际使用die分配资源 | 54 | // 确认die之后按实际使用die分配资源 |
| @@ -61,7 +61,7 @@ t ccu_kernel::create_res_assist(std::array<std::vector<t>, ccu_max_iodie_num>& r | |||
| 61 | 61 | ||
| 62 | template <typename t> | 62 | template <typename t> |
| 63 | std::vector<t> ccu_kernel::create_block_res_assist( | 63 | std::vector<t> ccu_kernel::create_block_res_assist( |
| 64 | - const uint32_t count, std::array<std::vector<t>, ccu_max_iodie_num>& res_record) | 64 | + const uint32_t count, std::array<std::vector<t>, CCU_MAX_IODIE_NUM>& res_record) |
| 65 | { | 65 | { |
| 66 | constexpr uint16_t ccu_block_res_id_base = 0x1000; // block 批量分配资源 id 基址,与单资源 id 区间隔离便于 DFX 定位 | 66 | constexpr uint16_t ccu_block_res_id_base = 0x1000; // block 批量分配资源 id 基址,与单资源 id 区间隔离便于 DFX 定位 |
| 67 | std::vector<t> block; | 67 | std::vector<t> block; |
| @@ -90,7 +90,7 @@ static HcclResult get_die_id_by_channels( | |||
| 90 | const std::unordered_set<ChannelHandle>& channels, uint32_t valid_die_mask, uint32_t& die_id) | 90 | const std::unordered_set<ChannelHandle>& channels, uint32_t valid_die_mask, uint32_t& die_id) |
| 91 | { | 91 | { |
| 92 | if (channels.empty()) { | 92 | if (channels.empty()) { |
| 93 | - for (uint32_t die = 0; die < ccu_max_iodie_num; die++) { | 93 | + for (uint32_t die = 0; die < CCU_MAX_IODIE_NUM; die++) { |
| 94 | if ((valid_die_mask & (1U << die)) != 0) { | 94 | if ((valid_die_mask & (1U << die)) != 0) { |
| 95 | die_id = die; | 95 | die_id = die; |
| 96 | return HcclResult::HCCL_SUCCESS; | 96 | return HcclResult::HCCL_SUCCESS; |
| @@ -204,8 +204,8 @@ HcclResult ccu_kernel::apply_die_from_channels(uint32_t valid_die_mask) | |||
| 204 | uint32_t die_id{0}; | 204 | uint32_t die_id{0}; |
| 205 | CHK_RET(get_die_id_by_channels(channels_, valid_die_mask, die_id)); | 205 | CHK_RET(get_die_id_by_channels(channels_, valid_die_mask, die_id)); |
| 206 | CHK_PRT_RET( | 206 | CHK_PRT_RET( |
| 207 | - die_id >= ccu_max_iodie_num, | 207 | + die_id >= CCU_MAX_IODIE_NUM, |
| 208 | - HCCL_ERROR("[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", __func__, die_id, ccu_max_iodie_num), | 208 | + HCCL_ERROR("[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", __func__, die_id, CCU_MAX_IODIE_NUM), |
| 209 | HcclResult::HCCL_E_PARA); | 209 | HcclResult::HCCL_E_PARA); |
| 210 | set_die_id(die_id); | 210 | set_die_id(die_id); |
| 211 | move_resources_to_die(res_, die_id); | 211 | move_resources_to_die(res_, die_id); |
| @@ -217,9 +217,9 @@ HcclResult ccu_kernel::apply_die_from_channels(uint32_t valid_die_mask) | |||
| 217 | HcclResult ccu_kernel::validate_and_apply_die(const uint32_t target_die_id, uint32_t valid_die_mask) | 217 | HcclResult ccu_kernel::validate_and_apply_die(const uint32_t target_die_id, uint32_t valid_die_mask) |
| 218 | { | 218 | { |
| 219 | CHK_PRT_RET( | 219 | CHK_PRT_RET( |
| 220 | - target_die_id >= ccu_max_iodie_num, | 220 | + target_die_id >= CCU_MAX_IODIE_NUM, |
| 221 | HCCL_ERROR( | 221 | HCCL_ERROR( |
| 222 | - "[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", __func__, target_die_id, ccu_max_iodie_num), | 222 | + "[CcuKernel][%s] failed, dieId[%u] should be less than [%u].", __func__, target_die_id, CCU_MAX_IODIE_NUM), |
| 223 | HcclResult::HCCL_E_PARA); | 223 | HcclResult::HCCL_E_PARA); |
| 224 | 224 | ||
| 225 | CHK_PRT_RET( | 225 | CHK_PRT_RET( |
| @@ -2607,13 +2607,13 @@ void ccu_kernel::set_instr_id(uint32_t instr_id) { instr_info_.start_instr_id = | |||
| 2607 | 2607 | ||
| 2608 | uint32_t ccu_kernel::get_instr_id() const { return instr_info_.start_instr_id; } | 2608 | uint32_t ccu_kernel::get_instr_id() const { return instr_info_.start_instr_id; } |
| 2609 | 2609 | ||
| 2610 | -void ccu_kernel::set_instruction_resource(const HcommCcuResRangePod& range) | 2610 | +void ccu_kernel::set_instruction_resource(const asc_ccu_res_range& range) |
| 2611 | { | 2611 | { |
| 2612 | instruction_resource_ = range; | 2612 | instruction_resource_ = range; |
| 2613 | has_instruction_resource_ = true; | 2613 | has_instruction_resource_ = true; |
| 2614 | } | 2614 | } |
| 2615 | 2615 | ||
| 2616 | -bool ccu_kernel::get_instruction_resource(HcommCcuResRangePod& range) const | 2616 | +bool ccu_kernel::get_instruction_resource(asc_ccu_res_range& range) const |
| 2617 | { | 2617 | { |
| 2618 | if (!has_instruction_resource_) { | 2618 | if (!has_instruction_resource_) { |
| 2619 | return false; | 2619 | return false; |
| @@ -32,8 +32,7 @@ | |||
| 32 | #include "hcomm/resource/representation/interface/ccu_loopcall_v1.h" | 32 | #include "hcomm/resource/representation/interface/ccu_loopcall_v1.h" |
| 33 | 33 | ||
| 34 | // 类型(HcclResult 等)统一取自 hcomm 包内 hcomm_types.h,避免耦合 hccl 私有定义 | 34 | // 类型(HcclResult 等)统一取自 hcomm 包内 hcomm_types.h,避免耦合 hccl 私有定义 |
| 35 | -#include "hcomm/hcomm_ccu_channel.h" | 35 | +#include "hcomm/hcomm_ccu_resource.h" |
| 36 | -#include "hcomm/hcomm_ccu_res.h" | ||
| 37 | #include "hcomm/hcomm_types.h" | 36 | #include "hcomm/hcomm_types.h" |
| 38 | #include "hcomm/resource/representation/interface/ccu_datatype_v1.h" | 37 | #include "hcomm/resource/representation/interface/ccu_datatype_v1.h" |
| 39 | #include "hcomm/resource/representation/interface/ccu_interface_assist_v1.h" | 38 | #include "hcomm/resource/representation/interface/ccu_interface_assist_v1.h" |
| @@ -91,8 +90,8 @@ public: | |||
| 91 | uint32_t get_instr_count(); | 90 | uint32_t get_instr_count(); |
| 92 | uint32_t get_rep_need_to_add_latency() const; | 91 | uint32_t get_rep_need_to_add_latency() const; |
| 93 | void set_ccu_instr_info(const ccu_rep::ccu_instr_info& instr_info); | 92 | void set_ccu_instr_info(const ccu_rep::ccu_instr_info& instr_info); |
| 94 | - void set_instruction_resource(const HcommCcuResRangePod& range); | 93 | + void set_instruction_resource(const asc_ccu_res_range& range); |
| 95 | - bool get_instruction_resource(HcommCcuResRangePod& range) const; | 94 | + bool get_instruction_resource(asc_ccu_res_range& range) const; |
| 96 | void clear_instruction_resource(); | 95 | void clear_instruction_resource(); |
| 97 | 96 | ||
| 98 | CcuResult gene_task_params(const uint64_t* task_args, uint32_t arg_num, std::vector<ccu_task_param>& task_params); | 97 | CcuResult gene_task_params(const uint64_t* task_args, uint32_t arg_num, std::vector<ccu_task_param>& task_params); |
| @@ -480,10 +479,10 @@ protected: | |||
| 480 | 479 | ||
| 481 | private: | 480 | private: |
| 482 | template <typename t> | 481 | template <typename t> |
| 483 | - t create_res_assist(std::array<std::vector<t>, ccu_max_iodie_num>& res_record); | 482 | + t create_res_assist(std::array<std::vector<t>, CCU_MAX_IODIE_NUM>& res_record); |
| 484 | template <typename t> | 483 | template <typename t> |
| 485 | std::vector<t> create_block_res_assist( | 484 | std::vector<t> create_block_res_assist( |
| 486 | - const uint32_t count, std::array<std::vector<t>, ccu_max_iodie_num>& res_record); | 485 | + const uint32_t count, std::array<std::vector<t>, CCU_MAX_IODIE_NUM>& res_record); |
| 487 | 486 | ||
| 488 | private: | 487 | private: |
| 489 | ccu_rep_resource res_{}; | 488 | ccu_rep_resource res_{}; |
| @@ -493,7 +492,7 @@ private: | |||
| 493 | 492 | ||
| 494 | ccu_rep::ccu_instr_info instr_info_{}; | 493 | ccu_rep::ccu_instr_info instr_info_{}; |
| 495 | bool has_instruction_resource_{false}; | 494 | bool has_instruction_resource_{false}; |
| 496 | - HcommCcuResRangePod instruction_resource_{}; | 495 | + asc_ccu_res_range instruction_resource_{}; |
| 497 | 496 | ||
| 498 | uint32_t load_arg_index_{0}; | 497 | uint32_t load_arg_index_{0}; |
| 499 | 498 | ||
| @@ -24,7 +24,7 @@ | |||
| 24 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" | 24 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" |
| 25 | #include "hcomm/resource/representation/reps/common/ccu_rep_type_v1.h" | 25 | #include "hcomm/resource/representation/reps/common/ccu_rep_type_v1.h" |
| 26 | 26 | ||
| 27 | -#include "hcomm/hcomm_ccu_control.h" | 27 | +#include "hcomm/hcomm_ccu_resource.h" |
| 28 | 28 | ||
| 29 | #include "hcomm/common/ccu_log.h" | 29 | #include "hcomm/common/ccu_log.h" |
| 30 | #include "hcomm/resource/common/ccu_kernel_func.h" | 30 | #include "hcomm/resource/common/ccu_kernel_func.h" |
| @@ -65,7 +65,7 @@ CcuResult build_translator_resource_request(uint32_t die_id, uint32_t ccu_versio | |||
| 65 | 65 | ||
| 66 | CcuResult clear_kernel_instruction_resource(ccu_kernel& kernel) | 66 | CcuResult clear_kernel_instruction_resource(ccu_kernel& kernel) |
| 67 | { | 67 | { |
| 68 | - HcommCcuResRangePod range{}; | 68 | + asc_ccu_res_range range{}; |
| 69 | if (!kernel.get_instruction_resource(range)) { | 69 | if (!kernel.get_instruction_resource(range)) { |
| 70 | return CcuResult::CCU_SUCCESS; | 70 | return CcuResult::CCU_SUCCESS; |
| 71 | } | 71 | } |
| @@ -75,21 +75,14 @@ CcuResult clear_kernel_instruction_resource(ccu_kernel& kernel) | |||
| 75 | 75 | ||
| 76 | } // namespace | 76 | } // namespace |
| 77 | 77 | ||
| 78 | +static size_t compute_kernel_instr_region_size(ccu_kernel& kernel); // 定义位于本文件下方 | ||
| 79 | + | ||
| 78 | ccu_kernel_mgr::~ccu_kernel_mgr() | 80 | ccu_kernel_mgr::~ccu_kernel_mgr() |
| 79 | { | 81 | { |
| 80 | if (!initialized_flag_) { | 82 | if (!initialized_flag_) { |
| 81 | return; | 83 | return; |
| 82 | } | 84 | } |
| 83 | 85 | ||
| 84 | - if (instruction_load_dev_mem_) { | ||
| 85 | - HCCL_RUN_INFO( | ||
| 86 | - "[CcuKernelMgr][~CcuKernelMgr]: deviceLogicId[%d], free addr[%p]", dev_logic_id_, | ||
| 87 | - instruction_load_dev_mem_); | ||
| 88 | - (void)aclrtFree(instruction_load_dev_mem_); | ||
| 89 | - instruction_load_dev_mem_ = nullptr; | ||
| 90 | - instruction_load_dev_mem_size_ = 0; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | (void)deinit(); | 86 | (void)deinit(); |
| 94 | } | 87 | } |
| 95 | 88 | ||
| @@ -121,17 +114,20 @@ HcclResult ccu_kernel_mgr::init() | |||
| 121 | CcuResult ccu_kernel_mgr::configure(asc_ccu_res_snapshot& res_pack) | 114 | CcuResult ccu_kernel_mgr::configure(asc_ccu_res_snapshot& res_pack) |
| 122 | { | 115 | { |
| 123 | std::unique_lock<std::mutex> lock(kernel_map_mutex_); | 116 | std::unique_lock<std::mutex> lock(kernel_map_mutex_); |
| 124 | - dev_logic_id_ = res_pack.get_device_logic_id(); | 117 | + dev_logic_id_ = asc::get_current_ccu_device_logic_id(); // Instance 不再携带设备号,定档口径 |
| 125 | translators_.clear(); | 118 | translators_.clear(); |
| 126 | reference_mgrs_.clear(); | 119 | reference_mgrs_.clear(); |
| 127 | ccu_version_ = res_pack.get_ccu_version(); | 120 | ccu_version_ = res_pack.get_ccu_version(); |
| 128 | - control_ops_ = res_pack.get_control_ops(); | 121 | + const uint64_t* asc_custom = res_pack.get_control_ops(); |
| 122 | + for (uint32_t i = 0; i < HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT; ++i) { | ||
| 123 | + control_ops_[i] = asc_custom[i]; | ||
| 124 | + } | ||
| 129 | ccu_rep::ccu_rep_translator::set_ccu_version(ccu_version_); | 125 | ccu_rep::ccu_rep_translator::set_ccu_version(ccu_version_); |
| 130 | for (uint32_t die_id = 0; die_id < HCOMM_CCU_MAX_DIE_NUM; ++die_id) { | 126 | for (uint32_t die_id = 0; die_id < HCOMM_CCU_MAX_DIE_NUM; ++die_id) { |
| 131 | if ((res_pack.get_valid_die_mask() & (1U << die_id)) == 0) { | 127 | if ((res_pack.get_valid_die_mask() & (1U << die_id)) == 0) { |
| 132 | continue; | 128 | continue; |
| 133 | } | 129 | } |
| 134 | - const HcommCcuDieMetadataPod* metadata = res_pack.get_die_metadata(die_id); | 130 | + const HcommCcuDieMetadata* metadata = res_pack.get_die_metadata(die_id); |
| 135 | CCU_CHK_PTR_NULL(metadata); | 131 | CCU_CHK_PTR_NULL(metadata); |
| 136 | mission_keys_[die_id] = metadata->missionKey; | 132 | mission_keys_[die_id] = metadata->missionKey; |
| 137 | HcclResult trans_ret = instantiation_translator(static_cast<uint16_t>(die_id), res_pack); | 133 | HcclResult trans_ret = instantiation_translator(static_cast<uint16_t>(die_id), res_pack); |
| @@ -146,7 +142,7 @@ CcuResult ccu_kernel_mgr::configure(asc_ccu_res_snapshot& res_pack) | |||
| 146 | return CcuResult::CCU_SUCCESS; | 142 | return CcuResult::CCU_SUCCESS; |
| 147 | } | 143 | } |
| 148 | 144 | ||
| 149 | -const HcommCcuControlOpsPod& ccu_kernel_mgr::get_control_ops() const { return control_ops_; } | 145 | +const uint64_t* ccu_kernel_mgr::get_control_ops() const { return control_ops_; } |
| 150 | 146 | ||
| 151 | HcclResult ccu_kernel_mgr::deinit() | 147 | HcclResult ccu_kernel_mgr::deinit() |
| 152 | { | 148 | { |
| @@ -223,7 +219,7 @@ CcuResult ccu_kernel_mgr::Register( | |||
| 223 | 219 | ||
| 224 | static void dump_res_req_info(const asc_ccu_res_request& total_res) | 220 | static void dump_res_req_info(const asc_ccu_res_request& total_res) |
| 225 | { | 221 | { |
| 226 | - for (uint32_t i = 0; i < ccu_max_iodie_num; i++) { | 222 | + for (uint32_t i = 0; i < CCU_MAX_IODIE_NUM; i++) { |
| 227 | if (total_res.count[HCOMM_CCU_BATCH_RES_MS][i] != 0 || total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_MS][i] != 0 || | 223 | if (total_res.count[HCOMM_CCU_BATCH_RES_MS][i] != 0 || total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_MS][i] != 0 || |
| 228 | total_res.count[HCOMM_CCU_BATCH_RES_CKE][i] != 0 || | 224 | total_res.count[HCOMM_CCU_BATCH_RES_CKE][i] != 0 || |
| 229 | total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_CKE][i] != 0 || | 225 | total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_CKE][i] != 0 || |
| @@ -232,17 +228,17 @@ static void dump_res_req_info(const asc_ccu_res_request& total_res) | |||
| 232 | total_res.count[HCOMM_CCU_BATCH_RES_GSA][i] != 0 || | 228 | total_res.count[HCOMM_CCU_BATCH_RES_GSA][i] != 0 || |
| 233 | total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_GSA][i] != 0 || total_res.count[HCOMM_CCU_BATCH_RES_XN][i] != 0 || | 229 | total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_GSA][i] != 0 || total_res.count[HCOMM_CCU_BATCH_RES_XN][i] != 0 || |
| 234 | total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_XN][i] != 0 || | 230 | total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_XN][i] != 0 || |
| 235 | - total_res.count[HCOMM_CCU_BATCH_RES_MISSION][i] != 0 || total_res.instruction[i] != 0) { | 231 | + total_res.count[HCOMM_CCU_BATCH_RES_MISSION][i] != 0) { |
| 236 | HCCL_INFO( | 232 | HCCL_INFO( |
| 237 | "DumpResReqInfo: dieId[%u], msReq[%u], blockMsReq[%u], ckeReq[%u], blockCkeReq[%u], " | 233 | "DumpResReqInfo: dieId[%u], msReq[%u], blockMsReq[%u], ckeReq[%u], blockCkeReq[%u], " |
| 238 | "loopEngineReq[%u], blockLoopEngineReq[%u], gsaReq[%u], blockGsaReq[%u], xnReq[%u], " | 234 | "loopEngineReq[%u], blockLoopEngineReq[%u], gsaReq[%u], blockGsaReq[%u], xnReq[%u], " |
| 239 | - "blockXnReq[%u], missionReq[%u], instructionReq[%u]", | 235 | + "blockXnReq[%u], missionReq[%u]", |
| 240 | i, total_res.count[HCOMM_CCU_BATCH_RES_MS][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_MS][i], | 236 | i, total_res.count[HCOMM_CCU_BATCH_RES_MS][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_MS][i], |
| 241 | total_res.count[HCOMM_CCU_BATCH_RES_CKE][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_CKE][i], | 237 | total_res.count[HCOMM_CCU_BATCH_RES_CKE][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_CKE][i], |
| 242 | total_res.count[HCOMM_CCU_BATCH_RES_LOOP][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_LOOP][i], | 238 | total_res.count[HCOMM_CCU_BATCH_RES_LOOP][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_LOOP][i], |
| 243 | total_res.count[HCOMM_CCU_BATCH_RES_GSA][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_GSA][i], | 239 | total_res.count[HCOMM_CCU_BATCH_RES_GSA][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_GSA][i], |
| 244 | total_res.count[HCOMM_CCU_BATCH_RES_XN][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_XN][i], | 240 | total_res.count[HCOMM_CCU_BATCH_RES_XN][i], total_res.count[HCOMM_CCU_BATCH_RES_BLOCK_XN][i], |
| 245 | - total_res.count[HCOMM_CCU_BATCH_RES_MISSION][i], total_res.instruction[i]); | 241 | + total_res.count[HCOMM_CCU_BATCH_RES_MISSION][i]); |
| 246 | } | 242 | } |
| 247 | } | 243 | } |
| 248 | } | 244 | } |
| @@ -254,26 +250,41 @@ static size_t compute_kernel_instr_region_size(ccu_kernel& kernel) | |||
| 254 | static_cast<size_t>(kernel.get_rep_need_to_add_latency()) * ccu_rep::ccu_cke_raw_latency; | 250 | static_cast<size_t>(kernel.get_rep_need_to_add_latency()) * ccu_rep::ccu_cke_raw_latency; |
| 255 | } | 251 | } |
| 256 | 252 | ||
| 257 | -static CcuResult set_instr_request(std::unique_ptr<ccu_kernel>& kernel, asc_ccu_res_request& request) | 253 | +// 指令空间经 ascCustom.allocInstSpace 向 hcomm 按需申请(不再从本地 range 池切分) |
| 258 | -{ | ||
| 259 | - const size_t instr_count = compute_kernel_instr_region_size(*kernel); | ||
| 260 | - const uint32_t die_id = kernel->get_die_id(); | ||
| 261 | - return set_request_count(request.instruction[die_id], instr_count); | ||
| 262 | -} | ||
| 263 | - | ||
| 264 | static CcuResult set_kernel_instruction_resource( | 254 | static CcuResult set_kernel_instruction_resource( |
| 265 | std::unique_ptr<ccu_kernel>& kernel, const asc_ccu_res_repository& allocated) | 255 | std::unique_ptr<ccu_kernel>& kernel, const asc_ccu_res_repository& allocated) |
| 266 | { | 256 | { |
| 267 | const uint32_t die_id = kernel->get_die_id(); | 257 | const uint32_t die_id = kernel->get_die_id(); |
| 268 | - const auto& instruction_ranges = allocated.instruction[die_id]; | 258 | + const size_t instr_count = compute_kernel_instr_region_size(*kernel); |
| 269 | - if (instruction_ranges.empty()) { | 259 | + if (instr_count == 0 || instr_count > static_cast<size_t>(std::numeric_limits<uint32_t>::max())) { |
| 270 | - HCCL_ERROR("[CcuKernelMgr][%s] failed, dieId[%u] does not have instruction resource.", __func__, die_id); | 260 | + HCCL_ERROR("[CcuKernelMgr][%s] invalid instruction count[%zu], dieId[%u].", __func__, instr_count, die_id); |
| 271 | - return CcuResult::CCU_E_UNAVAIL; | 261 | + return CcuResult::CCU_E_INTERNAL; |
| 272 | } | 262 | } |
| 273 | - const HcommCcuResRangePod& ins_info = instruction_ranges.front(); | 263 | + |
| 264 | + const auto alloc_inst_space = reinterpret_cast<HcommCcuAllocInstSpaceFn>( | ||
| 265 | + get_current_ccu_control_ops()[HCOMM_CCU_ASC_CUSTOM_ALLOC_INST_SPACE]); | ||
| 266 | + CHK_PRT_RET( | ||
| 267 | + alloc_inst_space == nullptr, HCCL_ERROR("[CcuKernelMgr][%s] controlOps.allocInstSpace is nullptr.", __func__), | ||
| 268 | + CcuResult::CCU_E_INTERNAL); | ||
| 269 | + uint32_t start_inst_id = 0; | ||
| 270 | + const int32_t dev_logic_id = asc::get_current_ccu_device_logic_id(); | ||
| 271 | + const int32_t ret = alloc_inst_space(dev_logic_id, die_id, static_cast<uint32_t>(instr_count), &start_inst_id); | ||
| 272 | + CHK_PRT_RET( | ||
| 273 | + ret != 0, | ||
| 274 | + HCCL_ERROR( | ||
| 275 | + "[CcuKernelMgr][%s] allocInstSpace failed, dieId[%u] instrNum[%zu] ret[%d].", __func__, die_id, instr_count, | ||
| 276 | + ret), | ||
| 277 | + static_cast<CcuResult>(ret)); | ||
| 278 | + | ||
| 279 | + // 申请到的区间记为本地 instruction range:un_register 时仅需清记录(释放由 hcomm 池整体归还) | ||
| 280 | + asc_ccu_res_range ins_info{}; | ||
| 281 | + ins_info.resource_type = HCOMM_CCU_BATCH_RES_MISSION; // 类型仅作记录占位,指令不再回池 | ||
| 282 | + ins_info.die_id = die_id; | ||
| 283 | + ins_info.start_id = start_inst_id; | ||
| 284 | + ins_info.count = static_cast<uint32_t>(instr_count); | ||
| 274 | HCCL_INFO( | 285 | HCCL_INFO( |
| 275 | - "[CcuKernelMgr][%s]: dieId[%u], startId[%u], count[%u]", __func__, die_id, ins_info.startId, ins_info.count); | 286 | + "[CcuKernelMgr][%s]: dieId[%u], startId[%u], count[%u]", __func__, die_id, ins_info.start_id, ins_info.count); |
| 276 | - kernel->set_instr_id(ins_info.startId); | 287 | + kernel->set_instr_id(ins_info.start_id); |
| 277 | kernel->set_instruction_resource(ins_info); | 288 | kernel->set_instruction_resource(ins_info); |
| 278 | 289 | ||
| 279 | return CcuResult::CCU_SUCCESS; | 290 | return CcuResult::CCU_SUCCESS; |
| @@ -311,7 +322,6 @@ CcuResult ccu_kernel_mgr::prepare_const_value_resources() | |||
| 311 | CcuResult ccu_kernel_mgr::alloc_res(asc_ccu_res_snapshot& res_pack) | 322 | CcuResult ccu_kernel_mgr::alloc_res(asc_ccu_res_snapshot& res_pack) |
| 312 | { | 323 | { |
| 313 | asc_ccu_res_request res_req = curr_kernel_->get_resource_request(); | 324 | asc_ccu_res_request res_req = curr_kernel_->get_resource_request(); |
| 314 | - CCU_CHK_RET(set_instr_request(curr_kernel_, res_req)); | ||
| 315 | asc_ccu_res_repository remaining{}; | 325 | asc_ccu_res_repository remaining{}; |
| 316 | asc_ccu_res_repository allocated{}; | 326 | asc_ccu_res_repository allocated{}; |
| 317 | CcuResult plan_ret = plan_kernel_resources(res_pack.get_ccu_res_repo(), res_req, remaining, allocated); | 327 | CcuResult plan_ret = plan_kernel_resources(res_pack.get_ccu_res_repo(), res_req, remaining, allocated); |
| @@ -325,7 +335,7 @@ CcuResult ccu_kernel_mgr::alloc_res(asc_ccu_res_snapshot& res_pack) | |||
| 325 | 335 | ||
| 326 | res_pack.get_ccu_res_repo() = std::move(remaining); | 336 | res_pack.get_ccu_res_repo() = std::move(remaining); |
| 327 | curr_kernel_->set_res_repository(std::move(allocated)); | 337 | curr_kernel_->set_res_repository(std::move(allocated)); |
| 328 | - const HcommCcuDieMetadataPod* metadata = res_pack.get_die_metadata(curr_kernel_->get_die_id()); | 338 | + const HcommCcuDieMetadata* metadata = res_pack.get_die_metadata(curr_kernel_->get_die_id()); |
| 329 | CCU_CHK_PTR_NULL(metadata); | 339 | CCU_CHK_PTR_NULL(metadata); |
| 330 | curr_kernel_->set_mission_key(metadata->missionKey); | 340 | curr_kernel_->set_mission_key(metadata->missionKey); |
| 331 | 341 | ||
| @@ -345,7 +355,7 @@ HcclResult reset_rep_resource_template( | |||
| 345 | } | 355 | } |
| 346 | 356 | ||
| 347 | for (uint32_t j = 0; j < resource.size(); j++) { | 357 | for (uint32_t j = 0; j < resource.size(); j++) { |
| 348 | - resource[j].reset(repository[j + start_index].startId); | 358 | + resource[j].reset(repository[j + start_index].start_id); |
| 349 | } | 359 | } |
| 350 | 360 | ||
| 351 | return HcclResult::HCCL_SUCCESS; | 361 | return HcclResult::HCCL_SUCCESS; |
| @@ -355,7 +365,7 @@ static HcclResult reset_rep_resource_to_res_repository( | |||
| 355 | ccu_rep_resource& total_rep_res, const asc_ccu_res_repository& total_res_repository) | 365 | ccu_rep_resource& total_rep_res, const asc_ccu_res_repository& total_res_repository) |
| 356 | { | 366 | { |
| 357 | // 遍历translatorRepRes, 将每个rep的虚拟资源翻译到实际物理资源上 | 367 | // 遍历translatorRepRes, 将每个rep的虚拟资源翻译到实际物理资源上 |
| 358 | - for (uint32_t i = 0; i < ccu_max_iodie_num; i++) { | 368 | + for (uint32_t i = 0; i < CCU_MAX_IODIE_NUM; i++) { |
| 359 | CHK_RET(reset_rep_resource_template(total_rep_res.ccubufs[i], total_res_repository.ms[i])); | 369 | CHK_RET(reset_rep_resource_template(total_rep_res.ccubufs[i], total_res_repository.ms[i])); |
| 360 | CHK_RET(reset_rep_resource_template(total_rep_res.block_ccubufs[i], total_res_repository.block_ms[i])); | 370 | CHK_RET(reset_rep_resource_template(total_rep_res.block_ccubufs[i], total_res_repository.block_ms[i])); |
| 361 | CHK_RET(reset_rep_resource_template(total_rep_res.executor[i], total_res_repository.loop_engine[i])); | 371 | CHK_RET(reset_rep_resource_template(total_rep_res.executor[i], total_res_repository.loop_engine[i])); |
| @@ -374,7 +384,7 @@ static HcclResult reset_rep_resource_to_res_repository( | |||
| 374 | return HcclResult::HCCL_SUCCESS; | 384 | return HcclResult::HCCL_SUCCESS; |
| 375 | } | 385 | } |
| 376 | 386 | ||
| 377 | -using die_res_infos = std::array<std::vector<HcommCcuResRangePod>, ccu_max_iodie_num>; | 387 | +using die_res_infos = std::array<std::vector<asc_ccu_res_range>, CCU_MAX_IODIE_NUM>; |
| 378 | static HcclResult save_kernel_mission_info(ccu_kernel* kernel, const die_res_infos& mission_id) | 388 | static HcclResult save_kernel_mission_info(ccu_kernel* kernel, const die_res_infos& mission_id) |
| 379 | { | 389 | { |
| 380 | const uint32_t die_id = kernel->get_die_id(); | 390 | const uint32_t die_id = kernel->get_die_id(); |
| @@ -384,37 +394,37 @@ static HcclResult save_kernel_mission_info(ccu_kernel* kernel, const die_res_inf | |||
| 384 | return HcclResult::HCCL_E_INTERNAL; | 394 | return HcclResult::HCCL_E_INTERNAL; |
| 385 | } | 395 | } |
| 386 | 396 | ||
| 387 | - kernel->set_mission_id(mission_id[die_id].back().startId); | 397 | + kernel->set_mission_id(mission_id[die_id].back().start_id); |
| 388 | return HcclResult::HCCL_SUCCESS; | 398 | return HcclResult::HCCL_SUCCESS; |
| 389 | } | 399 | } |
| 390 | 400 | ||
| 391 | static void dump_res_repository_info(const asc_ccu_res_repository& res_repo) | 401 | static void dump_res_repository_info(const asc_ccu_res_repository& res_repo) |
| 392 | { | 402 | { |
| 393 | - for (uint32_t i = 0; i < ccu_max_iodie_num; i++) { | 403 | + for (uint32_t i = 0; i < CCU_MAX_IODIE_NUM; i++) { |
| 394 | if (res_repo.ms[i].size() != 0 || res_repo.block_ms[i].size() != 0 || res_repo.cke[i].size() != 0 || | 404 | if (res_repo.ms[i].size() != 0 || res_repo.block_ms[i].size() != 0 || res_repo.cke[i].size() != 0 || |
| 395 | res_repo.block_cke[i].size() != 0 || res_repo.loop_engine[i].size() != 0 || | 405 | res_repo.block_cke[i].size() != 0 || res_repo.loop_engine[i].size() != 0 || |
| 396 | res_repo.block_loop_engine[i].size() != 0 || res_repo.gsa[i].size() != 0 || | 406 | res_repo.block_loop_engine[i].size() != 0 || res_repo.gsa[i].size() != 0 || |
| 397 | res_repo.block_gsa[i].size() != 0 || res_repo.xn[i].size() != 0 || res_repo.block_xn[i].size() != 0 || | 407 | res_repo.block_gsa[i].size() != 0 || res_repo.xn[i].size() != 0 || res_repo.block_xn[i].size() != 0 || |
| 398 | - res_repo.mission[i].size() != 0 || res_repo.instruction[i].size() != 0) { | 408 | + res_repo.mission[i].size() != 0) { |
| 399 | HCCL_INFO( | 409 | HCCL_INFO( |
| 400 | "DumpResRepository: dieId[%u], ms size[%u], blockMs size[%u], cke size[%u], blockCke size[%u], " | 410 | "DumpResRepository: dieId[%u], ms size[%u], blockMs size[%u], cke size[%u], blockCke size[%u], " |
| 401 | "loopEngine size[%u], blockLoopEngine size[%u], gsa size[%u], blockGsa size[%u], xn size[%u], " | 411 | "loopEngine size[%u], blockLoopEngine size[%u], gsa size[%u], blockGsa size[%u], xn size[%u], " |
| 402 | - "blockXn size[%u], mission size[%u], instruction size[%u]", | 412 | + "blockXn size[%u], mission size[%u]", |
| 403 | i, res_repo.ms[i].size(), res_repo.block_ms[i].size(), res_repo.cke[i].size(), | 413 | i, res_repo.ms[i].size(), res_repo.block_ms[i].size(), res_repo.cke[i].size(), |
| 404 | res_repo.block_cke[i].size(), res_repo.loop_engine[i].size(), res_repo.block_loop_engine[i].size(), | 414 | res_repo.block_cke[i].size(), res_repo.loop_engine[i].size(), res_repo.block_loop_engine[i].size(), |
| 405 | res_repo.gsa[i].size(), res_repo.block_gsa[i].size(), res_repo.xn[i].size(), | 415 | res_repo.gsa[i].size(), res_repo.block_gsa[i].size(), res_repo.xn[i].size(), |
| 406 | - res_repo.block_xn[i].size(), res_repo.mission[i].size(), res_repo.instruction[i].size()); | 416 | + res_repo.block_xn[i].size(), res_repo.mission[i].size()); |
| 407 | } | 417 | } |
| 408 | } | 418 | } |
| 409 | } | 419 | } |
| 410 | 420 | ||
| 411 | inline void expand_res_info( | 421 | inline void expand_res_info( |
| 412 | - std::vector<HcommCcuResRangePod>& expend_res_infos, const std::vector<HcommCcuResRangePod>& res_infos) | 422 | + std::vector<asc_ccu_res_range>& expend_res_infos, const std::vector<asc_ccu_res_range>& res_infos) |
| 413 | { | 423 | { |
| 414 | // 将resInfo中的资源信息还原为单个资源粒度 | 424 | // 将resInfo中的资源信息还原为单个资源粒度 |
| 415 | for (auto& res_info : res_infos) { | 425 | for (auto& res_info : res_infos) { |
| 416 | for (uint32_t id = 0; id < res_info.count; id++) { | 426 | for (uint32_t id = 0; id < res_info.count; id++) { |
| 417 | - expend_res_infos.push_back({res_info.resourceType, res_info.dieId, res_info.startId + id, 1}); | 427 | + expend_res_infos.push_back({res_info.resource_type, res_info.die_id, res_info.start_id + id, 1}); |
| 418 | } | 428 | } |
| 419 | } | 429 | } |
| 420 | } | 430 | } |
| @@ -422,7 +432,7 @@ inline void expand_res_info( | |||
| 422 | static CcuResult expand_res_repo(asc_ccu_res_repository& total_res, const asc_ccu_res_repository& tmp_res_repository) | 432 | static CcuResult expand_res_repo(asc_ccu_res_repository& total_res, const asc_ccu_res_repository& tmp_res_repository) |
| 423 | { | 433 | { |
| 424 | // 合并获取的所持有的资源信息, 按照类型合并资源总和到totalRes中 | 434 | // 合并获取的所持有的资源信息, 按照类型合并资源总和到totalRes中 |
| 425 | - for (uint32_t i = 0; i < ccu_max_iodie_num; i++) { | 435 | + for (uint32_t i = 0; i < CCU_MAX_IODIE_NUM; i++) { |
| 426 | expand_res_info(total_res.ms[i], tmp_res_repository.ms[i]); | 436 | expand_res_info(total_res.ms[i], tmp_res_repository.ms[i]); |
| 427 | expand_res_info(total_res.block_ms[i], tmp_res_repository.block_ms[i]); | 437 | expand_res_info(total_res.block_ms[i], tmp_res_repository.block_ms[i]); |
| 428 | expand_res_info(total_res.loop_engine[i], tmp_res_repository.loop_engine[i]); | 438 | expand_res_info(total_res.loop_engine[i], tmp_res_repository.loop_engine[i]); |
| @@ -434,7 +444,6 @@ static CcuResult expand_res_repo(asc_ccu_res_repository& total_res, const asc_cc | |||
| 434 | expand_res_info(total_res.xn[i], tmp_res_repository.xn[i]); | 444 | expand_res_info(total_res.xn[i], tmp_res_repository.xn[i]); |
| 435 | expand_res_info(total_res.block_xn[i], tmp_res_repository.block_xn[i]); | 445 | expand_res_info(total_res.block_xn[i], tmp_res_repository.block_xn[i]); |
| 436 | expand_res_info(total_res.mission[i], tmp_res_repository.mission[i]); | 446 | expand_res_info(total_res.mission[i], tmp_res_repository.mission[i]); |
| 437 | - expand_res_info(total_res.instruction[i], tmp_res_repository.instruction[i]); | ||
| 438 | } | 447 | } |
| 439 | dump_res_repository_info(total_res); | 448 | dump_res_repository_info(total_res); |
| 440 | return CcuResult::CCU_SUCCESS; | 449 | return CcuResult::CCU_SUCCESS; |
| @@ -567,7 +576,7 @@ CcuResult ccu_kernel_mgr::un_register(const ccu_kernel_handle kernel_handle) | |||
| 567 | 576 | ||
| 568 | HcclResult ccu_kernel_mgr::instantiation_translator(const uint16_t die_id, asc_ccu_res_snapshot& res_pack) | 577 | HcclResult ccu_kernel_mgr::instantiation_translator(const uint16_t die_id, asc_ccu_res_snapshot& res_pack) |
| 569 | { | 578 | { |
| 570 | - const HcommCcuDieMetadataPod* metadata = res_pack.get_die_metadata(die_id); | 579 | + const HcommCcuDieMetadata* metadata = res_pack.get_die_metadata(die_id); |
| 571 | CHK_PTR_NULL(metadata); | 580 | CHK_PTR_NULL(metadata); |
| 572 | // 临时申请device hbm内存用于查询token信息,由本地 RAII 对象管理生命周期 | 581 | // 临时申请device hbm内存用于查询token信息,由本地 RAII 对象管理生命周期 |
| 573 | ccu_dev_mem tmp_dev_mem{1}; | 582 | ccu_dev_mem tmp_dev_mem{1}; |
| @@ -577,18 +586,21 @@ HcclResult ccu_kernel_mgr::instantiation_translator(const uint16_t die_id, asc_c | |||
| 577 | } | 586 | } |
| 578 | auto hbm_token_info = asc::ccu_rep::get_token_info(tmp_dev_mem.get_addr(), tmp_dev_mem.get_size()); | 587 | auto hbm_token_info = asc::ccu_rep::get_token_info(tmp_dev_mem.get_addr(), tmp_dev_mem.get_size()); |
| 579 | ccu_rep::trans_dep trans_dep{}; | 588 | ccu_rep::trans_dep trans_dep{}; |
| 580 | - trans_dep.logical_id = res_pack.get_device_logic_id(); | 589 | + trans_dep.logical_id = dev_logic_id_; // 仅用于日志 |
| 581 | trans_dep.die_id = die_id; | 590 | trans_dep.die_id = die_id; |
| 582 | - trans_dep.reserve_channal_id[0] = static_cast<uint16_t>(metadata->innerDieLoopChannelId); | 591 | + // 环回 channel 每 die 唯一(die 内/间访问共用),两个槽位填同一条 |
| 583 | - trans_dep.reserve_channal_id[1] = static_cast<uint16_t>(metadata->interDieLoopChannelId); | 592 | + trans_dep.reserve_channal_id[0] = static_cast<uint16_t>(metadata->loopChannelId); |
| 593 | + trans_dep.reserve_channal_id[1] = static_cast<uint16_t>(metadata->loopChannelId); | ||
| 584 | for (uint32_t metadata_die = 0; metadata_die < HCOMM_CCU_MAX_DIE_NUM; ++metadata_die) { | 594 | for (uint32_t metadata_die = 0; metadata_die < HCOMM_CCU_MAX_DIE_NUM; ++metadata_die) { |
| 585 | - const HcommCcuDieMetadataPod* die_metadata = res_pack.get_die_metadata(metadata_die); | 595 | + const HcommCcuDieMetadata* die_metadata = res_pack.get_die_metadata(metadata_die); |
| 586 | if (die_metadata != nullptr) { | 596 | if (die_metadata != nullptr) { |
| 587 | - trans_dep.xn_base_addr[metadata_die] = die_metadata->xnBaseAddr; | 597 | + trans_dep.xn_base_addr[metadata_die] = |
| 598 | + die_metadata->ccuResBuffer.bufferInfo.rma.addr; // ccuResBuffer.addr 即 XN 基址 | ||
| 588 | } | 599 | } |
| 589 | } | 600 | } |
| 590 | - trans_dep.ccu_res_space_token_info = | 601 | + trans_dep.ccu_res_space_token_info = ccu_rep::get_token( |
| 591 | - ccu_rep::get_token(metadata->resourceSpaceTokenId, metadata->resourceSpaceTokenValue, 1); | 602 | + metadata->ccuResBuffer.bufferInfo.rma.protectionInfo.memInfo.ub.tokenId, |
| 603 | + metadata->ccuResBuffer.bufferInfo.rma.protectionInfo.memInfo.ub.tokenValue, 1); | ||
| 592 | trans_dep.mem_token_info = hbm_token_info; | 604 | trans_dep.mem_token_info = hbm_token_info; |
| 593 | 605 | ||
| 594 | // 实例化CcuRepReferenceManager和CcuRepTranslator,并为CcuRepReferenceManager绑定物理资源 | 606 | // 实例化CcuRepReferenceManager和CcuRepTranslator,并为CcuRepReferenceManager绑定物理资源 |
| @@ -635,48 +647,25 @@ HcclResult ccu_kernel_mgr::instantiation_translator(const uint16_t die_id, asc_c | |||
| 635 | 647 | ||
| 636 | HcclResult ccu_kernel_mgr::load_instruction(const ccu_rep::ccu_instr_info& instr_info, const uint32_t die_id) | 648 | HcclResult ccu_kernel_mgr::load_instruction(const ccu_rep::ccu_instr_info& instr_info, const uint32_t die_id) |
| 637 | { | 649 | { |
| 638 | - const uint64_t instr_info_size = instr_info.instr_vec.size() * sizeof(asc::ccu_rep::ccu_instr); | 650 | + const uint32_t instr_num = static_cast<uint32_t>(instr_info.instr_vec.size()); |
| 639 | 651 | ||
| 640 | - if (instr_info_size == 0) { | 652 | + if (instr_num == 0) { |
| 641 | return HcclResult::HCCL_E_PARA; | 653 | return HcclResult::HCCL_E_PARA; |
| 642 | } | 654 | } |
| 643 | - if (instruction_load_dev_mem_size_ < instr_info_size) { | ||
| 644 | - if (instruction_load_dev_mem_ != nullptr) { | ||
| 645 | - CHK_RET(static_cast<HcclResult>(aclrtFree(instruction_load_dev_mem_))); | ||
| 646 | - instruction_load_dev_mem_ = nullptr; | ||
| 647 | - instruction_load_dev_mem_size_ = 0; | ||
| 648 | - } | ||
| 649 | - CHK_RET(static_cast<HcclResult>( | ||
| 650 | - aclrtMalloc(&instruction_load_dev_mem_, instr_info_size, ACL_MEM_MALLOC_HUGE_FIRST))); | ||
| 651 | - instruction_load_dev_mem_size_ = instr_info_size; | ||
| 652 | - } | ||
| 653 | 655 | ||
| 654 | - CHK_RET(static_cast<HcclResult>(aclrtMemcpy( | 656 | + // ascCustom 槽 2:data 为 host 指针,设备内存暂存与驱动交互均由 hcomm 在其 SO 内完成 |
| 655 | - instruction_load_dev_mem_, instr_info_size, instr_info.instr_vec.data(), instr_info_size, | 657 | + const auto submit_insts = |
| 656 | - ACL_MEMCPY_HOST_TO_DEVICE))); | 658 | + reinterpret_cast<HcommCcuSubmitInstsFn>(get_current_ccu_control_ops()[HCOMM_CCU_ASC_CUSTOM_SUBMIT_INSTS]); |
| 657 | - | ||
| 658 | - // 只传语义参数;opcode 选择、TLV 报文组装与驱动交互均由 hcomm 在其 SO 内完成 | ||
| 659 | - HcommCcuInstructionLoadPod request{}; | ||
| 660 | - request.header.version = HCOMM_CCU_INSTRUCTION_ABI_VERSION; | ||
| 661 | - request.header.magicWord = HCOMM_CCU_INSTRUCTION_LOAD_MAGIC_WORD; | ||
| 662 | - request.header.size = sizeof(request); | ||
| 663 | - request.deviceLogicId = dev_logic_id_; | ||
| 664 | - request.dieId = die_id; | ||
| 665 | - request.startInstructionId = instr_info.start_instr_id; | ||
| 666 | - request.deviceAddress = reinterpret_cast<uint64_t>(instruction_load_dev_mem_); | ||
| 667 | - request.byteSize = instr_info_size; | ||
| 668 | - | ||
| 669 | - const auto load_instruction = get_current_ccu_control_ops().loadInstruction; | ||
| 670 | CHK_PRT_RET( | 659 | CHK_PRT_RET( |
| 671 | - load_instruction == nullptr, HCCL_ERROR("[CcuKernelMgr][%s] controlOps.loadInstruction is nullptr.", __func__), | 660 | + submit_insts == nullptr, HCCL_ERROR("[CcuKernelMgr][%s] controlOps.submitInsts is nullptr.", __func__), |
| 672 | HcclResult::HCCL_E_INTERNAL); | 661 | HcclResult::HCCL_E_INTERNAL); |
| 673 | - auto ret = static_cast<HcclResult>(load_instruction(&request)); | 662 | + auto ret = static_cast<HcclResult>( |
| 663 | + submit_insts(dev_logic_id_, die_id, instr_info.start_instr_id, instr_info.instr_vec.data(), instr_num)); | ||
| 674 | if (ret != HcclResult::HCCL_SUCCESS) { | 664 | if (ret != HcclResult::HCCL_SUCCESS) { |
| 675 | HCCL_ERROR( | 665 | HCCL_ERROR( |
| 676 | - "[CcuKernelMgr][%s] failed to load instruction, " | 666 | + "[CcuKernelMgr][%s] failed to submit instructions, " |
| 677 | - "devLogicId[%d] dieId[%u] startInstrId[%u] byteSize[%llu] ret[%d].", | 667 | + "devLogicId[%d] dieId[%u] startInstrId[%u] instrNum[%u] ret[%d].", |
| 678 | - __func__, dev_logic_id_, die_id, instr_info.start_instr_id, | 668 | + __func__, dev_logic_id_, die_id, instr_info.start_instr_id, instr_num, ret); |
| 679 | - static_cast<unsigned long long>(instr_info_size), ret); | ||
| 680 | return ret; | 669 | return ret; |
| 681 | } | 670 | } |
| 682 | 671 | ||
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | #include "hcomm/resource/kernel/ccu_kernel.h" | 18 | #include "hcomm/resource/kernel/ccu_kernel.h" |
| 19 | #include "hcomm/resource/common/asc_ccu_res_snapshot.h" | 19 | #include "hcomm/resource/common/asc_ccu_res_snapshot.h" |
| 20 | +#include "hcomm/hcomm_ccu_dfx.h" // asccomm_ccu_diagnose 的请求/回调类型(DFX 诊断专用头) | ||
| 20 | 21 | ||
| 21 | #include "hcomm/resource/representation/reps/translator/ccu_rep_translator_v1.h" | 22 | #include "hcomm/resource/representation/reps/translator/ccu_rep_translator_v1.h" |
| 22 | 23 | ||
| @@ -24,7 +25,7 @@ | |||
| 24 | 25 | ||
| 25 | namespace asc { | 26 | namespace asc { |
| 26 | 27 | ||
| 27 | -int32_t asccomm_ccu_diagnose(const HcommCcuDfxRequestPod* request, HcommCcuDfxEmitFn emit, void* context); | 28 | +int32_t asccomm_ccu_diagnose(const HcommCcuDfxRequest* request, HcommCcuDfxEmitFn emit, void* context); |
| 28 | 29 | ||
| 29 | using namespace ccu_rep; | 30 | using namespace ccu_rep; |
| 30 | 31 | ||
| @@ -47,7 +48,7 @@ public: | |||
| 47 | CcuResult un_register(ccu_kernel_handle kernel_handle); | 48 | CcuResult un_register(ccu_kernel_handle kernel_handle); |
| 48 | 49 | ||
| 49 | ccu_kernel* get_current_kernel(); | 50 | ccu_kernel* get_current_kernel(); |
| 50 | - const HcommCcuControlOpsPod& get_control_ops() const; | 51 | + const uint64_t* get_control_ops() const; // ascCustom 槽位数组 |
| 51 | 52 | ||
| 52 | private: | 53 | private: |
| 53 | explicit ccu_kernel_mgr() = default; | 54 | explicit ccu_kernel_mgr() = default; |
| @@ -71,8 +72,6 @@ private: | |||
| 71 | std::mutex translate_mutex_{}; | 72 | std::mutex translate_mutex_{}; |
| 72 | ccu_kernel_handle kernel_id_ = 0; | 73 | ccu_kernel_handle kernel_id_ = 0; |
| 73 | std::unordered_map<ccu_kernel_handle, std::unique_ptr<ccu_kernel>> kernel_map_{}; | 74 | std::unordered_map<ccu_kernel_handle, std::unique_ptr<ccu_kernel>> kernel_map_{}; |
| 74 | - void* instruction_load_dev_mem_{nullptr}; | ||
| 75 | - uint64_t instruction_load_dev_mem_size_{0}; | ||
| 76 | 75 | ||
| 77 | std::unordered_map<uint16_t, std::unordered_map<uint16_t, std::shared_ptr<ccu_rep::ccu_rep_translator>>> | 76 | std::unordered_map<uint16_t, std::unordered_map<uint16_t, std::shared_ptr<ccu_rep::ccu_rep_translator>>> |
| 78 | translators_; | 77 | translators_; |
| @@ -82,7 +81,7 @@ private: | |||
| 82 | std::shared_ptr<ccu_ins_generater_base> ins_gene_ptr_; | 81 | std::shared_ptr<ccu_ins_generater_base> ins_gene_ptr_; |
| 83 | uint32_t ccu_version_{HCOMM_CCU_VERSION_INVALID}; | 82 | uint32_t ccu_version_{HCOMM_CCU_VERSION_INVALID}; |
| 84 | std::array<uint32_t, HCOMM_CCU_MAX_DIE_NUM> mission_keys_{}; | 83 | std::array<uint32_t, HCOMM_CCU_MAX_DIE_NUM> mission_keys_{}; |
| 85 | - HcommCcuControlOpsPod control_ops_{}; | 84 | + uint64_t control_ops_[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]{}; |
| 86 | }; | 85 | }; |
| 87 | }; // namespace asc | 86 | }; // namespace asc |
| 88 | #endif // HCOMM_CCU_KERNEL_MGR_IMP_H | 87 | #endif // HCOMM_CCU_KERNEL_MGR_IMP_H |
| @@ -10,6 +10,8 @@ | |||
| 10 | 10 | ||
| 11 | #include "hcomm/resource/kernel/ccu_kernel_registry.h" | 11 | #include "hcomm/resource/kernel/ccu_kernel_registry.h" |
| 12 | 12 | ||
| 13 | +#include "hcomm/common/ccu_device_context.h" | ||
| 14 | + | ||
| 13 | #include <algorithm> | 15 | #include <algorithm> |
| 14 | 16 | ||
| 15 | #include "hcomm/common/ccu_log.h" | 17 | #include "hcomm/common/ccu_log.h" |
| @@ -45,21 +47,23 @@ CcuResult ccu_kernel_registry::init(int32_t device_logic_id) | |||
| 45 | return CcuResult::CCU_SUCCESS; | 47 | return CcuResult::CCU_SUCCESS; |
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | -CcuResult ccu_kernel_registry::load_register_context(const HcommCcuRegisterContextPod& context) | 50 | +CcuResult ccu_kernel_registry::load_register_context(const HcommCcuInstance& instance) |
| 49 | { | 51 | { |
| 50 | CCU_EXCEPTION_HANDLE_BEGIN | 52 | CCU_EXCEPTION_HANDLE_BEGIN |
| 51 | if (!res_snapshot_) { | 53 | if (!res_snapshot_) { |
| 52 | res_snapshot_.reset(new (std::nothrow) asc_ccu_res_snapshot()); | 54 | res_snapshot_.reset(new (std::nothrow) asc_ccu_res_snapshot()); |
| 53 | CCU_CHK_PTR_NULL(res_snapshot_); | 55 | CCU_CHK_PTR_NULL(res_snapshot_); |
| 54 | } | 56 | } |
| 55 | - // 上下文的设备号必须与创建时传入的一致,否则说明调用方把上下文用在了错误的实例上。 | 57 | + // 当前线程设备必须与创建 registry 时一致,否则说明上下文被用在了错误的设备上 |
| 56 | - if (context.deviceLogicId != dev_logic_id_) { | 58 | + // (Instance 不再携带设备号,定档口径:即时取 aclrtGetDevice)。 |
| 59 | + const int32_t current_device = asc::get_current_ccu_device_logic_id(); | ||
| 60 | + if (current_device != dev_logic_id_) { | ||
| 57 | HCCL_ERROR( | 61 | HCCL_ERROR( |
| 58 | - "[CcuKernelRegistry][%s] failed, context deviceLogicId[%d] mismatches instance deviceLogicId[%d].", | 62 | + "[CcuKernelRegistry][%s] failed, current device[%d] mismatches instance device[%d].", __func__, |
| 59 | - __func__, context.deviceLogicId, dev_logic_id_); | 63 | + current_device, dev_logic_id_); |
| 60 | return CcuResult::CCU_E_PARA; | 64 | return CcuResult::CCU_E_PARA; |
| 61 | } | 65 | } |
| 62 | - CCU_CHK_RET(res_snapshot_->load(context)); | 66 | + CCU_CHK_RET(res_snapshot_->load(instance)); |
| 63 | CCU_EXCEPTION_HANDLE_END | 67 | CCU_EXCEPTION_HANDLE_END |
| 64 | return CcuResult::CCU_SUCCESS; | 68 | return CcuResult::CCU_SUCCESS; |
| 65 | } | 69 | } |
| @@ -34,7 +34,7 @@ public: | |||
| 34 | // 计数器分配且各自从 0 起,跨设备会重号,实例必须落在指定设备的 handle table 上。 | 34 | // 计数器分配且各自从 0 起,跨设备会重号,实例必须落在指定设备的 handle table 上。 |
| 35 | // 该值在 LoadRegisterContext 之前即需就绪,析构时注销 kernel 依赖它定位 CcuKernelMgr。 | 35 | // 该值在 LoadRegisterContext 之前即需就绪,析构时注销 kernel 依赖它定位 CcuKernelMgr。 |
| 36 | CcuResult init(int32_t device_logic_id); | 36 | CcuResult init(int32_t device_logic_id); |
| 37 | - CcuResult load_register_context(const HcommCcuRegisterContextPod& context); | 37 | + CcuResult load_register_context(const HcommCcuInstance& instance); |
| 38 | CcuResult reset(); | 38 | CcuResult reset(); |
| 39 | asc_ccu_res_snapshot* get_res_snapshot(); | 39 | asc_ccu_res_snapshot* get_res_snapshot(); |
| 40 | CcuResult save_kernel(const ccu_kernel_handle kernel_handle); | 40 | CcuResult save_kernel(const ccu_kernel_handle kernel_handle); |
| @@ -52,7 +52,7 @@ private: | |||
| 52 | 52 | ||
| 53 | int32_t dev_logic_id_{INT32_MAX}; | 53 | int32_t dev_logic_id_{INT32_MAX}; |
| 54 | // CcuVarEventResMgr 按 handle 记账,析构时需以此调用 ReleaseByInstance。 | 54 | // CcuVarEventResMgr 按 handle 记账,析构时需以此调用 ReleaseByInstance。 |
| 55 | - CcuInsHandle ins_handle_{0}; | 55 | + CcuInsHandle ins_handle_{}; |
| 56 | std::unique_ptr<asc_ccu_res_snapshot> res_snapshot_{}; | 56 | std::unique_ptr<asc_ccu_res_snapshot> res_snapshot_{}; |
| 57 | std::vector<ccu_kernel_handle> kernel_handles_{}; | 57 | std::vector<ccu_kernel_handle> kernel_handles_{}; |
| 58 | std::vector<ccu_kernel_handle> untranslated_kernel_handles_{}; | 58 | std::vector<ccu_kernel_handle> untranslated_kernel_handles_{}; |
| @@ -67,12 +67,12 @@ CcuResult ccu_kernel_registry_mgr::get_or_create( | |||
| 67 | int32_t device_logic_id, CcuInsHandle ins_handle, ccu_kernel_registry*& registry) | 67 | int32_t device_logic_id, CcuInsHandle ins_handle, ccu_kernel_registry*& registry) |
| 68 | { | 68 | { |
| 69 | registry = nullptr; | 69 | registry = nullptr; |
| 70 | - if (ins_handle == 0) { | 70 | + if (ins_handle.ccuInsKey == 0) { |
| 71 | return CcuResult::CCU_E_PARA; | 71 | return CcuResult::CCU_E_PARA; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | std::unique_lock<std::shared_timed_mutex> lock(ins_map_mutex_); | 74 | std::unique_lock<std::shared_timed_mutex> lock(ins_map_mutex_); |
| 75 | - auto it = ins_map_.find(ins_handle); | 75 | + auto it = ins_map_.find(ins_handle.ccuInsKey); |
| 76 | if (it != ins_map_.end()) { | 76 | if (it != ins_map_.end()) { |
| 77 | registry = it->second.get(); | 77 | registry = it->second.get(); |
| 78 | return CcuResult::CCU_SUCCESS; | 78 | return CcuResult::CCU_SUCCESS; |
| @@ -83,16 +83,18 @@ CcuResult ccu_kernel_registry_mgr::get_or_create( | |||
| 83 | CCU_CHK_RET(instance->init(device_logic_id)); | 83 | CCU_CHK_RET(instance->init(device_logic_id)); |
| 84 | instance->set_handle(ins_handle); | 84 | instance->set_handle(ins_handle); |
| 85 | registry = instance.get(); | 85 | registry = instance.get(); |
| 86 | - ins_map_.emplace(ins_handle, std::move(instance)); | 86 | + ins_map_.emplace(ins_handle.ccuInsKey, std::move(instance)); |
| 87 | return CcuResult::CCU_SUCCESS; | 87 | return CcuResult::CCU_SUCCESS; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | ccu_kernel_registry* ccu_kernel_registry_mgr::get(CcuInsHandle ins_handle) const | 90 | ccu_kernel_registry* ccu_kernel_registry_mgr::get(CcuInsHandle ins_handle) const |
| 91 | { | 91 | { |
| 92 | std::shared_lock<std::shared_timed_mutex> lock(ins_map_mutex_); | 92 | std::shared_lock<std::shared_timed_mutex> lock(ins_map_mutex_); |
| 93 | - auto it = ins_map_.find(ins_handle); | 93 | + auto it = ins_map_.find(ins_handle.ccuInsKey); |
| 94 | if (it == ins_map_.end()) { | 94 | if (it == ins_map_.end()) { |
| 95 | - HCCL_ERROR("[CcuKernelRegistryMgr][%s] handle[%llx] is not existed.", __func__, ins_handle); | 95 | + HCCL_ERROR( |
| 96 | + "[CcuKernelRegistryMgr][%s] handle key[%llx] is not existed.", __func__, | ||
| 97 | + static_cast<unsigned long long>(ins_handle.ccuInsKey)); | ||
| 96 | return nullptr; | 98 | return nullptr; |
| 97 | } | 99 | } |
| 98 | 100 | ||
| @@ -28,7 +28,7 @@ public: | |||
| 28 | CcuResult init(); | 28 | CcuResult init(); |
| 29 | CcuResult deinit(); | 29 | CcuResult deinit(); |
| 30 | 30 | ||
| 31 | - // insHandle is hcomm-owned. asc-comm only uses it as an opaque key. | 31 | + // insHandle is hcomm-owned. asc-comm only uses ccuInsKey as an opaque lookup key. |
| 32 | CcuResult get_or_create(int32_t device_logic_id, CcuInsHandle ins_handle, ccu_kernel_registry*& registry); | 32 | CcuResult get_or_create(int32_t device_logic_id, CcuInsHandle ins_handle, ccu_kernel_registry*& registry); |
| 33 | ccu_kernel_registry* get(CcuInsHandle ins_handle) const; | 33 | ccu_kernel_registry* get(CcuInsHandle ins_handle) const; |
| 34 | 34 | ||
| @@ -43,7 +43,7 @@ private: | |||
| 43 | bool initialized_flag_{false}; | 43 | bool initialized_flag_{false}; |
| 44 | int32_t dev_logic_id_{-1}; | 44 | int32_t dev_logic_id_{-1}; |
| 45 | mutable std::shared_timed_mutex ins_map_mutex_; | 45 | mutable std::shared_timed_mutex ins_map_mutex_; |
| 46 | - std::unordered_map<CcuInsHandle, std::unique_ptr<ccu_kernel_registry>> ins_map_{}; | 46 | + std::unordered_map<uint64_t, std::unique_ptr<ccu_kernel_registry>> ins_map_{}; |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | } // namespace asc | 49 | } // namespace asc |
| @@ -17,40 +17,40 @@ namespace asc { | |||
| 17 | namespace { | 17 | namespace { |
| 18 | 18 | ||
| 19 | bool take_contiguous( | 19 | bool take_contiguous( |
| 20 | - std::vector<HcommCcuResRangePod>& source, uint32_t count, std::vector<HcommCcuResRangePod>& destination) | 20 | + std::vector<asc_ccu_res_range>& source, uint32_t count, std::vector<asc_ccu_res_range>& destination) |
| 21 | { | 21 | { |
| 22 | if (count == 0) { | 22 | if (count == 0) { |
| 23 | return true; | 23 | return true; |
| 24 | } | 24 | } |
| 25 | auto iter = std::find_if( | 25 | auto iter = std::find_if( |
| 26 | - source.begin(), source.end(), [count](const HcommCcuResRangePod& range) { return range.count >= count; }); | 26 | + source.begin(), source.end(), [count](const asc_ccu_res_range& range) { return range.count >= count; }); |
| 27 | if (iter == source.end()) { | 27 | if (iter == source.end()) { |
| 28 | return false; | 28 | return false; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | - destination.push_back({iter->resourceType, iter->dieId, iter->startId, count}); | 31 | + destination.push_back({iter->resource_type, iter->die_id, iter->start_id, count}); |
| 32 | if (iter->count == count) { | 32 | if (iter->count == count) { |
| 33 | source.erase(iter); | 33 | source.erase(iter); |
| 34 | } else { | 34 | } else { |
| 35 | - iter->startId += count; | 35 | + iter->start_id += count; |
| 36 | iter->count -= count; | 36 | iter->count -= count; |
| 37 | } | 37 | } |
| 38 | return true; | 38 | return true; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | uint32_t take_any( | 41 | uint32_t take_any( |
| 42 | - std::vector<HcommCcuResRangePod>& source, uint32_t count, uint32_t destination_type, | 42 | + std::vector<asc_ccu_res_range>& source, uint32_t count, uint32_t destination_type, |
| 43 | - std::vector<HcommCcuResRangePod>& destination) | 43 | + std::vector<asc_ccu_res_range>& destination) |
| 44 | { | 44 | { |
| 45 | auto iter = source.begin(); | 45 | auto iter = source.begin(); |
| 46 | while (count > 0 && iter != source.end()) { | 46 | while (count > 0 && iter != source.end()) { |
| 47 | const uint32_t take = std::min(count, iter->count); | 47 | const uint32_t take = std::min(count, iter->count); |
| 48 | - destination.push_back({destination_type, iter->dieId, iter->startId, take}); | 48 | + destination.push_back({destination_type, iter->die_id, iter->start_id, take}); |
| 49 | count -= take; | 49 | count -= take; |
| 50 | if (take == iter->count) { | 50 | if (take == iter->count) { |
| 51 | iter = source.erase(iter); | 51 | iter = source.erase(iter); |
| 52 | } else { | 52 | } else { |
| 53 | - iter->startId += take; | 53 | + iter->start_id += take; |
| 54 | iter->count -= take; | 54 | iter->count -= take; |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| @@ -58,9 +58,9 @@ uint32_t take_any( | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | bool plan_resource_pair( | 60 | bool plan_resource_pair( |
| 61 | - std::vector<HcommCcuResRangePod>& normal_pool, std::vector<HcommCcuResRangePod>& block_pool, | 61 | + std::vector<asc_ccu_res_range>& normal_pool, std::vector<asc_ccu_res_range>& block_pool, uint32_t normal_request, |
| 62 | - uint32_t normal_request, uint32_t block_request, uint32_t normal_type, | 62 | + uint32_t block_request, uint32_t normal_type, std::vector<asc_ccu_res_range>& normal_allocated, |
| 63 | - std::vector<HcommCcuResRangePod>& normal_allocated, std::vector<HcommCcuResRangePod>& block_allocated) | 63 | + std::vector<asc_ccu_res_range>& block_allocated) |
| 64 | { | 64 | { |
| 65 | if (!take_contiguous(block_pool, block_request, block_allocated)) { | 65 | if (!take_contiguous(block_pool, block_request, block_allocated)) { |
| 66 | return false; | 66 | return false; |
| @@ -103,15 +103,12 @@ CcuResult plan_kernel_resources( | |||
| 103 | planned_remaining.gsa[die_id], planned_remaining.block_gsa[die_id], | 103 | planned_remaining.gsa[die_id], planned_remaining.block_gsa[die_id], |
| 104 | request.count[HCOMM_CCU_BATCH_RES_GSA][die_id], request.count[HCOMM_CCU_BATCH_RES_BLOCK_GSA][die_id], | 104 | request.count[HCOMM_CCU_BATCH_RES_GSA][die_id], request.count[HCOMM_CCU_BATCH_RES_BLOCK_GSA][die_id], |
| 105 | HCOMM_CCU_BATCH_RES_GSA, planned_allocated.gsa[die_id], planned_allocated.block_gsa[die_id]); | 105 | HCOMM_CCU_BATCH_RES_GSA, planned_allocated.gsa[die_id], planned_allocated.block_gsa[die_id]); |
| 106 | - if (!planned || | 106 | + if (!planned || take_any( |
| 107 | - take_any( | 107 | + planned_remaining.mission[die_id], request.count[HCOMM_CCU_BATCH_RES_MISSION][die_id], |
| 108 | - planned_remaining.mission[die_id], request.count[HCOMM_CCU_BATCH_RES_MISSION][die_id], | 108 | + HCOMM_CCU_BATCH_RES_MISSION, planned_allocated.mission[die_id]) != 0) { |
| 109 | - HCOMM_CCU_BATCH_RES_MISSION, planned_allocated.mission[die_id]) != 0 || | ||
| 110 | - !take_contiguous( | ||
| 111 | - planned_remaining.instruction[die_id], request.instruction[die_id], | ||
| 112 | - planned_allocated.instruction[die_id])) { | ||
| 113 | return CcuResult::CCU_E_UNAVAIL; | 109 | return CcuResult::CCU_E_UNAVAIL; |
| 114 | } | 110 | } |
| 111 | + // INS 不走 range 池:指令空间由 ascCustom.allocInstSpace 向 hcomm 按需申请,随 RegisterContext 归还。 | ||
| 115 | } | 112 | } |
| 116 | 113 | ||
| 117 | remaining = std::move(planned_remaining); | 114 | remaining = std::move(planned_remaining); |
| @@ -17,7 +17,7 @@ | |||
| 17 | #include <string> | 17 | #include <string> |
| 18 | #include <unordered_map> | 18 | #include <unordered_map> |
| 19 | 19 | ||
| 20 | -#include "hcomm/hcomm_ccu_channel.h" | 20 | +#include "hcomm/hcomm_ccu_resource.h" |
| 21 | #include "hcomm/resource/representation/reps/common/ccu_rep_base_v1.h" | 21 | #include "hcomm/resource/representation/reps/common/ccu_rep_base_v1.h" |
| 22 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" | 22 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" |
| 23 | 23 | ||
| @@ -32,8 +32,9 @@ struct trans_dep { | |||
| 32 | uint16_t reserve_xn_id; | 32 | uint16_t reserve_xn_id; |
| 33 | uint16_t reserve_gsa_id; | 33 | uint16_t reserve_gsa_id; |
| 34 | uint16_t reserve_cke_id; | 34 | uint16_t reserve_cke_id; |
| 35 | - uint16_t reserve_channal_id[2]; // 0: selfLoopBack; 1: inter die, 0xffff为无效值,rep翻译时检查 | 35 | + uint16_t |
| 36 | - uint64_t xn_base_addr[ccu_max_iodie_num]; | 36 | + reserve_channal_id[2]; // 环回 channel(die 内/间共用同一条):0/1 两槽位同值,0xffff为无效值,rep翻译时检查 |
| 37 | + uint64_t xn_base_addr[CCU_MAX_IODIE_NUM]; | ||
| 37 | uint64_t ccu_res_space_token_info; | 38 | uint64_t ccu_res_space_token_info; |
| 38 | uint64_t mem_token_info; | 39 | uint64_t mem_token_info; |
| 39 | uint16_t comm_xn[3]; // 3个Xn | 40 | uint16_t comm_xn[3]; // 3个Xn |
| @@ -13,7 +13,7 @@ | |||
| 13 | #include "hcomm/common/ccu_exception.h" | 13 | #include "hcomm/common/ccu_exception.h" |
| 14 | #include "hcomm/resource/microcode/ccu_assist_v1.h" | 14 | #include "hcomm/resource/microcode/ccu_assist_v1.h" |
| 15 | #include "hcomm/common/ccu_log.h" | 15 | #include "hcomm/common/ccu_log.h" |
| 16 | -#include "hcomm/hcomm_ccu_res.h" | 16 | +#include "hcomm/hcomm_ccu_resource.h" |
| 17 | 17 | ||
| 18 | namespace asc { | 18 | namespace asc { |
| 19 | namespace ccu_rep { | 19 | namespace ccu_rep { |
| @@ -15,7 +15,7 @@ | |||
| 15 | #include <vector> | 15 | #include <vector> |
| 16 | #include <memory> | 16 | #include <memory> |
| 17 | 17 | ||
| 18 | -#include "hcomm/hcomm_ccu_res.h" | 18 | +#include "hcomm/hcomm_ccu_resource.h" |
| 19 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" | 19 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" |
| 20 | #include "hcomm/resource/common/ccu_kernel_resource.h" | 20 | #include "hcomm/resource/common/ccu_kernel_resource.h" |
| 21 | 21 | ||
| @@ -15,7 +15,7 @@ | |||
| 15 | #include <vector> | 15 | #include <vector> |
| 16 | #include <functional> | 16 | #include <functional> |
| 17 | 17 | ||
| 18 | -#include "hcomm/hcomm_ccu_res.h" | 18 | +#include "hcomm/hcomm_ccu_resource.h" |
| 19 | #include "hcomm/resource/microcode/ccu_instr_info_v1.h" | 19 | #include "hcomm/resource/microcode/ccu_instr_info_v1.h" |
| 20 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" | 20 | #include "hcomm/resource/representation/reps/common/ccu_rep_block_v1.h" |
| 21 | #include "hcomm/resource/representation/reps/translator/ccu_rep_reference_manager_v1.h" | 21 | #include "hcomm/resource/representation/reps/translator/ccu_rep_reference_manager_v1.h" |
| @@ -257,19 +257,25 @@ protected: | |||
| 257 | 257 | ||
| 258 | void SetUp() override | 258 | void SetUp() override |
| 259 | { | 259 | { |
| 260 | - HcommCcuChannelPod channelPod{}; | 260 | + HcommCcuChannelEntity channelEntity{}; |
| 261 | - channelPod.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; | 261 | + channelEntity.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; |
| 262 | - channelPod.header.magicWord = HCOMM_CCU_CHANNEL_POD_MAGIC_WORD; | 262 | + channelEntity.header.magicWord = HCOMM_CCU_CHANNEL_MAGIC_WORD; |
| 263 | - channelPod.header.size = sizeof(HcommCcuChannelPod); | 263 | + channelEntity.header.size = sizeof(HcommCcuChannelEntity); |
| 264 | - channelPod.localXnIds[0] = 0; | 264 | + channelEntity.localVarNum = 1; |
| 265 | - channelPod.remoteXnIds[0] = 0; | 265 | + channelEntity.remoteVarNum = 1; |
| 266 | - channelPod.localCkeIds[0] = 5; | 266 | + channelEntity.localEventNum = 1; |
| 267 | - channelPod.remoteCkeIds[0] = 6; | 267 | + channelEntity.remoteEventNum = 1; |
| 268 | - channelPod.rmtCcuBufSize = 1; | 268 | + channelEntity.localVarIds[0] = 0; |
| 269 | - SetHcommCcuChannelQueryStub(channelPod); | 269 | + channelEntity.remoteVarIds[0] = 0; |
| 270 | + channelEntity.localEventIds[0] = 5; | ||
| 271 | + channelEntity.remoteEventIds[0] = 6; | ||
| 272 | + channelEntity.rmtCcuResBuffer.type = REGED_BUFFER_RMA; | ||
| 273 | + channelEntity.rmtCcuResBuffer.bufferInfo.rma.addr = 0x1000; | ||
| 274 | + channelEntity.rmtCcuResBuffer.bufferInfo.rma.size = 1; | ||
| 275 | + SetHcommCcuChannelGetEntityStub(channelEntity); | ||
| 270 | } | 276 | } |
| 271 | 277 | ||
| 272 | - void TearDown() override { ResetHcommCcuChannelQueryStub(); } | 278 | + void TearDown() override { ResetHcommCcuChannelGetEntityStub(); } |
| 273 | }; | 279 | }; |
| 274 | 280 | ||
| 275 | TEST_F(CcuRepContextProfilingTest, AddProfiling_WithChannel) | 281 | TEST_F(CcuRepContextProfilingTest, AddProfiling_WithChannel) |
| @@ -328,16 +334,9 @@ TEST_F(CcuRepContextTest, GetRepByInstrId_Found) | |||
| 328 | EXPECT_EQ(context_.get_rep_by_instr_id(1000), nullptr); | 334 | EXPECT_EQ(context_.get_rep_by_instr_id(1000), nullptr); |
| 329 | } | 335 | } |
| 330 | 336 | ||
| 331 | -TEST_F(CcuRepContextTest, DeviceLogicId_SetAndGet) | ||
| 332 | -{ | ||
| 333 | - set_current_ccu_device_logic_id(7); | ||
| 334 | - EXPECT_EQ(get_current_ccu_device_logic_id(), 7); | ||
| 335 | - set_current_ccu_device_logic_id(-1); | ||
| 336 | -} | ||
| 337 | - | ||
| 338 | TEST_F(CcuRepContextProfilingTest, AddProfiling_WithChannel_StubFailure) | 337 | TEST_F(CcuRepContextProfilingTest, AddProfiling_WithChannel_StubFailure) |
| 339 | { | 338 | { |
| 340 | - SetHcommCcuChannelQueryStubResult(-1); | 339 | + SetHcommCcuChannelGetEntityStubResult(-1); |
| 341 | ccu_rep_context context_; | 340 | ccu_rep_context context_; |
| 342 | ChannelHandle ch = 0; | 341 | ChannelHandle ch = 0; |
| 343 | int32_t ret = context_.add_profiling(ch, std::string("wait_cke"), 0, 0xF); | 342 | int32_t ret = context_.add_profiling(ch, std::string("wait_cke"), 0, 0xF); |
| @@ -31,8 +31,6 @@ | |||
| 31 | #include <string> | 31 | #include <string> |
| 32 | #include <vector> | 32 | #include <vector> |
| 33 | 33 | ||
| 34 | -#include "ccu/hcomm/ccu_utils.hpp" | ||
| 35 | - | ||
| 36 | using CcuUtException = ::AscendC::ccu::detail::ccu_exception; | 34 | using CcuUtException = ::AscendC::ccu::detail::ccu_exception; |
| 37 | 35 | ||
| 38 | namespace asc { | 36 | namespace asc { |
| @@ -44,18 +42,25 @@ protected: | |||
| 44 | ccu_ins_generater_v1 insGen{}; | 42 | ccu_ins_generater_v1 insGen{}; |
| 45 | void SetUp() override | 43 | void SetUp() override |
| 46 | { | 44 | { |
| 47 | - HcommCcuChannelPod channelPod{}; | 45 | + HcommCcuChannelEntity channelEntity{}; |
| 48 | - channelPod.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; | 46 | + channelEntity.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; |
| 49 | - channelPod.header.magicWord = HCOMM_CCU_CHANNEL_POD_MAGIC_WORD; | 47 | + channelEntity.header.magicWord = HCOMM_CCU_CHANNEL_MAGIC_WORD; |
| 50 | - channelPod.header.size = sizeof(HcommCcuChannelPod); | 48 | + channelEntity.header.size = sizeof(HcommCcuChannelEntity); |
| 51 | - channelPod.localXnIds[0] = 0; | 49 | + channelEntity.localVarNum = 1; |
| 52 | - channelPod.remoteXnIds[0] = 0; | 50 | + channelEntity.remoteVarNum = 1; |
| 53 | - channelPod.localCkeIds[0] = 0; | 51 | + channelEntity.localEventNum = 1; |
| 54 | - channelPod.remoteCkeIds[0] = 0; | 52 | + channelEntity.remoteEventNum = 1; |
| 55 | - channelPod.rmtCcuBufSize = 1; | 53 | + channelEntity.localVarIds[0] = 0; |
| 56 | - SetHcommCcuChannelQueryStub(channelPod); | 54 | + channelEntity.remoteVarIds[0] = 0; |
| 55 | + channelEntity.localEventIds[0] = 0; | ||
| 56 | + channelEntity.remoteEventIds[0] = 0; | ||
| 57 | + channelEntity.rmtCcuResBuffer.type = REGED_BUFFER_RMA; | ||
| 58 | + channelEntity.rmtCcuResBuffer.bufferInfo.rma.addr = 0x1000; | ||
| 59 | + channelEntity.rmtCcuResBuffer.bufferInfo.rma.size = 1; | ||
| 60 | + channelEntity.rmtCcuResBuffer.bufferInfo.rma.protectionInfo.type = PROTECTION_TYPE_UB; | ||
| 61 | + SetHcommCcuChannelGetEntityStub(channelEntity); | ||
| 57 | } | 62 | } |
| 58 | - void TearDown() override { ResetHcommCcuChannelQueryStub(); } | 63 | + void TearDown() override { ResetHcommCcuChannelGetEntityStub(); } |
| 59 | }; | 64 | }; |
| 60 | 65 | ||
| 61 | class CcuRepReadTest : public CcuRepChannelTest {}; | 66 | class CcuRepReadTest : public CcuRepChannelTest {}; |
| @@ -660,7 +665,6 @@ TEST_F(CcuRepRemMemTest, translate) | |||
| 660 | ccu_rep_rem_mem rep(&insGen, 0, rem_); | 665 | ccu_rep_rem_mem rep(&insGen, 0, rem_); |
| 661 | EXPECT_EQ(rep.type(), ccu_rep_type::rem_mem); | 666 | EXPECT_EQ(rep.type(), ccu_rep_type::rem_mem); |
| 662 | } | 667 | } |
| 663 | - | ||
| 664 | TEST_F(CcuRepReadTest, TranslateReal_GeneratesInstr) | 668 | TEST_F(CcuRepReadTest, TranslateReal_GeneratesInstr) |
| 665 | { | 669 | { |
| 666 | ccu_rep_context context_; | 670 | ccu_rep_context context_; |
| @@ -16,105 +16,104 @@ | |||
| 16 | namespace asc { | 16 | namespace asc { |
| 17 | namespace { | 17 | namespace { |
| 18 | 18 | ||
| 19 | +HcommCcuChannelEntity MakeChannelEntity() | ||
| 20 | +{ | ||
| 21 | + HcommCcuChannelEntity entity{}; | ||
| 22 | + entity.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; | ||
| 23 | + entity.header.magicWord = HCOMM_CCU_CHANNEL_MAGIC_WORD; | ||
| 24 | + entity.header.size = sizeof(HcommCcuChannelEntity); | ||
| 25 | + entity.dieId = 3; | ||
| 26 | + entity.channelId = 17; | ||
| 27 | + entity.localVarNum = 2; | ||
| 28 | + entity.remoteVarNum = 2; | ||
| 29 | + entity.localEventNum = 2; | ||
| 30 | + entity.remoteEventNum = 2; | ||
| 31 | + entity.localVarIds[0] = 21; | ||
| 32 | + entity.localVarIds[1] = 22; | ||
| 33 | + entity.remoteVarIds[0] = 121; | ||
| 34 | + entity.remoteVarIds[1] = 122; | ||
| 35 | + entity.localEventIds[0] = 11; | ||
| 36 | + entity.localEventIds[1] = 12; | ||
| 37 | + entity.remoteEventIds[0] = 111; | ||
| 38 | + entity.remoteEventIds[1] = 112; | ||
| 39 | + entity.rmtCcuResBuffer.type = REGED_BUFFER_RMA; | ||
| 40 | + entity.rmtCcuResBuffer.bufferInfo.rma.addr = 0x123456789ABCDEF0ULL; | ||
| 41 | + entity.rmtCcuResBuffer.bufferInfo.rma.size = 0x8000; | ||
| 42 | + entity.rmtCcuResBuffer.bufferInfo.rma.protectionInfo.type = PROTECTION_TYPE_UB; | ||
| 43 | + entity.rmtCcuResBuffer.bufferInfo.rma.protectionInfo.memInfo.ub.tokenId = 0x51; | ||
| 44 | + entity.rmtCcuResBuffer.bufferInfo.rma.protectionInfo.memInfo.ub.tokenValue = 0x62; | ||
| 45 | + return entity; | ||
| 46 | +} | ||
| 47 | + | ||
| 19 | class CcuChannelTest : public testing::Test { | 48 | class CcuChannelTest : public testing::Test { |
| 20 | protected: | 49 | protected: |
| 21 | void SetUp() override | 50 | void SetUp() override |
| 22 | { | 51 | { |
| 23 | - channel_pod_.header.version = HCOMM_CCU_CHANNEL_ABI_VERSION; | 52 | + channel_entity_ = MakeChannelEntity(); |
| 24 | - channel_pod_.header.magicWord = HCOMM_CCU_CHANNEL_POD_MAGIC_WORD; | 53 | + SetHcommCcuChannelGetEntityStub(channel_entity_); |
| 25 | - channel_pod_.header.size = sizeof(HcommCcuChannelPod); | ||
| 26 | - channel_pod_.dieId = 3; | ||
| 27 | - channel_pod_.channelId = 17; | ||
| 28 | - channel_pod_.localXnIds[0] = 21; | ||
| 29 | - channel_pod_.localXnIds[1] = 22; | ||
| 30 | - channel_pod_.remoteXnIds[0] = 121; | ||
| 31 | - channel_pod_.remoteXnIds[1] = 122; | ||
| 32 | - channel_pod_.localCkeIds[0] = 11; | ||
| 33 | - channel_pod_.localCkeIds[1] = 12; | ||
| 34 | - channel_pod_.remoteCkeIds[0] = 111; | ||
| 35 | - channel_pod_.remoteCkeIds[1] = 112; | ||
| 36 | - channel_pod_.rmtCcuBufAddr = 0x123456789ABCDEF0ULL; | ||
| 37 | - channel_pod_.rmtCcuBufSize = 0x8000; | ||
| 38 | - channel_pod_.rmtCcuBufTokenId = 0x51; | ||
| 39 | - channel_pod_.rmtCcuBufTokenValue = 0x62; | ||
| 40 | - SetHcommCcuChannelQueryStub(channel_pod_); | ||
| 41 | } | 54 | } |
| 42 | 55 | ||
| 43 | - void TearDown() override { ResetHcommCcuChannelQueryStub(); } | 56 | + void TearDown() override { ResetHcommCcuChannelGetEntityStub(); } |
| 44 | 57 | ||
| 45 | - HcommCcuChannelPod channel_pod_{}; | 58 | + HcommCcuChannelEntity channel_entity_{}; |
| 46 | }; | 59 | }; |
| 47 | 60 | ||
| 48 | TEST_F(CcuChannelTest, InitCopiesAllFieldsAndResources) | 61 | TEST_F(CcuChannelTest, InitCopiesAllFieldsAndResources) |
| 49 | { | 62 | { |
| 50 | - ccu_channel channel_(1); | 63 | + asc::ccu_channel channel_(1); |
| 51 | ASSERT_EQ(channel_.get_result(), HCCL_SUCCESS); | 64 | ASSERT_EQ(channel_.get_result(), HCCL_SUCCESS); |
| 52 | - EXPECT_EQ(channel_.get_die_id(), 3U); | 65 | + EXPECT_EQ(channel_->get_die_id(), 3U); |
| 53 | - EXPECT_EQ(channel_.get_channel_id(), 17U); | 66 | + EXPECT_EQ(channel_->get_channel_id(), 17U); |
| 54 | 67 | ||
| 55 | uint32_t value = 0; | 68 | uint32_t value = 0; |
| 56 | - EXPECT_EQ(channel_.get_loc_cke_by_index(0, value), HCCL_SUCCESS); | 69 | + EXPECT_EQ(channel_->get_loc_cke_by_index(0, value), HCCL_SUCCESS); |
| 57 | EXPECT_EQ(value, 11U); | 70 | EXPECT_EQ(value, 11U); |
| 58 | - EXPECT_EQ(channel_.get_loc_xn_by_index(1, value), HCCL_SUCCESS); | 71 | + EXPECT_EQ(channel_->get_loc_cke_by_index(1, value), HCCL_SUCCESS); |
| 59 | - EXPECT_EQ(value, 22U); | 72 | + EXPECT_EQ(value, 12U); |
| 60 | - EXPECT_EQ(channel_.get_rmt_cke_by_index(0, value), HCCL_SUCCESS); | 73 | + EXPECT_EQ(channel_->get_rmt_cke_by_index(0, value), HCCL_SUCCESS); |
| 61 | EXPECT_EQ(value, 111U); | 74 | EXPECT_EQ(value, 111U); |
| 62 | - EXPECT_EQ(channel_.get_rmt_xn_by_index(1, value), HCCL_SUCCESS); | 75 | + EXPECT_EQ(channel_->get_loc_xn_by_index(0, value), HCCL_SUCCESS); |
| 63 | - EXPECT_EQ(value, 122U); | 76 | + EXPECT_EQ(value, 21U); |
| 77 | + EXPECT_EQ(channel_->get_loc_xn_by_index(1, value), HCCL_SUCCESS); | ||
| 78 | + EXPECT_EQ(value, 22U); | ||
| 79 | + EXPECT_EQ(channel_->get_rmt_xn_by_index(0, value), HCCL_SUCCESS); | ||
| 80 | + EXPECT_EQ(value, 121U); | ||
| 81 | +} | ||
| 64 | 82 | ||
| 65 | - uint64_t addr_ = 0; | 83 | +TEST_F(CcuChannelTest, GetRmtBufferDecodesRegedBufferEntity) |
| 84 | +{ | ||
| 85 | + asc::ccu_channel channel_(1); | ||
| 86 | + ASSERT_EQ(channel_.get_result(), HCCL_SUCCESS); | ||
| 87 | + | ||
| 88 | + uint64_t addr = 0; | ||
| 66 | uint32_t size = 0; | 89 | uint32_t size = 0; |
| 67 | uint32_t token_id = 0; | 90 | uint32_t token_id = 0; |
| 68 | uint32_t token_value = 0; | 91 | uint32_t token_value = 0; |
| 69 | - EXPECT_EQ(channel_.get_rmt_buffer(addr_, size, token_id, token_value), HCCL_SUCCESS); | 92 | + EXPECT_EQ(channel_->get_rmt_buffer(addr, size, token_id, token_value), HCCL_SUCCESS); |
| 70 | - EXPECT_EQ(addr_, 0x123456789ABCDEF0ULL); | 93 | + EXPECT_EQ(addr, 0x123456789ABCDEF0ULL); |
| 71 | EXPECT_EQ(size, 0x8000U); | 94 | EXPECT_EQ(size, 0x8000U); |
| 72 | EXPECT_EQ(token_id, 0x51U); | 95 | EXPECT_EQ(token_id, 0x51U); |
| 73 | EXPECT_EQ(token_value, 0x62U); | 96 | EXPECT_EQ(token_value, 0x62U); |
| 74 | } | 97 | } |
| 75 | 98 | ||
| 76 | -TEST_F(CcuChannelTest, SnapshotOwnsDeepCopy) | 99 | +TEST_F(CcuChannelTest, IndexBeyondValidNumRejected) |
| 77 | { | 100 | { |
| 78 | - ccu_channel channel_(1); | 101 | + asc::ccu_channel channel_(1); |
| 79 | ASSERT_EQ(channel_.get_result(), HCCL_SUCCESS); | 102 | ASSERT_EQ(channel_.get_result(), HCCL_SUCCESS); |
| 80 | 103 | ||
| 81 | - channel_pod_.dieId = 99; | 104 | + // 有效数量 localVarNum=2:index 2 越界(容量 16 也允许更大的有效数量) |
| 82 | - channel_pod_.localCkeIds[0] = 999; | ||
| 83 | - SetHcommCcuChannelQueryStub(channel_pod_); | ||
| 84 | - | ||
| 85 | - uint32_t local_cke_id = 0; | ||
| 86 | - EXPECT_EQ(channel_.get_die_id(), 3U); | ||
| 87 | - EXPECT_EQ(channel_.get_loc_cke_by_index(0, local_cke_id), HCCL_SUCCESS); | ||
| 88 | - EXPECT_EQ(local_cke_id, 11U); | ||
| 89 | -} | ||
| 90 | - | ||
| 91 | -TEST_F(CcuChannelTest, ResourceIndexOutOfRangeReturnsParameterError) | ||
| 92 | -{ | ||
| 93 | - ccu_channel channel_(1); | ||
| 94 | - ASSERT_EQ(channel_.get_result(), HCCL_SUCCESS); | ||
| 95 | uint32_t value = 0; | 105 | uint32_t value = 0; |
| 96 | - EXPECT_EQ(channel_.get_loc_cke_by_index(HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY, value), HCCL_E_PARA); | 106 | + EXPECT_NE(channel_->get_loc_xn_by_index(2, value), HCCL_SUCCESS); |
| 97 | - EXPECT_EQ(channel_.get_loc_xn_by_index(HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY, value), HCCL_E_PARA); | 107 | + EXPECT_NE(channel_->get_rmt_cke_by_index(2, value), HCCL_SUCCESS); |
| 98 | - EXPECT_EQ(channel_.get_rmt_cke_by_index(HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY, value), HCCL_E_PARA); | ||
| 99 | - EXPECT_EQ(channel_.get_rmt_xn_by_index(HCOMM_CCU_CHANNEL_RESOURCE_CAPACITY, value), HCCL_E_PARA); | ||
| 100 | } | 108 | } |
| 101 | 109 | ||
| 102 | -TEST_F(CcuChannelTest, FirstQueryFailureIsPropagated) | 110 | +TEST_F(CcuChannelTest, UnreadyRemoteBufferRejected) |
| 103 | { | 111 | { |
| 104 | - SetHcommCcuChannelQueryStubResult(HCCL_E_UNAVAIL); | 112 | + HcommCcuChannelEntity entity = MakeChannelEntity(); |
| 105 | - ccu_channel channel_(1); | 113 | + entity.rmtCcuResBuffer.bufferInfo.rma.size = 0; // 远端资源空间未就绪 |
| 106 | - EXPECT_EQ(channel_.get_result(), HCCL_E_UNAVAIL); | 114 | + SetHcommCcuChannelGetEntityStub(entity); |
| 107 | - | 115 | + asc::ccu_channel channel_(1); |
| 108 | - uint32_t value = 0; | 116 | + EXPECT_NE(channel_.get_result(), HCCL_SUCCESS); |
| 109 | - EXPECT_EQ(channel_.get_loc_cke_by_index(0, value), HCCL_E_UNAVAIL); | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | -TEST_F(CcuChannelTest, RemoteBufferSizeZeroReturnsInternalError) | ||
| 113 | -{ | ||
| 114 | - channel_pod_.rmtCcuBufSize = 0; | ||
| 115 | - SetHcommCcuChannelQueryStub(channel_pod_); | ||
| 116 | - ccu_channel channel_(1); | ||
| 117 | - EXPECT_EQ(channel_.get_result(), HCCL_E_INTERNAL); | ||
| 118 | } | 117 | } |
| 119 | 118 | ||
| 120 | } // namespace | 119 | } // namespace |
| @@ -19,123 +19,144 @@ | |||
| 19 | namespace asc { | 19 | namespace asc { |
| 20 | namespace { | 20 | namespace { |
| 21 | 21 | ||
| 22 | +// 把 range 存进 dieResources[die][type],元数据存进 metadata 实体 | ||
| 22 | struct ContextStorage { | 23 | struct ContextStorage { |
| 23 | - HcommCcuRegisterContextPod context_{}; | 24 | + HcommCcuInstance instance_{}; |
| 24 | - std::vector<HcommCcuResRangePod> instance{{HCOMM_CCU_BATCH_RES_LOOP, 0, 10, 4}}; | 25 | + HcommCcuDieMetadata dieMetadata[HCOMM_CCU_MAX_DIE_NUM]{}; |
| 26 | + std::vector<HcommCcuResRange> dieRanges[HCOMM_CCU_MAX_DIE_NUM][HCOMM_CCU_BATCH_RES_TYPE_COUNT]{}; | ||
| 25 | 27 | ||
| 26 | ContextStorage() | 28 | ContextStorage() |
| 27 | { | 29 | { |
| 28 | - context_.header = { | 30 | + instance_.header = {HCOMM_CCU_RES_ABI_VERSION, HCOMM_CCU_INSTANCE_MAGIC_WORD, sizeof(HcommCcuInstance), 0}; |
| 29 | - HCOMM_CCU_RES_ABI_VERSION, HCOMM_CCU_REGISTER_CONTEXT_MAGIC_WORD, sizeof(HcommCcuRegisterContextPod), 0}; | 31 | + instance_.ccuDieNum = HCOMM_CCU_MAX_DIE_NUM; |
| 30 | - context_.generation = 1; | 32 | + instance_.ccuVersion = HCOMM_CCU_VERSION_V1; |
| 31 | - context_.deviceLogicId = 0; | 33 | + instance_.ascCustom[HCOMM_CCU_ASC_CUSTOM_CHANNEL_ENTITY] = 0x1; |
| 32 | - context_.ccuVersion = 0; | 34 | + instance_.ascCustom[HCOMM_CCU_ASC_CUSTOM_ALLOC_INST_SPACE] = 0x1; |
| 33 | - context_.dieNum = HCOMM_CCU_MAX_DIE_NUM; | 35 | + instance_.ascCustom[HCOMM_CCU_ASC_CUSTOM_SUBMIT_INSTS] = 0x1; |
| 34 | - context_.validDieMask = 1; | 36 | + |
| 35 | - context_.die[0].enabled = 1; | 37 | + dieMetadata[0].header = { |
| 36 | - context_.controlOps.header = { | 38 | + HCOMM_CCU_RES_ABI_VERSION, HCOMM_CCU_DIE_METADATA_MAGIC_WORD, sizeof(HcommCcuDieMetadata), 0}; |
| 37 | - HCOMM_CCU_CONTROL_ABI_VERSION, HCOMM_CCU_CONTROL_OPS_MAGIC_WORD, sizeof(HcommCcuControlOpsPod), 0}; | 39 | + dieMetadata[0].enabled = 1; |
| 38 | - context_.controlOps.channelQuery = +[](ChannelHandle, HcommCcuChannelPod*) -> int32_t { return 0; }; | 40 | + dieMetadata[0].ccuResBuffer.type = REGED_BUFFER_RMA; |
| 39 | - context_.controlOps.loadInstruction = +[](const HcommCcuInstructionLoadPod*) -> int32_t { return 0; }; | 41 | + dieMetadata[0].ccuResBuffer.bufferInfo.rma.addr = 0x1000; |
| 40 | - context_.controlOps.missionContextQuery = | 42 | + dieMetadata[0].ccuResBuffer.bufferInfo.rma.size = 0x1000; |
| 41 | - +[](int32_t, uint32_t, uint32_t, HcommCcuMissionContextPod*) -> int32_t { return 0; }; | 43 | + dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP].push_back({10, 4, 0}); |
| 42 | - context_.controlOps.loopContextQuery = | ||
| 43 | - +[](int32_t, uint32_t, uint32_t, HcommCcuLoopContextPod*) -> int32_t { return 0; }; | ||
| 44 | - context_.controlOps.ckeQuery = +[](int32_t, uint32_t, uint32_t, uint64_t*) -> int32_t { return 0; }; | ||
| 45 | - context_.controlOps.xnQuery = +[](int32_t, uint32_t, uint32_t, uint64_t*) -> int32_t { return 0; }; | ||
| 46 | - context_.controlOps.gsaQuery = +[](int32_t, uint32_t, uint32_t, uint64_t*) -> int32_t { return 0; }; | ||
| 47 | RefreshViews(); | 44 | RefreshViews(); |
| 48 | } | 45 | } |
| 49 | 46 | ||
| 50 | - void RefreshViews() { context_.instanceResources = {instance.data(), static_cast<uint32_t>(instance.size()), 0}; } | 47 | + void RefreshViews() |
| 48 | + { | ||
| 49 | + for (uint32_t die = 0; die < HCOMM_CCU_MAX_DIE_NUM; ++die) { | ||
| 50 | + HcommCcuDieRes& dieRes = instance_.ccuDieReses[die]; | ||
| 51 | + dieRes.dieId = die; | ||
| 52 | + dieRes.resTypeNum = 0; | ||
| 53 | + for (uint32_t type = 0; type < HCOMM_CCU_BATCH_RES_TYPE_COUNT; ++type) { | ||
| 54 | + HcommCcuResRanges& view = dieRes.resTypes[type]; | ||
| 55 | + view = HcommCcuResRanges{}; | ||
| 56 | + view.resourceType = type; | ||
| 57 | + if (!dieRanges[die][type].empty()) { | ||
| 58 | + view.resRanges = dieRanges[die][type].data(); | ||
| 59 | + view.resRangeNum = static_cast<uint32_t>(dieRanges[die][type].size()); | ||
| 60 | + dieRes.resTypeNum = type + 1; | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + dieRes.dieMetadata = dieMetadata[die].enabled != 0 ? &dieMetadata[die] : nullptr; | ||
| 64 | + } | ||
| 65 | + } | ||
| 51 | }; | 66 | }; |
| 52 | 67 | ||
| 53 | TEST(AscCcuResSnapshotTest, DeepCopiesAndResetsOrdinaryResources) | 68 | TEST(AscCcuResSnapshotTest, DeepCopiesAndResetsOrdinaryResources) |
| 54 | { | 69 | { |
| 55 | ContextStorage storage; | 70 | ContextStorage storage; |
| 56 | asc::asc_ccu_res_snapshot pack; | 71 | asc::asc_ccu_res_snapshot pack; |
| 57 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | 72 | + ASSERT_EQ(pack.load(storage.instance_), CcuResult::CCU_SUCCESS); |
| 58 | 73 | ||
| 59 | - storage.instance[0].startId = 999; | 74 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP][0].startId = 999; |
| 60 | - ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[0][0].startId, 10U); | 75 | + ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[0][0].start_id, 10U); |
| 61 | pack.get_ccu_res_repo().loop_engine[0].clear(); | 76 | pack.get_ccu_res_repo().loop_engine[0].clear(); |
| 62 | ASSERT_EQ(pack.reset(), CcuResult::CCU_SUCCESS); | 77 | ASSERT_EQ(pack.reset(), CcuResult::CCU_SUCCESS); |
| 63 | ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[0].size(), 1U); | 78 | ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[0].size(), 1U); |
| 64 | - EXPECT_EQ(pack.get_ccu_res_repo().loop_engine[0][0].startId, 10U); | 79 | + EXPECT_EQ(pack.get_ccu_res_repo().loop_engine[0][0].start_id, 10U); |
| 80 | +} | ||
| 81 | + | ||
| 82 | +TEST(AscCcuResSnapshotTest, ExposesDieMetadataSnapshot) | ||
| 83 | +{ | ||
| 84 | + ContextStorage storage; | ||
| 85 | + asc::asc_ccu_res_snapshot pack; | ||
| 86 | + ASSERT_EQ(pack.load(storage.instance_), CcuResult::CCU_SUCCESS); | ||
| 87 | + const HcommCcuDieMetadata* metadata = pack.get_die_metadata(0); | ||
| 88 | + ASSERT_NE(metadata, nullptr); | ||
| 89 | + EXPECT_EQ(metadata->ccuResBuffer.bufferInfo.rma.addr, 0x1000U); | ||
| 90 | + EXPECT_EQ(pack.get_ccu_version(), HCOMM_CCU_VERSION_V1); | ||
| 91 | + EXPECT_EQ(pack.get_die_metadata(1), nullptr); // die 1 未启用 | ||
| 65 | } | 92 | } |
| 66 | 93 | ||
| 67 | TEST(AscCcuResSnapshotTest, RejectsInvalidAbiDieTypeOverflowAndOverlap) | 94 | TEST(AscCcuResSnapshotTest, RejectsInvalidAbiDieTypeOverflowAndOverlap) |
| 68 | { | 95 | { |
| 69 | { | 96 | { |
| 70 | ContextStorage storage; | 97 | ContextStorage storage; |
| 71 | - storage.context_.header.magicWord = 0; | 98 | + storage.instance_.header.magicWord = 0; |
| 72 | asc::asc_ccu_res_snapshot pack; | 99 | asc::asc_ccu_res_snapshot pack; |
| 73 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 100 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 74 | } | 101 | } |
| 75 | { | 102 | { |
| 76 | ContextStorage storage; | 103 | ContextStorage storage; |
| 77 | - storage.instance[0].dieId = HCOMM_CCU_MAX_DIE_NUM; | 104 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP][0].startId = std::numeric_limits<uint32_t>::max(); |
| 105 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP][0].count = 2; | ||
| 78 | asc::asc_ccu_res_snapshot pack; | 106 | asc::asc_ccu_res_snapshot pack; |
| 79 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 107 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 80 | } | 108 | } |
| 81 | { | 109 | { |
| 82 | ContextStorage storage; | 110 | ContextStorage storage; |
| 83 | - storage.instance[0].resourceType = HCOMM_CCU_RES_INSTRUCTION; | 111 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP].push_back({12, 4, 0}); // 与 [10,4) 重叠 |
| 84 | - asc::asc_ccu_res_snapshot pack; | ||
| 85 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | ||
| 86 | - ASSERT_EQ(pack.get_ccu_res_repo().instruction[0].size(), 1U); | ||
| 87 | - EXPECT_EQ(pack.get_ccu_res_repo().instruction[0][0].startId, 10U); | ||
| 88 | - } | ||
| 89 | - { | ||
| 90 | - ContextStorage storage; | ||
| 91 | - storage.instance[0].resourceType = HCOMM_CCU_RES_INSTRUCTION + 1; | ||
| 92 | - asc::asc_ccu_res_snapshot pack; | ||
| 93 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | ||
| 94 | - } | ||
| 95 | - { | ||
| 96 | - ContextStorage storage; | ||
| 97 | - storage.instance[0].startId = std::numeric_limits<uint32_t>::max(); | ||
| 98 | - storage.instance[0].count = 2; | ||
| 99 | - asc::asc_ccu_res_snapshot pack; | ||
| 100 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | ||
| 101 | - } | ||
| 102 | - { | ||
| 103 | - ContextStorage storage; | ||
| 104 | - storage.instance.push_back({HCOMM_CCU_BATCH_RES_LOOP, 0, 12, 4}); | ||
| 105 | storage.RefreshViews(); | 112 | storage.RefreshViews(); |
| 106 | asc::asc_ccu_res_snapshot pack; | 113 | asc::asc_ccu_res_snapshot pack; |
| 107 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 114 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 115 | + } | ||
| 116 | + { | ||
| 117 | + ContextStorage storage; | ||
| 118 | + storage.instance_.ccuDieReses[0].dieId = 1; // die 槽位与 dieId 不一致 | ||
| 119 | + asc::asc_ccu_res_snapshot pack; | ||
| 120 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); | ||
| 121 | + } | ||
| 122 | + { | ||
| 123 | + ContextStorage storage; | ||
| 124 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP][0].reserved = 1; // wire range 保留字段非零 | ||
| 125 | + asc::asc_ccu_res_snapshot pack; | ||
| 126 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); | ||
| 108 | } | 127 | } |
| 109 | -} | ||
| 110 | - | ||
| 111 | -TEST(AscCcuResSnapshotTest, RejectsGenerationChange) | ||
| 112 | -{ | ||
| 113 | - ContextStorage storage; | ||
| 114 | - asc::asc_ccu_res_snapshot pack; | ||
| 115 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | ||
| 116 | - storage.context_.generation = 2; | ||
| 117 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | ||
| 118 | } | 128 | } |
| 119 | 129 | ||
| 120 | TEST(AscCcuResSnapshotTest, RejectsReservedAndInvalidDisabledDieMetadata) | 130 | TEST(AscCcuResSnapshotTest, RejectsReservedAndInvalidDisabledDieMetadata) |
| 121 | { | 131 | { |
| 122 | { | 132 | { |
| 123 | ContextStorage storage; | 133 | ContextStorage storage; |
| 124 | - storage.context_.reserved[0] = 1; | 134 | + storage.instance_.ccuDieReses[2].reserved[0] = 1; // 超出 ccuDieNum 的预留 die 槽保留字段非零 |
| 125 | asc::asc_ccu_res_snapshot pack; | 135 | asc::asc_ccu_res_snapshot pack; |
| 126 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 136 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 127 | } | 137 | } |
| 128 | { | 138 | { |
| 129 | ContextStorage storage; | 139 | ContextStorage storage; |
| 130 | - storage.context_.die[0].enabled = 2; | 140 | + storage.instance_.ccuVersion = HCOMM_CCU_VERSION_INVALID; // Instance 版本无效 |
| 131 | asc::asc_ccu_res_snapshot pack; | 141 | asc::asc_ccu_res_snapshot pack; |
| 132 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 142 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 133 | } | 143 | } |
| 134 | { | 144 | { |
| 135 | ContextStorage storage; | 145 | ContextStorage storage; |
| 136 | - storage.context_.die[1].missionKey = 1; | 146 | + storage.dieMetadata[0].enabled = 2; |
| 137 | asc::asc_ccu_res_snapshot pack; | 147 | asc::asc_ccu_res_snapshot pack; |
| 138 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 148 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 149 | + } | ||
| 150 | + { | ||
| 151 | + ContextStorage storage; | ||
| 152 | + // die 1 未启用(validDieMask=1)却携带了元数据指针 | ||
| 153 | + storage.dieMetadata[1].header = { | ||
| 154 | + HCOMM_CCU_RES_ABI_VERSION, HCOMM_CCU_DIE_METADATA_MAGIC_WORD, sizeof(HcommCcuDieMetadata), 0}; | ||
| 155 | + storage.dieMetadata[1].ccuResBuffer.type = REGED_BUFFER_RMA; | ||
| 156 | + // die 1 未启用(metadata.enabled=0)却携带元数据指针 | ||
| 157 | + storage.instance_.ccuDieReses[1].dieMetadata = &storage.dieMetadata[1]; | ||
| 158 | + asc::asc_ccu_res_snapshot pack; | ||
| 159 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); | ||
| 139 | } | 160 | } |
| 140 | } | 161 | } |
| 141 | 162 | ||
| @@ -143,92 +164,29 @@ TEST(AscCcuResSnapshotTest, FailedLoadDoesNotReplaceActiveSnapshot) | |||
| 143 | { | 164 | { |
| 144 | ContextStorage storage; | 165 | ContextStorage storage; |
| 145 | asc::asc_ccu_res_snapshot pack; | 166 | asc::asc_ccu_res_snapshot pack; |
| 146 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | 167 | + ASSERT_EQ(pack.load(storage.instance_), CcuResult::CCU_SUCCESS); |
| 147 | 168 | ||
| 148 | - storage.instance[0].startId = std::numeric_limits<uint32_t>::max(); | 169 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP][0].startId = std::numeric_limits<uint32_t>::max(); |
| 149 | - storage.instance[0].count = 2; | 170 | + storage.dieRanges[0][HCOMM_CCU_BATCH_RES_LOOP][0].count = 2; |
| 150 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | 171 | + EXPECT_EQ(pack.load(storage.instance_), CcuResult::CCU_E_PARA); |
| 151 | ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[0].size(), 1U); | 172 | ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[0].size(), 1U); |
| 152 | - EXPECT_EQ(pack.get_ccu_res_repo().loop_engine[0][0].startId, 10U); | 173 | + EXPECT_EQ(pack.get_ccu_res_repo().loop_engine[0][0].start_id, 10U); |
| 153 | - EXPECT_EQ(pack.get_generation(), 1U); | ||
| 154 | } | 174 | } |
| 155 | 175 | ||
| 156 | TEST(AscCcuResSnapshotTest, SupportsTwoDies) | 176 | TEST(AscCcuResSnapshotTest, SupportsTwoDies) |
| 157 | { | 177 | { |
| 158 | ContextStorage storage; | 178 | ContextStorage storage; |
| 159 | - storage.context_.validDieMask = 3; | 179 | + storage.dieMetadata[1].header = { |
| 160 | - storage.context_.die[1].enabled = 1; | 180 | + HCOMM_CCU_RES_ABI_VERSION, HCOMM_CCU_DIE_METADATA_MAGIC_WORD, sizeof(HcommCcuDieMetadata), 0}; |
| 161 | - storage.instance.push_back({HCOMM_CCU_BATCH_RES_LOOP, 1, 20, 2}); | 181 | + storage.dieMetadata[1].enabled = 1; |
| 182 | + storage.dieMetadata[1].ccuResBuffer.type = REGED_BUFFER_RMA; | ||
| 183 | + storage.dieRanges[1][HCOMM_CCU_BATCH_RES_LOOP].push_back({20, 2, 0}); | ||
| 162 | storage.RefreshViews(); | 184 | storage.RefreshViews(); |
| 163 | 185 | ||
| 164 | asc::asc_ccu_res_snapshot pack; | 186 | asc::asc_ccu_res_snapshot pack; |
| 165 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | 187 | + ASSERT_EQ(pack.load(storage.instance_), CcuResult::CCU_SUCCESS); |
| 166 | ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[1].size(), 1U); | 188 | ASSERT_EQ(pack.get_ccu_res_repo().loop_engine[1].size(), 1U); |
| 167 | - EXPECT_EQ(pack.get_ccu_res_repo().loop_engine[1][0].startId, 20U); | 189 | + EXPECT_EQ(pack.get_ccu_res_repo().loop_engine[1][0].start_id, 20U); |
| 168 | -} | ||
| 169 | - | ||
| 170 | -TEST(AscCcuResSnapshotTest, LoadsAllRepositoryResourceTypes) | ||
| 171 | -{ | ||
| 172 | - ContextStorage storage; | ||
| 173 | - // 覆盖 get_ranges 的全部资源类型分支 | ||
| 174 | - storage.instance = { | ||
| 175 | - {HCOMM_CCU_BATCH_RES_LOOP, 0, 10, 4}, {HCOMM_CCU_BATCH_RES_BLOCK_LOOP, 0, 11, 4}, | ||
| 176 | - {HCOMM_CCU_BATCH_RES_MS, 0, 12, 4}, {HCOMM_CCU_BATCH_RES_BLOCK_MS, 0, 13, 4}, | ||
| 177 | - {HCOMM_CCU_BATCH_RES_CKE, 0, 14, 4}, {HCOMM_CCU_BATCH_RES_BLOCK_CKE, 0, 15, 4}, | ||
| 178 | - {HCOMM_CCU_BATCH_RES_XN, 0, 16, 4}, {HCOMM_CCU_BATCH_RES_BLOCK_XN, 0, 17, 4}, | ||
| 179 | - {HCOMM_CCU_BATCH_RES_GSA, 0, 18, 4}, {HCOMM_CCU_BATCH_RES_BLOCK_GSA, 0, 19, 4}, | ||
| 180 | - {HCOMM_CCU_BATCH_RES_MISSION, 0, 20, 4}, {HCOMM_CCU_RES_INSTRUCTION, 0, 21, 4}, | ||
| 181 | - }; | ||
| 182 | - storage.RefreshViews(); | ||
| 183 | - | ||
| 184 | - asc::asc_ccu_res_snapshot pack; | ||
| 185 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | ||
| 186 | - const asc_ccu_res_repository& repo = pack.get_ccu_res_repo(); | ||
| 187 | - EXPECT_EQ(repo.loop_engine[0].size(), 1U); | ||
| 188 | - EXPECT_EQ(repo.block_loop_engine[0].size(), 1U); | ||
| 189 | - EXPECT_EQ(repo.ms[0].size(), 1U); | ||
| 190 | - EXPECT_EQ(repo.block_ms[0].size(), 1U); | ||
| 191 | - EXPECT_EQ(repo.cke[0].size(), 1U); | ||
| 192 | - EXPECT_EQ(repo.block_cke[0].size(), 1U); | ||
| 193 | - EXPECT_EQ(repo.xn[0].size(), 1U); | ||
| 194 | - EXPECT_EQ(repo.block_xn[0].size(), 1U); | ||
| 195 | - EXPECT_EQ(repo.gsa[0].size(), 1U); | ||
| 196 | - EXPECT_EQ(repo.block_gsa[0].size(), 1U); | ||
| 197 | - EXPECT_EQ(repo.mission[0].size(), 1U); | ||
| 198 | - EXPECT_EQ(repo.instruction[0].size(), 1U); | ||
| 199 | -} | ||
| 200 | - | ||
| 201 | -TEST(AscCcuResSnapshotTest, RejectsUnknownResourceType) | ||
| 202 | -{ | ||
| 203 | - ContextStorage storage; | ||
| 204 | - storage.instance = {{0xFFFF, 0, 10, 4}}; // 未定义的资源类型 | ||
| 205 | - storage.RefreshViews(); | ||
| 206 | - | ||
| 207 | - asc::asc_ccu_res_snapshot pack; | ||
| 208 | - EXPECT_EQ(pack.load(storage.context_), CcuResult::CCU_E_PARA); | ||
| 209 | -} | ||
| 210 | - | ||
| 211 | -TEST(AscCcuResSnapshotTest, ResetWithoutLoadReturnsUnavail) | ||
| 212 | -{ | ||
| 213 | - asc::asc_ccu_res_snapshot pack; | ||
| 214 | - EXPECT_EQ(pack.reset(), CcuResult::CCU_E_UNAVAIL); | ||
| 215 | -} | ||
| 216 | - | ||
| 217 | -TEST(AscCcuResSnapshotTest, GettersExposeSnapshotFields) | ||
| 218 | -{ | ||
| 219 | - ContextStorage storage; | ||
| 220 | - asc::asc_ccu_res_snapshot pack; | ||
| 221 | - ASSERT_EQ(pack.load(storage.context_), CcuResult::CCU_SUCCESS); | ||
| 222 | - | ||
| 223 | - EXPECT_EQ(pack.get_generation(), storage.context_.generation); | ||
| 224 | - EXPECT_EQ(pack.get_device_logic_id(), storage.context_.deviceLogicId); | ||
| 225 | - EXPECT_EQ(pack.get_ccu_version(), storage.context_.ccuVersion); | ||
| 226 | - EXPECT_EQ(pack.get_valid_die_mask(), storage.context_.validDieMask); | ||
| 227 | - EXPECT_NE(pack.get_die_metadata(0), nullptr); | ||
| 228 | - EXPECT_EQ(pack.get_die_metadata(1), nullptr); // validDieMask=1, die1 无效 | ||
| 229 | - EXPECT_EQ(pack.get_die_metadata(HCOMM_CCU_MAX_DIE_NUM), nullptr); // 越界 | ||
| 230 | - // control_ops 快照与原 POD 一致 | ||
| 231 | - EXPECT_EQ(pack.get_control_ops().header.magicWord, storage.context_.controlOps.header.magicWord); | ||
| 232 | } | 190 | } |
| 233 | 191 | ||
| 234 | } // namespace | 192 | } // namespace |
| @@ -14,8 +14,15 @@ | |||
| 14 | 14 | ||
| 15 | namespace asc { | 15 | namespace asc { |
| 16 | namespace { | 16 | namespace { |
| 17 | +using asc::asc_ccu_res_range; | ||
| 18 | +using asc::asc_ccu_res_repository; | ||
| 19 | +using asc::asc_ccu_res_request; | ||
| 20 | +using asc::plan_kernel_resources; | ||
| 17 | 21 | ||
| 18 | -HcommCcuResRangePod Range(uint32_t type_, uint32_t startId, uint32_t count_) { return {type_, 0, startId, count_}; } | 22 | +asc_ccu_res_range Range(uint32_t resource_type, uint32_t start_id, uint32_t count) |
| 23 | +{ | ||
| 24 | + return {resource_type, 0, start_id, count}; | ||
| 25 | +} | ||
| 19 | 26 | ||
| 20 | TEST(CcuKernelResAllocatorTest, NormalRequestFallsBackToBlockPool) | 27 | TEST(CcuKernelResAllocatorTest, NormalRequestFallsBackToBlockPool) |
| 21 | { | 28 | { |
| @@ -30,12 +37,12 @@ TEST(CcuKernelResAllocatorTest, NormalRequestFallsBackToBlockPool) | |||
| 30 | asc_ccu_res_repository allocated{}; | 37 | asc_ccu_res_repository allocated{}; |
| 31 | ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); | 38 | ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); |
| 32 | ASSERT_EQ(allocated.cke[0].size(), 1); | 39 | ASSERT_EQ(allocated.cke[0].size(), 1); |
| 33 | - EXPECT_EQ(allocated.cke[0][0].resourceType, HCOMM_CCU_BATCH_RES_CKE); | 40 | + EXPECT_EQ(allocated.cke[0][0].resource_type, HCOMM_CCU_BATCH_RES_CKE); |
| 34 | - EXPECT_EQ(allocated.cke[0][0].startId, 10); | 41 | + EXPECT_EQ(allocated.cke[0][0].start_id, 10); |
| 35 | EXPECT_EQ(allocated.cke[0][0].count, 1); | 42 | EXPECT_EQ(allocated.cke[0][0].count, 1); |
| 36 | ASSERT_EQ(allocated.gsa[0].size(), 1); | 43 | ASSERT_EQ(allocated.gsa[0].size(), 1); |
| 37 | - EXPECT_EQ(allocated.gsa[0][0].resourceType, HCOMM_CCU_BATCH_RES_GSA); | 44 | + EXPECT_EQ(allocated.gsa[0][0].resource_type, HCOMM_CCU_BATCH_RES_GSA); |
| 38 | - EXPECT_EQ(allocated.gsa[0][0].startId, 100); | 45 | + EXPECT_EQ(allocated.gsa[0][0].start_id, 100); |
| 39 | EXPECT_EQ(allocated.gsa[0][0].count, 8); | 46 | EXPECT_EQ(allocated.gsa[0][0].count, 8); |
| 40 | ASSERT_EQ(remaining.block_cke[0].size(), 1); | 47 | ASSERT_EQ(remaining.block_cke[0].size(), 1); |
| 41 | EXPECT_EQ(remaining.block_cke[0][0].count, 47); | 48 | EXPECT_EQ(remaining.block_cke[0][0].count, 47); |
| @@ -56,12 +63,12 @@ TEST(CcuKernelResAllocatorTest, BlockRequestIsPlannedBeforeNormalRequest) | |||
| 56 | asc_ccu_res_repository allocated{}; | 63 | asc_ccu_res_repository allocated{}; |
| 57 | ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); | 64 | ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); |
| 58 | ASSERT_EQ(allocated.block_cke[0].size(), 1); | 65 | ASSERT_EQ(allocated.block_cke[0].size(), 1); |
| 59 | - EXPECT_EQ(allocated.block_cke[0][0].startId, 0); | 66 | + EXPECT_EQ(allocated.block_cke[0][0].start_id, 0); |
| 60 | EXPECT_EQ(allocated.block_cke[0][0].count, 8); | 67 | EXPECT_EQ(allocated.block_cke[0][0].count, 8); |
| 61 | ASSERT_EQ(allocated.cke[0].size(), 2); | 68 | ASSERT_EQ(allocated.cke[0].size(), 2); |
| 62 | - EXPECT_EQ(allocated.cke[0][0].startId, 100); | 69 | + EXPECT_EQ(allocated.cke[0][0].start_id, 100); |
| 63 | - EXPECT_EQ(allocated.cke[0][1].startId, 8); | 70 | + EXPECT_EQ(allocated.cke[0][1].start_id, 8); |
| 64 | - EXPECT_EQ(allocated.cke[0][1].resourceType, HCOMM_CCU_BATCH_RES_CKE); | 71 | + EXPECT_EQ(allocated.cke[0][1].resource_type, HCOMM_CCU_BATCH_RES_CKE); |
| 65 | } | 72 | } |
| 66 | 73 | ||
| 67 | TEST(CcuKernelResAllocatorTest, FragmentedBlockPoolFailsWithoutChangingOutputs) | 74 | TEST(CcuKernelResAllocatorTest, FragmentedBlockPoolFailsWithoutChangingOutputs) |
| @@ -78,9 +85,9 @@ TEST(CcuKernelResAllocatorTest, FragmentedBlockPoolFailsWithoutChangingOutputs) | |||
| 78 | 85 | ||
| 79 | EXPECT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_E_UNAVAIL); | 86 | EXPECT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_E_UNAVAIL); |
| 80 | ASSERT_EQ(remaining.ms[0].size(), 1); | 87 | ASSERT_EQ(remaining.ms[0].size(), 1); |
| 81 | - EXPECT_EQ(remaining.ms[0][0].startId, 77); | 88 | + EXPECT_EQ(remaining.ms[0][0].start_id, 77); |
| 82 | ASSERT_EQ(allocated.gsa[0].size(), 1); | 89 | ASSERT_EQ(allocated.gsa[0].size(), 1); |
| 83 | - EXPECT_EQ(allocated.gsa[0][0].startId, 88); | 90 | + EXPECT_EQ(allocated.gsa[0][0].start_id, 88); |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 86 | TEST(CcuKernelResAllocatorTest, NormalRequestPreservesReservedGap) | 93 | TEST(CcuKernelResAllocatorTest, NormalRequestPreservesReservedGap) |
| @@ -95,32 +102,16 @@ TEST(CcuKernelResAllocatorTest, NormalRequestPreservesReservedGap) | |||
| 95 | asc_ccu_res_repository allocated{}; | 102 | asc_ccu_res_repository allocated{}; |
| 96 | ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); | 103 | ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); |
| 97 | ASSERT_EQ(allocated.gsa[0].size(), 2); | 104 | ASSERT_EQ(allocated.gsa[0].size(), 2); |
| 98 | - EXPECT_EQ(allocated.gsa[0][0].startId, 0); | 105 | + EXPECT_EQ(allocated.gsa[0][0].start_id, 0); |
| 99 | EXPECT_EQ(allocated.gsa[0][0].count, 4); | 106 | EXPECT_EQ(allocated.gsa[0][0].count, 4); |
| 100 | - EXPECT_EQ(allocated.gsa[0][1].startId, 8); | 107 | + EXPECT_EQ(allocated.gsa[0][1].start_id, 8); |
| 101 | EXPECT_EQ(allocated.gsa[0][1].count, 2); | 108 | EXPECT_EQ(allocated.gsa[0][1].count, 2); |
| 102 | ASSERT_EQ(remaining.block_gsa[0].size(), 1); | 109 | ASSERT_EQ(remaining.block_gsa[0].size(), 1); |
| 103 | - EXPECT_EQ(remaining.block_gsa[0][0].startId, 10); | 110 | + EXPECT_EQ(remaining.block_gsa[0][0].start_id, 10); |
| 104 | } | 111 | } |
| 105 | 112 | ||
| 106 | -TEST(CcuKernelResAllocatorTest, InstructionRequestNeedsContiguousRange) | 113 | +// INS 不再走 range 池:指令空间由 ascCustom.allocInstSpace 向 hcomm 申请(见 ccu_kernel_mgr), |
| 107 | -{ | 114 | +// allocator 不再切分 instruction 池,原连续区间用例已随该机制移除。 |
| 108 | - asc_ccu_res_repository available{}; | ||
| 109 | - available.instruction[0].push_back(Range(HCOMM_CCU_RES_INSTRUCTION, 0, 4)); | ||
| 110 | - available.instruction[0].push_back(Range(HCOMM_CCU_RES_INSTRUCTION, 8, 8)); | ||
| 111 | - asc_ccu_res_request request{}; | ||
| 112 | - request.instruction[0] = 6; | ||
| 113 | - | ||
| 114 | - asc_ccu_res_repository remaining{}; | ||
| 115 | - asc_ccu_res_repository allocated{}; | ||
| 116 | - ASSERT_EQ(plan_kernel_resources(available, request, remaining, allocated), CcuResult::CCU_SUCCESS); | ||
| 117 | - ASSERT_EQ(allocated.instruction[0].size(), 1); | ||
| 118 | - EXPECT_EQ(allocated.instruction[0][0].startId, 8); | ||
| 119 | - EXPECT_EQ(allocated.instruction[0][0].count, 6); | ||
| 120 | - ASSERT_EQ(remaining.instruction[0].size(), 2); | ||
| 121 | - EXPECT_EQ(remaining.instruction[0][1].startId, 14); | ||
| 122 | - EXPECT_EQ(remaining.instruction[0][1].count, 2); | ||
| 123 | -} | ||
| 124 | 115 | ||
| 125 | } // namespace | 116 | } // namespace |
| 126 | } // namespace asc | 117 | } // namespace asc |
| @@ -36,4 +36,26 @@ using u32 = uint32_t; | |||
| 36 | } \ | 36 | } \ |
| 37 | } while (0) | 37 | } while (0) |
| 38 | 38 | ||
| 39 | +#define CHK_RET(expression) \ | ||
| 40 | + do { \ | ||
| 41 | + const HcclResult result = (expression); \ | ||
| 42 | + if (result != HCCL_SUCCESS) { \ | ||
| 43 | + return result; \ | ||
| 44 | + } \ | ||
| 45 | + } while (0) | ||
| 46 | + | ||
| 47 | +#define CHK_SAFETY_FUNC_RET(expression) \ | ||
| 48 | + do { \ | ||
| 49 | + if ((expression) != 0) { \ | ||
| 50 | + return HCCL_E_INTERNAL; \ | ||
| 51 | + } \ | ||
| 52 | + } while (0) | ||
| 53 | + | ||
| 54 | +#define CHK_PTR_NULL(pointer) \ | ||
| 55 | + do { \ | ||
| 56 | + if ((pointer) == nullptr) { \ | ||
| 57 | + return HCCL_E_PTR; \ | ||
| 58 | + } \ | ||
| 59 | + } while (0) | ||
| 60 | + | ||
| 39 | #endif | 61 | #endif |
| @@ -15,6 +15,6 @@ | |||
| 15 | 15 | ||
| 16 | #include "hcomm_primitives.h" | 16 | #include "hcomm_primitives.h" |
| 17 | 17 | ||
| 18 | -typedef HcclResult HcommResult; | 18 | +#include "hcomm/hcomm_ccu_resource.h" // 提供 HcommResult(hcomm_res_defs)与 Channel POD |
| 19 | 19 | ||
| 20 | #endif | 20 | #endif |
| @@ -12,50 +12,59 @@ | |||
| 12 | 12 | ||
| 13 | #include "hcomm/common/ccu_device_context.h" | 13 | #include "hcomm/common/ccu_device_context.h" |
| 14 | 14 | ||
| 15 | +// 本文件底部提供的 stub 入口(ascCustom 槽 0:返回实体借用地址) | ||
| 16 | +extern "C" int32_t HcommCcuGetChannelEntity(ChannelHandle channel, uint64_t* channelEntityPtr); | ||
| 17 | + | ||
| 15 | namespace asc { | 18 | namespace asc { |
| 16 | namespace { | 19 | namespace { |
| 17 | 20 | ||
| 18 | -HcommCcuChannelPod channelPodStub{}; | 21 | +HcommCcuChannelEntity channelEntityStub{}; |
| 19 | -int32_t queryResultStub = HCCL_SUCCESS; | 22 | +HcommResult queryResultStub = HCCL_SUCCESS; |
| 20 | -bool channelPodStubConfigured = false; | 23 | +bool channelEntityStubConfigured = false; |
| 21 | - | ||
| 22 | -int32_t HcommCcuChannelQueryStubFn(ChannelHandle, HcommCcuChannelPod* channelPod) | ||
| 23 | -{ | ||
| 24 | - if (channelPod == nullptr || !channelPodStubConfigured) { | ||
| 25 | - return HCCL_E_PTR; | ||
| 26 | - } | ||
| 27 | - if (queryResultStub != HCCL_SUCCESS) { | ||
| 28 | - return queryResultStub; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - *channelPod = channelPodStub; | ||
| 32 | - return HCCL_SUCCESS; | ||
| 33 | -} | ||
| 34 | 24 | ||
| 35 | } // namespace | 25 | } // namespace |
| 36 | 26 | ||
| 37 | -void SetHcommCcuChannelQueryStub(const HcommCcuChannelPod& channelPod) | 27 | +void SetHcommCcuChannelGetEntityStub(const HcommCcuChannelEntity& channelEntity) |
| 38 | { | 28 | { |
| 39 | - channelPodStub = channelPod; | 29 | + channelEntityStub = channelEntity; |
| 40 | queryResultStub = HCCL_SUCCESS; | 30 | queryResultStub = HCCL_SUCCESS; |
| 41 | - channelPodStubConfigured = true; | 31 | + channelEntityStubConfigured = true; |
| 42 | 32 | ||
| 43 | - HcommCcuControlOpsPod controlOps{}; | 33 | + // 仅注入本 stub 关心的槽 0(getChannelEntity) |
| 44 | - controlOps.header.version = HCOMM_CCU_CONTROL_ABI_VERSION; | 34 | + uint64_t ops[HCOMM_CCU_ASC_CUSTOM_SLOT_COUNT]{}; |
| 45 | - controlOps.header.magicWord = HCOMM_CCU_CONTROL_OPS_MAGIC_WORD; | 35 | + ops[HCOMM_CCU_ASC_CUSTOM_CHANNEL_ENTITY] = reinterpret_cast<uint64_t>(HcommCcuGetChannelEntity); |
| 46 | - controlOps.header.size = sizeof(HcommCcuControlOpsPod); | 36 | + asc::set_current_ccu_control_ops(ops); |
| 47 | - controlOps.channelQuery = &HcommCcuChannelQueryStubFn; | ||
| 48 | - asc::set_current_ccu_control_ops(controlOps); | ||
| 49 | } | 37 | } |
| 50 | 38 | ||
| 51 | -void SetHcommCcuChannelQueryStubResult(int32_t result) { queryResultStub = result; } | 39 | +void SetHcommCcuChannelGetEntityStubResult(HcommResult result) { queryResultStub = result; } |
| 52 | 40 | ||
| 53 | -void ResetHcommCcuChannelQueryStub() | 41 | +void ResetHcommCcuChannelGetEntityStub() |
| 54 | { | 42 | { |
| 55 | - channelPodStub = {}; | 43 | + channelEntityStub = {}; |
| 56 | queryResultStub = HCCL_SUCCESS; | 44 | queryResultStub = HCCL_SUCCESS; |
| 57 | - channelPodStubConfigured = false; | 45 | + channelEntityStubConfigured = false; |
| 58 | asc::set_current_ccu_control_ops({}); | 46 | asc::set_current_ccu_control_ops({}); |
| 59 | } | 47 | } |
| 60 | 48 | ||
| 61 | } // namespace asc | 49 | } // namespace asc |
| 50 | + | ||
| 51 | +namespace asc { | ||
| 52 | +namespace { | ||
| 53 | +HcommCcuChannelEntity channelEntityStorage{}; // stub 的"实体"存储:借出该地址 | ||
| 54 | +} | ||
| 55 | +} // namespace asc | ||
| 56 | + | ||
| 57 | +// 借用地址指向预置快照 | ||
| 58 | +int32_t HcommCcuGetChannelEntity(ChannelHandle, uint64_t* channelEntityPtr) | ||
| 59 | +{ | ||
| 60 | + if (channelEntityPtr == nullptr || !asc::channelEntityStubConfigured) { | ||
| 61 | + return static_cast<int32_t>(HCCL_E_PTR); | ||
| 62 | + } | ||
| 63 | + if (asc::queryResultStub != HCCL_SUCCESS) { | ||
| 64 | + return static_cast<int32_t>(asc::queryResultStub); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + asc::channelEntityStorage = asc::channelEntityStub; | ||
| 68 | + *channelEntityPtr = reinterpret_cast<uint64_t>(&asc::channelEntityStorage); | ||
| 69 | + return static_cast<int32_t>(HCCL_SUCCESS); | ||
| 70 | +} | ||
| @@ -12,13 +12,14 @@ | |||
| 12 | #define ASCCOMM_CCU_CHANNEL_GET_STUB_H | 12 | #define ASCCOMM_CCU_CHANNEL_GET_STUB_H |
| 13 | 13 | ||
| 14 | #include "hcomm/hcomm_types.h" | 14 | #include "hcomm/hcomm_types.h" |
| 15 | -#include "hcomm/hcomm_ccu_channel.h" | 15 | +#include "hcomm/hcomm_ccu_resource.h" |
| 16 | 16 | ||
| 17 | namespace asc { | 17 | namespace asc { |
| 18 | 18 | ||
| 19 | -void SetHcommCcuChannelQueryStub(const HcommCcuChannelPod& channelPod); | 19 | +// ascCustom 槽 0(getChannelEntity)的 stub:预置快照 + 可注入的失败返回 |
| 20 | -void SetHcommCcuChannelQueryStubResult(int32_t result); | 20 | +void SetHcommCcuChannelGetEntityStub(const HcommCcuChannelEntity& channelEntity); |
| 21 | -void ResetHcommCcuChannelQueryStub(); | 21 | +void SetHcommCcuChannelGetEntityStubResult(HcommResult result); |
| 22 | +void ResetHcommCcuChannelGetEntityStub(); | ||
| 22 | } // namespace asc | 23 | } // namespace asc |
| 23 | 24 | ||
| 24 | #endif | 25 | #endif |
| @@ -14,8 +14,8 @@ namespace asc { | |||
| 14 | 14 | ||
| 15 | ccu_kernel::~ccu_kernel() = default; | 15 | ccu_kernel::~ccu_kernel() = default; |
| 16 | 16 | ||
| 17 | -void ccu_kernel::append(std::shared_ptr<asc::ccu_rep::ccu_rep_base> rep) { asc::ccu_rep::append_to_context(this, rep); } | 17 | +void ccu_kernel::append(std::shared_ptr<ccu_rep::ccu_rep_base> rep) { ccu_rep_context::append(rep); } |
| 18 | 18 | ||
| 19 | -asc::ccu_rep::variable ccu_kernel::create_variable() { return asc::ccu_rep::variable(this); } | 19 | +ccu_rep::variable ccu_kernel::create_variable() { return ccu_rep::variable(this); } |
| 20 | 20 | ||
| 21 | } // namespace asc | 21 | } // namespace asc |
| @@ -14,9 +14,9 @@ | |||
| 14 | namespace asc { | 14 | namespace asc { |
| 15 | namespace ccu_rep { | 15 | namespace ccu_rep { |
| 16 | 16 | ||
| 17 | -void append_to_context(ccu_rep_context* context, std::shared_ptr<ccu_rep_base> rep) {} | 17 | +void append_to_context(ccu_rep_context* context_, std::shared_ptr<ccu_rep_base> rep) {} |
| 18 | 18 | ||
| 19 | -variable create_variable(ccu_rep_context* context) { return variable(context); } | 19 | +variable create_variable(ccu_rep_context* context_) { return variable(context_); } |
| 20 | 20 | ||
| 21 | } // namespace ccu_rep | 21 | } // namespace ccu_rep |
| 22 | } // namespace asc | 22 | } // namespace asc |
| @@ -10,6 +10,8 @@ | |||
| 10 | 10 | ||
| 11 | #include "hcomm_adapter_rts.h" | 11 | #include "hcomm_adapter_rts.h" |
| 12 | 12 | ||
| 13 | +#include "acl/acl_rt.h" | ||
| 14 | + | ||
| 13 | namespace asc { | 15 | namespace asc { |
| 14 | 16 | ||
| 15 | HcclResult RtsUbDevQueryInfo(const rtUbDevQueryCmd cmd, rtMemUbTokenInfo& devInfo) | 17 | HcclResult RtsUbDevQueryInfo(const rtUbDevQueryCmd cmd, rtMemUbTokenInfo& devInfo) |
| @@ -31,3 +33,13 @@ extern "C" int rtUbDevQueryInfo(int cmd, void* devInfo) | |||
| 31 | } | 33 | } |
| 32 | return 0; | 34 | return 0; |
| 33 | } | 35 | } |
| 36 | + | ||
| 37 | +// 桩:ccu_device_context.cc 经 runtime 取当前线程设备逻辑 id,UT 环境无真实 runtime,固定成功并返回设备 0 | ||
| 38 | +extern "C" aclError aclrtGetDevice(int32_t* deviceId) | ||
| 39 | +{ | ||
| 40 | + if (deviceId == nullptr) { | ||
| 41 | + return 1; // 非 0 即失败,与 ACL_SUCCESS 语义一致 | ||
| 42 | + } | ||
| 43 | + *deviceId = 0; | ||
| 44 | + return ACL_SUCCESS; | ||
| 45 | +} | ||


pkg_inc的目录,放包间不对外的结构