LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/communicator - ccu_super_fast_load.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.9 % 33 29
Test Date: 2026-08-04 10:52:23 Functions: 88.9 % 9 8

            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 HCCL_CCU_SUPER_FAST_LOAD_H
      11              : #define HCCL_CCU_SUPER_FAST_LOAD_H
      12              : #include <cstdlib>
      13              : #include <array>
      14              : #include <vector>
      15              : #include <cstring>
      16              : #include <utility>
      17              : #include <cstddef>
      18              : 
      19              : #include "securec.h"
      20              : #include "string_util.h"
      21              : 
      22              : #include "types.h"
      23              : #include "op_type.h"
      24              : #include "orion_adapter_rts.h"
      25              : #include "ccu/ccu_task_param.h"
      26              : #include "task_param.h"
      27              : #include "ccu_ins.h"
      28              : #include "acl/acl_rt.h"
      29              : 
      30              : namespace Hccl {
      31              : using CcuParamsMappingKeyType = std::uint32_t;
      32              : constexpr std::size_t CCU_SFL_PARAM_KEY_LEN = 3;
      33              : using CcuSFLMappingKey = std::array<CcuParamsMappingKeyType, CCU_SFL_PARAM_KEY_LEN>;
      34              : struct CachedCCUParams {
      35              : public:
      36              :     rtCcuTaskInfo_t *ccuParams{nullptr};
      37              :     std::vector<std::size_t> count;
      38              :     std::vector<TaskParam> taskParams;
      39              :     u64 execId{0};
      40              :     std::size_t totalCounts{0};
      41              :     CcuInstType insType{};
      42              :     bool isSlave{false};
      43              : 
      44            0 :     CachedCCUParams() = default;
      45              :     explicit CachedCCUParams(std::vector<std::vector<Hccl::CcuTaskParam>> &&ccuInstruction,
      46              :                              std::vector<std::vector<CcuProfilingInfo>> &&profilingInfo, std::size_t execId,
      47              :                              CcuInstType insType, bool isSlave, void* comm);
      48              : 
      49              :     CachedCCUParams(const CachedCCUParams &) = delete;
      50              :     CachedCCUParams &operator=(const CachedCCUParams &) = delete;
      51              : 
      52              :     CachedCCUParams(CachedCCUParams &&other) noexcept;
      53              :     CachedCCUParams &operator=(CachedCCUParams &&other) noexcept;
      54              : 
      55              :     ~CachedCCUParams();
      56              : 
      57              : private:
      58           13 :     inline void *aligned_malloc(size_t align, size_t size) const
      59              :     {
      60           13 :         void *p = nullptr;
      61           13 :         if (posix_memalign(&p, align, size) != 0) {
      62            0 :             throw std::bad_alloc();
      63              :         }
      64           13 :         return p;
      65              :     }
      66              : 
      67           13 :     inline void aligned_free(void *ptr) const
      68              :     {
      69           13 :         if (ptr) {
      70           13 :             std::free(ptr);
      71           13 :             ptr = nullptr;
      72              :         }
      73           13 :     }
      74              : 
      75           13 :     inline bool is_power_of_2(std::size_t x) const
      76              :     {
      77           13 :         return static_cast<bool>(x) && !static_cast<bool>((x & (x - 1)));
      78              :     }
      79           13 :     inline std::size_t round_up_to(std::size_t size, std::size_t alignment) const
      80              :     {
      81           13 :         return alignment != 0 ? (size + alignment - 1) / alignment * alignment : size;
      82              :     }
      83           13 :     inline void *alloc_aligned_raw(std::size_t alignment, std::size_t size) const
      84              :     {
      85           13 :         if (alignment == 0) {
      86            0 :             alignment = alignof(std::max_align_t);
      87              :         }
      88           13 :         if (!is_power_of_2(alignment)) {
      89            0 :             return nullptr;
      90              :         };
      91           13 :         return aligned_malloc(alignment, round_up_to(size, alignment));
      92              :     }
      93              : 
      94              :     rtCcuTaskInfo_t *alloc_and_memcpy_aligned(const std::vector<std::vector<rtCcuTaskInfo_t>> &vecs,
      95              :                                               std::size_t alignment);
      96              : };
      97              : 
      98            9 : inline void SuperFastLoad(rtCcuTaskInfo_t *params, aclrtStream const streamPtr, int counts)
      99              : {
     100           27 :     for (int i = 0; i < counts; ++i) {
     101           18 :         HrtCcuLaunch(params[i], streamPtr);
     102              :     }
     103            9 : }
     104              : }  // namespace Hccl
     105              : 
     106              : namespace std {
     107              : constexpr std::size_t NUMBER_SIX = 6;
     108              : constexpr std::size_t NUMBER_TWO = 2;
     109              : struct ArrayHasher {
     110           28 :     std::size_t operator()(
     111              :         const std::array<Hccl::CcuParamsMappingKeyType, Hccl::CCU_SFL_PARAM_KEY_LEN> &ccuParams) const noexcept
     112              :     {
     113           28 :         std::size_t hashVal = 0;
     114          112 :         for (auto ccuParam : ccuParams) {
     115           84 :             hashVal ^=
     116           84 :                 std::hash<std::uint32_t>{}(ccuParam) + 0x9e3779b9 + (hashVal << NUMBER_SIX) + (hashVal >> NUMBER_TWO);
     117              :         }
     118           28 :         return hashVal;
     119              :     }
     120              : };
     121              : 
     122              : template <>
     123              : struct hash<Hccl::OpType> {
     124              :     std::size_t operator()(const Hccl::OpType &type) const noexcept
     125              :     {
     126              :         return static_cast<std::size_t>(type);
     127              :     }
     128              : };
     129              : template <>
     130              : struct hash<const Hccl::OpType> {
     131           53 :     std::size_t operator()(const Hccl::OpType &type) const noexcept
     132              :     {
     133           53 :         return static_cast<std::size_t>(type);
     134              :     }
     135              : };
     136              : };      // namespace std
     137              : #endif  // HCCL_CCU_SUPER_FAST_LOAD_H
        

Generated by: LCOV version 2.0-1