LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/alg_template - nonuniform_hierarchical_ring_v1_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 60 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 18 0

            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 "nonuniform_hierarchical_ring_v1_base.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            0 : RingInfo::RingInfo(u32 rankSize) : rankSize_(rankSize)
      16              : {
      17            0 :     sqrtRankSize_ = static_cast<u32>(std::sqrt(rankSize));
      18              : 
      19            0 :     u32 left = sqrtRankSize_;
      20            0 :     u32 right = sqrtRankSize_;
      21              : 
      22            0 :     while (left > 0 && right < rankSize) {
      23            0 :         if (left * right < rankSize) {
      24            0 :             right++;
      25            0 :         } else if (left * right > rankSize) {
      26            0 :             left--;
      27              :         } else {
      28            0 :             break;
      29              :         }
      30              :     }
      31              : 
      32            0 :     if ((right - left) < threshold) {
      33            0 :         colSize_ = left;
      34            0 :         rowSize_ = right;
      35            0 :         extraRowSize_ = 0;
      36            0 :         extraColSize_ = 0;
      37            0 :         rankOffset_ = colSize_ * rowSize_;
      38              :     } else {
      39              :         // 保证除了最后一列之外的其他列size相等
      40            0 :         u32 extraSize = rankSize - sqrtRankSize_ * sqrtRankSize_;
      41            0 :         extraRowSize_ = (extraSize >= sqrtRankSize_) ? sqrtRankSize_ : 0;
      42            0 :         extraColSize_ = extraSize - extraRowSize_;
      43              : 
      44            0 :         colSize_ = sqrtRankSize_ + ((extraRowSize_ == 0) ? 0 : 1);
      45            0 :         rowSize_ = sqrtRankSize_;
      46              : 
      47              :         // 当rank < rankOffset_时,rank所处的行size为sqrtRankSize_ + 1
      48              :         // 当rank >= rankOffset_时,rank所处的行size为sqrtRankSize_
      49            0 :         if (extraColSize_ == 0) {
      50            0 :             rankOffset_ = colSize_ * rowSize_;
      51              :         } else {
      52            0 :             rankOffset_ = (sqrtRankSize_ + 1) * extraColSize_;
      53              :         }
      54              :     }
      55            0 : }
      56              : 
      57            0 : RingInfo::~RingInfo() {}
      58              : 
      59            0 : u32 RingInfo::GetRankSize() const { return rankSize_; }
      60              : 
      61            0 : u32 RingInfo::GetRankOffset() const { return rankOffset_; }
      62              : 
      63            0 : u32 RingInfo::GetSqrtRankSize() const { return sqrtRankSize_; }
      64              : 
      65            0 : u32 RingInfo::GetRowSize() const { return rowSize_; }
      66              : 
      67            0 : u32 RingInfo::GetColSize() const { return colSize_; }
      68              : 
      69            0 : u32 RingInfo::GetVIndex(u32 rank) const
      70              : {
      71            0 :     if (rank < rankOffset_) {
      72            0 :         return rank / (rowSize_ + ((extraColSize_ == 0) ? 0 : 1));
      73              :     } else {
      74            0 :         return extraColSize_ + (rank - rankOffset_) / sqrtRankSize_;
      75              :     }
      76              : }
      77              : 
      78            0 : u32 RingInfo::GetHIndex(u32 rank) const
      79              : {
      80            0 :     if (rank < rankOffset_) {
      81            0 :         return rank % (rowSize_ + ((extraColSize_ == 0) ? 0 : 1));
      82              :     } else {
      83            0 :         return (rank - rankOffset_) % sqrtRankSize_;
      84              :     }
      85              : }
      86              : 
      87            0 : u32 RingInfo::GetVSizeByHIndex(u32 hIndex) const
      88              : {
      89            0 :     if (rankOffset_ == rankSize_) {
      90            0 :         return colSize_;
      91            0 :     } else if (hIndex == sqrtRankSize_) {
      92            0 :         return extraColSize_;
      93              :     } else {
      94            0 :         return sqrtRankSize_ + static_cast<u32>(hIndex < extraRowSize_);
      95              :     }
      96              : }
      97              : 
      98            0 : u32 RingInfo::GetVSizeByRank(u32 rank) const { return GetVSizeByHIndex(GetHIndex(rank)); }
      99              : 
     100            0 : u32 RingInfo::GetHSizeByVIndex(u32 vIndex) const
     101              : {
     102            0 :     if (rankOffset_ == rankSize_) {
     103            0 :         return rowSize_;
     104              :     } else {
     105            0 :         return sqrtRankSize_ + static_cast<u32>(vIndex < extraColSize_);
     106              :     }
     107              : }
     108              : 
     109            0 : u32 RingInfo::GetHSizeByRank(u32 rank) const { return GetHSizeByVIndex(GetVIndex(rank)); }
     110              : 
     111            0 : u32 RingInfo::GetRank(u32 vIndex, u32 hIndex) const
     112              : {
     113            0 :     if (rankOffset_ == rankSize_) {
     114            0 :         return vIndex * rowSize_ + hIndex;
     115            0 :     } else if (vIndex < extraColSize_) {
     116            0 :         return (sqrtRankSize_ + 1) * vIndex + hIndex;
     117              :     } else {
     118            0 :         return rankOffset_ + sqrtRankSize_ * (vIndex - extraColSize_) + hIndex;
     119              :     }
     120              : }
     121              : 
     122            0 : NHRV1Base::NHRV1Base(const HcclDispatcher dispatcher) : AlgTemplateBase(dispatcher) {}
     123              : 
     124            0 : NHRV1Base::~NHRV1Base() {}
     125              : 
     126            0 : RingInfo NHRV1Base::GetRingInfo(u32 rankSize) { return RingInfo(rankSize); }
     127              : 
     128              : } // namespace hccl
        

Generated by: LCOV version 2.0-1