行业资讯
📅 2026/7/15 15:39:04
CANN/hcomm Profiling模块分析
Profiling Module Code Analysis【免费下载链接】hcommHCOMMHuawei Communication是HCCL的通信基础库提供通信域以及通信资源的管理能力。项目地址: https://gitcode.com/cann/hcommFeature DescriptionThe Profiling module is responsible for collecting and reporting performance data of HCCL collective communication tasks. It is a core component of the HCCL DFX (Diagnostics and Observability) system. The module is deployed on both the Host side and the Device side, providing unified profiling capabilities.Core capabilities:Report communication tasks: Report execution information of collective communication tasks (AllReduce, Broadcast, and so on) to the Profiling framework.Report operator information: Report key metrics such as start and end times and operator types for communication operators (Host side only).Report MC2 communication information: Report Stream, Rank, and other metadata of the MC2 communication domain (Host side only).Report Kernel: Report AICPU or AIV Kernel execution timeline information. The Device side reports kernel start and end task events.Update Profiling status: Update Profiling statistics based on task queue consumption progress.Manage Profiling switches: Respond to subscription and unsubscription commands from the Profiling framework to control data collection start and stop.External InterfacesHeader FileInterfaceSideDescriptionhccl_diag.hHcclDfxRegOpInfoByCommIdHost DeviceRegisters operator information with the communication domain, recordsbeginTime, and stores it inMirrorTaskManager.hccl_diag.hHcclProfilingReportOpHostReports operator execution events: firstReportAllTasks, thenReportOp.hccl_diag.hHcclReportAicpuKernelHostReports AICPU Kernel execution events, records taskId and streamId, and adds task information.hccl_diag.hHcclReportAivKernelHostReports AIV Kernel execution events, records taskId and streamId, and adds task information.hccl_diag.hHcommGetProfilingSysCycleTimeHostObtains the Profiling system cycle time.hcomm_diag.hHcommProfilingReportDeviceOpDeviceReports Device operator execution events: firstReportAllTasks, then reports OP information throughProfilingHandlerLite.hcomm_diag.hHcommProfilingReportKernelStartTaskDeviceReports kernel start task events, reports HEAD typeFlagTaskInfothroughProfilingHandlerLite.hcomm_diag.hHcommProfilingReportKernelEndTaskDeviceReports kernel end task events, reports TAIL typeFlagTaskInfothroughProfilingHandlerLite.Directory Descriptionprofiling/ ├── CMakeLists.txt # Top-level build, includes aicpu and host subdirectories ├── host/ │ ├── CMakeLists.txt # Host-side build, compiles hcclCommProfiling.cc │ ├── hcclCommProfiling.h # Host-side Profiling facade class definition │ └── hcclCommProfiling.cc # Host-side Profiling facade class implementation └── aicpu/ ├── CMakeLists.txt # AICPU-side build, compiles hcclCommProfilingLite.cc ├── hcclCommProfilingLite.h # AICPU-side Profiling facade class definition ├── hcclCommProfilingLite.cc # AICPU-side Profiling facade class implementation ├── aicpu_ts_urma_dfx_kernel.h # [Deprecated] URMA DFX Kernel └── aicpu_ts_urma_dfx_kernel.cc # [Deprecated] URMA DFX KernelFile RelationshipsFileFunctionDependencieshost/hcclCommProfiling.hHost-side Profiling facade class declarationDepends onMirrorTaskManager,ProfilingReporterhost/hcclCommProfiling.ccHost-side Profiling facade class implementationDepends onprofiling_reporter.h,profiling_handler.h,dlprof_function.haicpu/hcclCommProfilingLite.hAICPU-side Profiling facade class declarationDepends onMirrorTaskManagerLite,ProfilingReporterLiteaicpu/hcclCommProfilingLite.ccAICPU-side Profiling facade class implementationDepends onprofiling_reporter_lite.h,mirror_task_manager_lite.hProfiling File InteractionFlow DescriptionHost Profiling FlowRegister Operator Information (HcclDfxRegOpInfoByCommId)Report Operator (HcclProfilingReportOp)Report AICPU Kernel (HcclReportAicpuKernel)Report AIV Kernel (HcclReportAivKernel)Report MC2 Communication InformationManage Host-Side Profiling SwitchDevice Profiling FlowRegister Operator Information (HcclDfxRegOpInfoByCommId)Report Device Operator (HcommProfilingReportDeviceOp)Report Kernel Start Task (HcommProfilingReportKernelStartTask)Report Kernel End Task (HcommProfilingReportKernelEndTask)Manage Device-Side Profiling SwitchReport Level and Type Constants SummaryConstant NameValueDescriptionMSPROF_REPORT_ACL_LEVEL20000ACL level, used for Host API reportingMSPROF_REPORT_NODE_LEVEL10000Node level, used for Node BasicInfo, HCCL OP, and MC2 CommInfo reportingMSPROF_REPORT_HCCL_NODE_LEVEL5500HCCL Node level, used for Task details and CCU information reportingMSPROF_REPORT_ACL_HOST_HCCL_BASE_TYPE0x070000ACL Host HCCL base typeMSPROF_REPORT_NODE_LAUNCH_TYPE5Node Launch type, used forReportNodeApiMSPROF_REPORT_NODE_BASIC_INFO_TYPE0Node basic information type, used forReportNodeBasicInfoMSPROF_REPORT_NODE_HCCL_OP_INFO_TYPE10Node HCCL OP information typeMSPROF_REPORT_NODE_MC2_COMMINFO_TYPE12Node MC2 communication resource information typeMSPROF_REPORT_HCCL_MASTER_TYPE0x010001HCCL main stream typeMSPROF_REPORT_HCCL_SLAVE_TYPE0x010002HCCL slave stream typeMSPROF_REPORT_CCU_TASK_INFO14CCU Task information typeMSPROF_REPORT_CCU_WAIT_SIGNAL_INFO15CCU Wait Signal information typeMSPROF_REPORT_CCU_GROUP_INFO16CCU Group information typeSwitch Control and Report Content MappingSwitchCorresponding MaskControlled Report ContentenableHostApi_PROF_ACL_API_MASK 0x1Host API timestamp reporting (ReportAclApi,ReportNodeApi,ReportHcclOpApi,ReportHcclOpInfo,ReportMc2AdditionInfo)enableHcclL0_PROF_TASK_TIME_MASK 0x800HCCL operator granularity tracing (ReportHcclOpApi)enableHcclNode_PROF_TASK_TIME_L1_MASK 0x2Task granularity tracing (ReportHcclTaskApi)enableHcclL1_PROF_TASK_TIME_L1_MASK 0x2Task details reporting (CallAddtionInfo,ReportNodeBasicInfo)enableHcclL2_PROF_TASK_TIME_L2_MASK 0x2000CCU details reporting (ReportCcuInfo)Interface Description (Class Diagram)Interface DescriptionHcclCommProfiling (Host Side)InterfaceTypeParametersReturn ValueDescriptionHcclCommProfilingPublic[in] u32 deviceId,[in] MirrorTaskManager* mirrorTaskManager-Constructor, saves the task manager pointer, creates aProfilingReporterinstance (associated withProfilingHandler::GetInstance()).ReportAllTasksPublic[in] bool cachedReq falsevoidReports all communication tasks. WhencachedReqtrue, indicates cache request mode. Delegates toProfilingReporter::ReportAllTasksto traverse the task queue and report throughProfilingHandler.ReportOpPublic[in] uint64_t beginTime,[in] bool cachedReq,[in] bool opbasedvoidReports operator information. Delegates toProfilingReporter::ReportOp, which ultimately calls the profapi componentdlMsprofReportApithroughProfilingHandler::ReportHostApi.ReportMc2CommInfoPublic[in] const Mc2CommInfo mc2CommInfovoidReports MC2 communication domain information. Splits theMc2CommInfofields and callsProfilingReporter::CallReportMc2CommInfo, which ultimately reports throughdlMsprofReportAdditionalInfo.UpdateProfStatPublic-voidUpdates Profiling statistics. Delegates toProfilingReporter::UpdateProfStatto update the switch status.GetMirrorTaskManagerPublic-MirrorTaskManager*Returns the internally heldMirrorTaskManagerpointer.ReportKernelPublic[in] uint64_t beginTime,[in] const string commTag,[in] const string kernelName,[in] uint32_t threadId,[in] bool cachedReqHcclResultReports CCU Kernel information. Calls the profapi componentdlMsprofSysCycleTimeto get endTime anddlMsprofStr2Idto get cmdItemId, then callsProfilingHandlerto reportReportNodeApiandReportNodeBasicInfo. TheEXCEPTION_CATCHmacro catches exceptions and returnsHCCL_E_PTRon failure.HcclCommProfilingLite (Device Side)InterfaceTypeParametersReturn ValueDescriptionHcclCommProfilingLitePublic[in] DevId deviceId,[in] MirrorTaskManagerLite* mirrorTaskManagerLite-Constructor, saves the task manager pointer, creates aProfilingReporterLiteinstance (isIndoptrue, associated withProfilingHandlerLite::GetInstance()).ReportAllTasksPublic-voidReports all communication tasks. Delegates toProfilingReporterLite::ReportAllTasks, which ultimately calls the profapi componentMsprofReportAdditionalInfothrough a weak symbol.UpdateProfStatPublic-voidUpdates Profiling statistics. Delegates toProfilingReporterLite::UpdateProfStatto update the switch status.GetMirrorTaskManagerLitePublic-MirrorTaskManagerLite*Returns the internally heldMirrorTaskManagerLitepointer.Usage LimitationsSupported ScenariosScenarioHost SideDevice SideDescriptionRegister operator informationSupportedSupportedRegistered throughHcclDfxRegOpInfoByCommId.Report operatorSupportedSupportedHost reports throughHcclProfilingReportOp; Device reports throughHcommProfilingReportDeviceOp.Report KernelSupportedSupportedHost supports AICPU and AIV Kernel reporting; Device supports kernel start and end task reporting.Report MC2 communication infoSupportedNot supportedOnly the Host side supportsReportMc2CommInfo.Update Profiling statusSupportedSupportedBoth sides support this.Multi-device task managementSupportedNot supportedThe Host-sideMirrorTaskManagersupports multi-device queue mapping.Report CCU informationSupportedNot supportedOnly the Host side supports CCU Task, WaitSignal, and Group information reporting.Get system cycle timeSupportedNot supportedOnly the Host side supportsHcommGetProfilingSysCycleTime.Constraint SpecificationsMaximum device count: The Host-sideProfilingReporterstatic arrayallLastPoses_has a size ofREPORTER_MAX_MODULE_DEVICE_NUM 65, supporting profiling position records for up to 65 devices.ProfilingHandler singleton pattern: Both Host-side and Device-sideProfilingHandlerandProfilingHandlerLiteare singletons, globally unique. Copying and assignment are prohibited.DlProfFunction dynamic loading: The Host side dynamically loadslibprofapi.sothroughDlProfFunctionusingdlopen. If the SDK is unavailable, it falls back to stub functions (printing a WARNING log and skipping).Device-side weak symbol linking: The Device side declares profapi component functions through__attribute__((weak))(such asMsprofReportAdditionalInfoandAdprofReportAdditionalInfo). At runtime, the selection priority is:MsprofReportBatchAdditionalInfoAdprofReportAdditionalInfoMsprofReportAdditionalInfo.Null pointer protection: All reporting interfaces check for non-null pointers before calling the Reporter to avoid null pointer dereferences.EXCEPTION_CATCH macro:ReportKerneluses theEXCEPTION_CATCHmacro to catch exceptions duringProfilingHandlerreporting, returningHCCL_E_PTRon failure.MC2 Stream group reporting:ReportMc2CommInfogroups every 8 streamIds into a group and reports them throughProfilingDeviceCommResInfo. ThecommStreamIdsarray size is fixed at 8.Device-side device type restriction:HcommProfilingReportDeviceOp,HcommProfilingReportKernelStartTask, andHcommProfilingReportKernelEndTaskonly execute onDEV_TYPE_950devices. For other device types, they directly return success.Known Limitationsaicpu_ts_urma_dfx_kernelis deprecated: The Device-sideaicpu_ts_urma_dfx_kernel.hand.ccfiles are deprecated and no longer maintained, but the build entry is still retained inCMakeLists.txt.Mc2CommInfohas no validation: TheReportMc2CommInfointerface does not validate the length of thestreamsIdvector inmc2CommInfo. This is handled by the underlyingCallReportMc2CommInfo.Thread safety: The Host-sideProfilingHandleruses multiple mutexes (cacheTaskInfosMutex_,cachedTaskApiInfoMutex_,cacheHcclOpInfoMutex_,cacheHcclAdditionInfoMutex_) to protect cached data. The Device-sideProfilingHandlerLitedoes not use locks and relies on a single-threaded execution environment.Device-side switch query mode: Unlike the Host side, which receives switch status passively through callbacks, the Device-sideProfilingHandlerLitemust actively callUpdateProfSwitch()to query the switch status from the profapi component.Non-V2 communication domain handling: OnDEV_TYPE_910Bdevices,HcclProfilingReportOpdirectly returns success and skips reporting for non-CommunicatorV2communication domains. For other device types,HCCL_E_NOT_SUPPORTis returned for non-V2 domains.【免费下载链接】hcommHCOMMHuawei Communication是HCCL的通信基础库提供通信域以及通信资源的管理能力。项目地址: https://gitcode.com/cann/hcomm创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考