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-18 17:47:01 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              : 
      11              : #ifndef AICPU_LAUNCH_MANAGER_H
      12              : #define AICPU_LAUNCH_MANAGER_H
      13              : 
      14              : #include "hccl_common.h"
      15              : #include "stream_pub.h"
      16              : #include "aicpu_operator_pub.h"
      17              : #include "thread.h"
      18              : #include "hccl/hccl_res.h"
      19              : #include "hccl_independent_common.h"
      20              : #include "local_notify.h"
      21              : #include "aicpu_init_param.h"
      22              : 
      23              : constexpr uint32_t THREAD_UNIQUE_ID_MAX_SIZE = 6000;
      24              : constexpr uint32_t NOTIFY_UNIQUE_ID_MAX_SIZE = THREAD_UNIQUE_ID_MAX_SIZE * hccl::HCCL_THREAD_NOTIFY_MAX_NUM;
      25              : constexpr uint32_t NOTIFY_DEVICE_ID_MAX_SIZE = 21 * hccl::HCCL_THREAD_NOTIFY_MAX_NUM;
      26              : constexpr uint32_t NAME_SIZE = 64;
      27              : constexpr uint32_t SIGNAL_DEV_STREAM_MAX_NUM = 200;
      28              : struct DevAicpuThreadConfig {
      29              :     // 如要新增配置类字段,在此处添加
      30              : };
      31              : 
      32              : struct ThreadMgrAicpuParam {
      33              :     u32 threadNum;
      34              :     char hcomId[HCOMID_MAX_SIZE];
      35              :     char threadParam[SIGNAL_DEV_STREAM_MAX_NUM][THREAD_UNIQUE_ID_MAX_SIZE]; // 含序列化后thread信息,约40KB
      36              :     void* deviceHandle;
      37              :     s32 deviceLogicId{-1};                   // 基础通信使用
      38              :     u32 deviceType{0};                       // 基础通信使用
      39              :     DevAicpuThreadConfig threadConfig;       // 收编thread配置类变量
      40              :     CommEngine engine{COMM_ENGINE_RESERVED}; // 通信引擎类型,由Host侧Thread对象携带
      41              : };
      42              : 
      43              : struct DevAicpuNotifyConfig {
      44              :     // 如要新增配置类字段,在此处添加
      45              : };
      46              : 
      47              : struct NotifyMgrAicpuParam {
      48              :     u32 notifyNum;
      49              :     char hcomId[HCOMID_MAX_SIZE];
      50              :     char notifyParam[NOTIFY_UNIQUE_ID_MAX_SIZE]; // 含序列化后notify信息
      51              :     void* deviceHandle;
      52              :     bool freeFlag;
      53              :     DevAicpuNotifyConfig notifyConfig; // 收编notify配置类变量
      54              : };
      55              : 
      56              : namespace hccl {
      57              : 
      58              : struct ApiParamDef {
      59              :     uint64_t commContext{};
      60              :     char kernelName[NAME_SIZE] = {};
      61              :     char soName[NAME_SIZE] = {};
      62              :     char opName[NAME_SIZE] = {};
      63              : 
      64              :     ApiParamDef(const char* kName, const char* sName, const char* oName)
      65              :     {
      66              :         strncpy_s(kernelName, NAME_SIZE, kName, NAME_SIZE - 1);
      67              :         strncpy_s(soName, NAME_SIZE, sName, NAME_SIZE - 1);
      68              :         strncpy_s(opName, NAME_SIZE, oName, NAME_SIZE - 1);
      69              :     }
      70              : };
      71              : 
      72              : struct ThreadKernelLaunchConfig {
      73              :     std::string commId;       // 通信ID
      74              :     aclrtBinHandle binHandle; // 自定义二进制句柄
      75              :     std::string kernelName;   // 核函数名称
      76              :     bool needDeviceInfo;      // 是否需要设备信息
      77              :     uint32_t timeoutSec;      // 超时时间(秒)
      78              :     bool needProfiling;       // 是否需要性能分析
      79              :     bool isSupplementNotify;  // 是否是补充notify kernel
      80              : 
      81            1 :     ThreadKernelLaunchConfig(
      82              :         const std::string& cid, aclrtBinHandle binHandle, const std::string& name, bool needDev, uint32_t timeout,
      83              :         bool profiling, bool isSupplementNotify)
      84            1 :         : commId(cid),
      85            1 :           binHandle(binHandle),
      86            1 :           kernelName(name),
      87            1 :           needDeviceInfo(needDev),
      88            1 :           timeoutSec(timeout),
      89            1 :           needProfiling(profiling),
      90            1 :           isSupplementNotify(isSupplementNotify)
      91            1 :     {}
      92              : };
      93              : 
      94              : class AicpuLaunchMgr {
      95              : public:
      96              :     AicpuLaunchMgr() = default;
      97              :     ~AicpuLaunchMgr() = default;
      98              :     template <typename OpParam, typename ApiParam>
      99              :     static HcclResult KernelLaunch(OpParam& opParam, ApiParam& apiParam, rtStream_t aicpuInitStream);
     100              :     static HcclResult ThreadKernelLaunchImpl(
     101              :         std::vector<std::shared_ptr<Thread>>& newThreads, std::unique_ptr<ThreadHandle[]>& aicpuHandle,
     102              :         const ThreadKernelLaunchConfig& config);
     103              :     static HcclResult ThreadKernelLaunchForComm(
     104              :         std::vector<std::shared_ptr<Thread>>& newThreads, const std::string& commId,
     105              :         std::unique_ptr<ThreadHandle[]>& aicpuHandle, aclrtBinHandle binHandle);
     106              :     static HcclResult ThreadKernelLaunchForBase(
     107              :         std::vector<std::shared_ptr<Thread>>& newThreads, std::unique_ptr<ThreadHandle[]>& aicpuHandle,
     108              :         aclrtBinHandle binHandle);
     109              :     static HcclResult SupplementNotifyKernelLaunch(
     110              :         std::vector<std::shared_ptr<Thread>>& newThreads, const std::string& commId,
     111              :         std::unique_ptr<ThreadHandle[]>& aicpuHandle, aclrtBinHandle binHandle);
     112              :     static HcclResult
     113              :     ThreadKernelLaunchDestroy(ThreadHandle* threadHandles, uint32_t listNum, aclrtBinHandle binHandle);
     114              :     static HcclResult NotifyKernelLaunchAlloc(
     115              :         std::vector<std::unique_ptr<LocalNotify>>& newNotifys, const std::string& commId,
     116              :         std::unique_ptr<NotifyHandle[]>& hostHandle, aclrtBinHandle binCustomHandle);
     117              :     static HcclResult NotifyKernelLaunchFree(
     118              :         std::vector<NotifyHandle>& aicpuNotifys, uint32_t notifyNum, const std::string& commId,
     119              :         aclrtBinHandle binCustomHandle);
     120              :     static HcclResult KernelLaunchAicpuCustom(
     121              :         uint64_t context, std::string kernelName, rtStream_t aicpuInitStream, aclrtBinHandle binCustomHandle);
     122              : 
     123              : private:
     124              :     HcclResult AiCpuStreamAllocAndGet(rtStream_t& aiCpuStream);
     125              :     static HcclResult PrepareAicpuNotifyParam(
     126              :         NotifyMgrAicpuParam& opParam, const std::string& commId, size_t notifyNum, bool freeFlag, void* deviceHandle);
     127              :     static HcclResult LaunchNotifyKernel(NotifyMgrAicpuParam& opParam, aclrtBinHandle binCustomHandle);
     128              :     Stream opStream_;
     129              : };
     130              : } // namespace hccl
     131              : #endif
        

Generated by: LCOV version 2.0-1