LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/communicator - ccu_super_fast_load.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.1 % 105 81
Test Date: 2026-07-28 12:11:00 Functions: 66.7 % 6 4

            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              : #include "ccu_super_fast_load.h"
      12              : 
      13              : #include "exception_util.h"
      14              : #include "internal_exception.h"
      15              : #include "communicator_impl.h"
      16              : #include "ccu_jetty_mgr.h"
      17              : #include "coll_service_device_mode.h"
      18              : 
      19              : namespace Hccl {
      20              : 
      21           16 : static void SFLReportCcuProfilingInfoInitPart(uint64_t execId, std::vector<CcuProfilingInfo> && streamProfilingInfo,
      22              :                                    const CommunicatorImpl &comm, TaskParam &taskParam)
      23              : {
      24           16 :     if (streamProfilingInfo.empty()) {
      25           39 :         HCCL_INFO("There is no ccu profiling info.");
      26           13 :         return;
      27              :     }
      28            3 :     taskParam.taskPara.Ccu.dieId     = streamProfilingInfo[0].dieId;
      29            3 :     taskParam.taskPara.Ccu.missionId = streamProfilingInfo[0].missionId;
      30            3 :     taskParam.taskPara.Ccu.execMissionId = streamProfilingInfo[0].missionId;
      31            3 :     taskParam.taskPara.Ccu.instrId   = streamProfilingInfo[0].instrId;
      32            3 :     taskParam.taskPara.Ccu.executeId = execId;
      33              :  
      34            6 :     CcuJettyMgr *ccuJettyMgr = dynamic_cast<CollServiceDeviceMode *>(comm.GetCollService())
      35            6 :         ->GetCcuInsPreprocessor()->GetCcuComm()->GetCcuJettyMgr();
      36            9 :     for (auto &profInfo : streamProfilingInfo) {
      37            6 :         for (int idx = 0; idx < CCU_MAX_CHANNEL_NUM; idx++) {
      38            6 :             if (profInfo.channelId[idx] == INVALID_VALUE_CHANNELID) {
      39            6 :                 break;
      40              :             }
      41            0 :             profInfo.remoteRankId[idx] =
      42            0 :                 ccuJettyMgr->GetRemoteRankIdByChannelId(profInfo.dieId, profInfo.channelId[idx]);
      43              :         }
      44              :     }
      45            3 :     taskParam.ccuDetailInfo = std::make_shared<std::vector<CcuProfilingInfo>>(std::move(streamProfilingInfo));
      46              : }
      47              : 
      48           13 : CachedCCUParams::CachedCCUParams(std::vector<std::vector<Hccl::CcuTaskParam>> &&ccuInstruction,
      49              :                              std::vector<std::vector<CcuProfilingInfo>> &&profilingInfo, std::size_t execId,
      50           13 :                              CcuInstType insType, bool isSlave, void* comm)
      51           13 :     : execId(execId), insType(insType), isSlave(isSlave)
      52              : {
      53           13 :     std::vector<std::vector<rtCcuTaskInfo_t>> ccuTaskInstruction{};
      54           13 :     auto& commImpl = *(static_cast<CommunicatorImpl *>(comm));
      55           29 :     for (auto &vec : ccuInstruction) {
      56           16 :         std::vector<rtCcuTaskInfo_t> ccuTaskVec{};
      57           36 :         for (auto &ccuTask : vec) {
      58           20 :             rtCcuTaskInfo_t taskInfo{};
      59           20 :             taskInfo.dieId       = ccuTask.dieId;
      60           20 :             taskInfo.missionId   = ccuTask.missionId;
      61           20 :             taskInfo.instStartId = ccuTask.instStartId;
      62           20 :             taskInfo.instCnt     = ccuTask.instCnt;
      63           20 :             taskInfo.key         = ccuTask.key;
      64           20 :             taskInfo.argSize     = ccuTask.argSize;
      65           20 :             taskInfo.timeout     = commImpl.GetNotifyTimeoutCfg().GetNotifyTimeout();
      66           60 :             std::copy(std::begin(ccuTask.args), std::end(ccuTask.args), std::begin(taskInfo.args));
      67           20 :             ccuTaskVec.push_back(taskInfo);
      68              :         }
      69           16 :         ccuTaskInstruction.push_back(ccuTaskVec);
      70           16 :     }
      71           13 :     constexpr std::size_t alignment = alignof(std::max_align_t);
      72           13 :     ccuParams =
      73           13 :         alloc_and_memcpy_aligned(std::forward<std::vector<std::vector<rtCcuTaskInfo_t>>>(ccuTaskInstruction), alignment);
      74           13 :     taskParams.reserve(ccuInstruction.size());
      75           29 :     for (std::size_t i = 0; i < ccuInstruction.size(); i++) {
      76           16 :         TaskParam taskParam = {};
      77           16 :         taskParam.taskType = TaskParamType::TASK_CCU;
      78           16 :         SFLReportCcuProfilingInfoInitPart(execId, std::forward<std::vector<CcuProfilingInfo>>(profilingInfo[i]),
      79              :                                           commImpl, taskParam);
      80           16 :         taskParams.emplace_back(std::move(taskParam));
      81           16 :     }
      82           39 :     HCCL_RUN_INFO("Save CcuInstType: %d", insType);
      83           13 : }
      84              : 
      85            0 : CachedCCUParams::CachedCCUParams(CachedCCUParams &&other) noexcept : ccuParams(std::exchange(other.ccuParams, nullptr)),
      86            0 :     count(std::move(other.count)), taskParams(std::move(other.taskParams)), execId(other.execId), totalCounts(other.totalCounts),
      87            0 :      insType(other.insType), isSlave(other.isSlave)
      88              : {
      89            0 : }
      90              : 
      91            0 : CachedCCUParams& CachedCCUParams::operator=(CachedCCUParams &&other) noexcept
      92              : {
      93            0 :     if (this != &other) {
      94            0 :         aligned_free(ccuParams);
      95            0 :         ccuParams  = std::exchange(other.ccuParams, nullptr);
      96            0 :         execId   = other.execId;
      97            0 :         count    = std::move(other.count);
      98            0 :         totalCounts = other.totalCounts;
      99            0 :         isSlave   = other.isSlave;
     100            0 :         taskParams = std::move(other.taskParams);
     101            0 :         insType = other.insType;
     102              :     }
     103            0 :     return *this;
     104              : }
     105              : 
     106           13 : CachedCCUParams::~CachedCCUParams()
     107              : {
     108           13 :     aligned_free(ccuParams);
     109           13 : }
     110              : 
     111           13 : rtCcuTaskInfo_t *CachedCCUParams::alloc_and_memcpy_aligned(const std::vector<std::vector<rtCcuTaskInfo_t>> &vecs,
     112              :                                                         std::size_t alignment)
     113              : {
     114           13 :     if (alignment < alignof(CcuTaskParam)) {
     115            0 :         THROW<InternalException>(StringFormat("[CachedCCUParams] alignment must be larger than type alignment."));
     116              :     }
     117           13 :     count.resize(vecs.size());
     118           13 :     std::size_t countIndex = 0;
     119           13 :     count[countIndex++] = vecs[0].size();
     120           29 :     for (const auto &vec : vecs) {
     121           16 :         totalCounts += vec.size();
     122           48 :         HCCL_INFO("CachedCCUParams: vec.size[%llu]", static_cast<std::uint64_t>(vec.size()));
     123              :     }
     124           13 :     if (totalCounts == 0) {
     125            0 :         THROW<InternalException>(StringFormat("[CachedCCUParams] total count is zero."));
     126              :     }
     127           39 :     HCCL_INFO("CachedCCUParams: totalCounts[%llu]", static_cast<std::uint64_t>(totalCounts));
     128           13 :     std::size_t bytes = totalCounts * sizeof(rtCcuTaskInfo_t);
     129           13 :     void *raw = alloc_aligned_raw(alignment, bytes);
     130           13 :     if (!raw) {
     131            0 :         THROW<InternalException>(StringFormat("[CachedCCUParams] failed to allocate memory, size %zu.", bytes));
     132              :     }
     133           13 :     rtCcuTaskInfo_t *dst = static_cast<rtCcuTaskInfo_t *>(raw);
     134           13 :     rtCcuTaskInfo_t *cur = dst;
     135           13 :     if (!vecs[0].empty()) {
     136           13 :         auto ret = memcpy_s(cur, count[0] * sizeof(rtCcuTaskInfo_t), vecs[0].data(), count[0] * sizeof(rtCcuTaskInfo_t));
     137           13 :         if (ret != EOK) {
     138            0 :             aligned_free(dst);
     139            0 :             THROW<InternalException>(StringFormat("[CachedCCUParams] failed to memcpy, ret %d.", ret));
     140              :         }
     141           13 :         cur += count[0];
     142              :     }
     143           13 :     u32 reqStreamNum = vecs.size() - 1;
     144           16 :     for (std::size_t i = 1; i <= reqStreamNum; i++) {
     145            3 :         auto &vec = vecs[i];
     146            3 :         if (!vec.empty()) {
     147            3 :             auto ret = memcpy_s(cur, vec.size() * sizeof(rtCcuTaskInfo_t), vec.data(), vec.size() * sizeof(rtCcuTaskInfo_t));
     148            3 :             if (ret != EOK) {
     149            0 :                 aligned_free(dst);
     150            0 :                 THROW<InternalException>(StringFormat("[CachedCCUParams] failed to memcpy, ret %d.", ret));
     151              :             }
     152            3 :             count[countIndex++] = vec.size();
     153            3 :             cur += vec.size();
     154              :         }
     155              :     }
     156           29 :     for (std::size_t i = 0; i < count.size(); ++i) {
     157           48 :         HCCL_INFO("CachedCCUParams: count value[%llu]", static_cast<std::uint64_t>(count[i]));
     158              :     }
     159           13 :     return dst;
     160              : }
     161              : }  // namespace Hccl
        

Generated by: LCOV version 2.0-1