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 % 4 4
Test Date: 2026-08-04 10:52:23 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(const std::string &cid, aclrtBinHandle binHandle,
      80              :                              const std::string &name, bool needDev, uint32_t timeout, bool profiling,
      81              :                             bool isSupplementNotify)
      82            1 :         : commId(cid), binHandle(binHandle), kernelName(name),
      83            1 :           needDeviceInfo(needDev), timeoutSec(timeout), needProfiling(profiling),
      84            1 :           isSupplementNotify(isSupplementNotify) {}
      85              : };
      86              : 
      87              : class AicpuLaunchMgr {
      88              : public:
      89              :     AicpuLaunchMgr() = default;
      90              :     ~AicpuLaunchMgr() = default;
      91              :     template <typename OpParam, typename ApiParam>
      92              :     static HcclResult KernelLaunch(OpParam &opParam, ApiParam &apiParam, rtStream_t aicpuInitStream);
      93              :     static HcclResult ThreadKernelLaunchImpl(std::vector<std::shared_ptr<Thread>> &newThreads,
      94              :         std::unique_ptr<ThreadHandle[]> &aicpuHandle, const ThreadKernelLaunchConfig &config);
      95              :     static HcclResult ThreadKernelLaunchForComm(std::vector<std::shared_ptr<Thread>> &newThreads,
      96              :         const std::string &commId, std::unique_ptr<ThreadHandle[]> &aicpuHandle, aclrtBinHandle binHandle);
      97              :     static HcclResult ThreadKernelLaunchForBase(std::vector<std::shared_ptr<Thread>> &newThreads,
      98              :         std::unique_ptr<ThreadHandle[]> &aicpuHandle, aclrtBinHandle binHandle);
      99              :     static HcclResult SupplementNotifyKernelLaunch(std::vector<std::shared_ptr<Thread>> &newThreads,
     100              :         const std::string &commId, std::unique_ptr<ThreadHandle[]> &aicpuHandle, aclrtBinHandle binHandle);
     101              :     static HcclResult ThreadKernelLaunchDestroy(ThreadHandle *threadHandles, uint32_t listNum, 
     102              :         aclrtBinHandle binHandle);
     103              :     static HcclResult NotifyKernelLaunchAlloc(std::vector<std::unique_ptr<LocalNotify>> &newNotifys,
     104              :         const std::string &commId, std::unique_ptr<NotifyHandle[]> &hostHandle, aclrtBinHandle binCustomHandle);
     105              :     static HcclResult NotifyKernelLaunchFree(std::vector<NotifyHandle> &aicpuNotifys, uint32_t notifyNum,
     106              :         const std::string &commId, aclrtBinHandle binCustomHandle);
     107              :     static HcclResult KernelLaunchAicpuCustom(uint64_t context, std::string kernelName, rtStream_t aicpuInitStream,
     108              :         aclrtBinHandle binCustomHandle);
     109              : private:
     110              :     HcclResult AiCpuStreamAllocAndGet(rtStream_t &aiCpuStream);
     111              :     static HcclResult PrepareAicpuNotifyParam(NotifyMgrAicpuParam &opParam, const std::string &commId,
     112              :         size_t notifyNum, bool freeFlag, void *deviceHandle);
     113              :     static HcclResult LaunchNotifyKernel(NotifyMgrAicpuParam &opParam, aclrtBinHandle binCustomHandle);
     114              :     Stream opStream_;
     115              : };
     116              : }
     117              : #endif
        

Generated by: LCOV version 2.0-1