LCOV - code coverage report
Current view: top level - base_comm/resources/comm_engine_res/launch - aicpu_launch_manager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 9 9
Test Date: 2026-08-17 10:19:35 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : #ifndef AICPU_LAUNCH_MANAGER_H
      11              : #define AICPU_LAUNCH_MANAGER_H
      12              : 
      13              : #include "hccl_common.h"
      14              : #include "stream_pub.h"
      15              : #include "aicpu_operator_pub.h"
      16              : #include "thread.h"
      17              : #include "hccl/hccl_res.h"
      18              : #include "hccl_independent_common.h"
      19              : #include "local_notify.h"
      20              : #include "aicpu_init_param.h"
      21              : 
      22              : constexpr uint32_t THREAD_UNIQUE_ID_MAX_SIZE = 6000;
      23              : constexpr uint32_t NOTIFY_UNIQUE_ID_MAX_SIZE = THREAD_UNIQUE_ID_MAX_SIZE * hccl::HCCL_THREAD_NOTIFY_MAX_NUM;
      24              : constexpr uint32_t NOTIFY_DEVICE_ID_MAX_SIZE = 21 * hccl::HCCL_THREAD_NOTIFY_MAX_NUM;
      25              : constexpr uint32_t NAME_SIZE = 64;
      26              : constexpr uint32_t SIGNAL_DEV_STREAM_MAX_NUM = 200;
      27              : struct DevAicpuThreadConfig {
      28              :     // 如要新增配置类字段,在此处添加
      29              : };
      30              : 
      31              : struct ThreadMgrAicpuParam {
      32              :     u32 threadNum;
      33              :     char hcomId[HCOMID_MAX_SIZE];
      34              :     char threadParam[SIGNAL_DEV_STREAM_MAX_NUM][THREAD_UNIQUE_ID_MAX_SIZE]; // 含序列化后thread信息,约40KB
      35              :     void* deviceHandle;
      36              :     s32 deviceLogicId{-1};             // 基础通信使用
      37              :     u32 deviceType{0};                 // 基础通信使用
      38              :     DevAicpuThreadConfig threadConfig; // 收编thread配置类变量
      39              : };
      40              : 
      41              : struct DevAicpuNotifyConfig {
      42              :     // 如要新增配置类字段,在此处添加
      43              : };
      44              : 
      45              : struct NotifyMgrAicpuParam {
      46              :     u32 notifyNum;
      47              :     char hcomId[HCOMID_MAX_SIZE];
      48              :     char notifyParam[NOTIFY_UNIQUE_ID_MAX_SIZE]; // 含序列化后notify信息
      49              :     void* deviceHandle;
      50              :     bool freeFlag;
      51              :     DevAicpuNotifyConfig notifyConfig; // 收编notify配置类变量
      52              : };
      53              : 
      54              : namespace hccl {
      55              : 
      56              : struct ApiParamDef {
      57              :     uint64_t commContext{};
      58              :     char kernelName[NAME_SIZE] = {};
      59              :     char soName[NAME_SIZE] = {};
      60              :     char opName[NAME_SIZE] = {};
      61              : 
      62              :     ApiParamDef(const char* kName, const char* sName, const char* oName)
      63              :     {
      64              :         strncpy_s(kernelName, NAME_SIZE, kName, NAME_SIZE - 1);
      65              :         strncpy_s(soName, NAME_SIZE, sName, NAME_SIZE - 1);
      66              :         strncpy_s(opName, NAME_SIZE, oName, NAME_SIZE - 1);
      67              :     }
      68              : };
      69              : 
      70              : struct ThreadKernelLaunchConfig {
      71              :     std::string commId;       // 通信ID
      72              :     aclrtBinHandle binHandle; // 自定义二进制句柄
      73              :     std::string kernelName;   // 核函数名称
      74              :     bool needDeviceInfo;      // 是否需要设备信息
      75              :     uint32_t timeoutSec;      // 超时时间(秒)
      76              :     bool needProfiling;       // 是否需要性能分析
      77              :     bool isSupplementNotify;  // 是否是补充notify kernel
      78              : 
      79            1 :     ThreadKernelLaunchConfig(
      80              :         const std::string& cid, aclrtBinHandle binHandle, const std::string& name, bool needDev, uint32_t timeout,
      81              :         bool profiling, bool isSupplementNotify)
      82            1 :         : commId(cid),
      83            1 :           binHandle(binHandle),
      84            1 :           kernelName(name),
      85            1 :           needDeviceInfo(needDev),
      86            1 :           timeoutSec(timeout),
      87            1 :           needProfiling(profiling),
      88            1 :           isSupplementNotify(isSupplementNotify)
      89            1 :     {}
      90              : };
      91              : 
      92              : class AicpuLaunchMgr {
      93              : public:
      94              :     AicpuLaunchMgr() = default;
      95              :     ~AicpuLaunchMgr() = default;
      96              :     template <typename OpParam, typename ApiParam>
      97              :     static HcclResult KernelLaunch(OpParam& opParam, ApiParam& apiParam, rtStream_t aicpuInitStream);
      98              :     static HcclResult ThreadKernelLaunchImpl(
      99              :         std::vector<std::shared_ptr<Thread>>& newThreads, std::unique_ptr<ThreadHandle[]>& aicpuHandle,
     100              :         const ThreadKernelLaunchConfig& config);
     101              :     static HcclResult ThreadKernelLaunchForComm(
     102              :         std::vector<std::shared_ptr<Thread>>& newThreads, const std::string& commId,
     103              :         std::unique_ptr<ThreadHandle[]>& aicpuHandle, aclrtBinHandle binHandle);
     104              :     static HcclResult ThreadKernelLaunchForBase(
     105              :         std::vector<std::shared_ptr<Thread>>& newThreads, std::unique_ptr<ThreadHandle[]>& aicpuHandle,
     106              :         aclrtBinHandle binHandle);
     107              :     static HcclResult SupplementNotifyKernelLaunch(
     108              :         std::vector<std::shared_ptr<Thread>>& newThreads, const std::string& commId,
     109              :         std::unique_ptr<ThreadHandle[]>& aicpuHandle, aclrtBinHandle binHandle);
     110              :     static HcclResult
     111              :     ThreadKernelLaunchDestroy(ThreadHandle* threadHandles, uint32_t listNum, aclrtBinHandle binHandle);
     112              :     static HcclResult NotifyKernelLaunchAlloc(
     113              :         std::vector<std::unique_ptr<LocalNotify>>& newNotifys, const std::string& commId,
     114              :         std::unique_ptr<NotifyHandle[]>& hostHandle, aclrtBinHandle binCustomHandle);
     115              :     static HcclResult NotifyKernelLaunchFree(
     116              :         std::vector<NotifyHandle>& aicpuNotifys, uint32_t notifyNum, const std::string& commId,
     117              :         aclrtBinHandle binCustomHandle);
     118              :     static HcclResult KernelLaunchAicpuCustom(
     119              :         uint64_t context, std::string kernelName, rtStream_t aicpuInitStream, aclrtBinHandle binCustomHandle);
     120              : 
     121              : private:
     122              :     HcclResult AiCpuStreamAllocAndGet(rtStream_t& aiCpuStream);
     123              :     static HcclResult PrepareAicpuNotifyParam(
     124              :         NotifyMgrAicpuParam& opParam, const std::string& commId, size_t notifyNum, bool freeFlag, void* deviceHandle);
     125              :     static HcclResult LaunchNotifyKernel(NotifyMgrAicpuParam& opParam, aclrtBinHandle binCustomHandle);
     126              :     Stream opStream_;
     127              : };
     128              : } // namespace hccl
     129              : #endif
        

Generated by: LCOV version 2.0-1