LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_kernel - ccu_kernel_mgr.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
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              : 
      11              : #ifndef HCOMM_CCU_KERNEL_MGR_H
      12              : #define HCOMM_CCU_KERNEL_MGR_H
      13              : 
      14              : #include <mutex>
      15              : #include <unordered_map>
      16              : 
      17              : #include "ccu_kernel.h"
      18              : #include "../ccu_instance/ccu_res_pack.h"
      19              : 
      20              : #include "ccu_dev_mgr_imp.h"
      21              : #include "../ccu_representation/reps/translator/ccu_rep_translator_v1.h"
      22              : 
      23              : #include "ccu_ins_generator_base.h"
      24              : 
      25              : namespace hcomm {
      26              : 
      27              : using namespace CcuRep;
      28              : 
      29              : class CcuKernelMgr {
      30              : public:
      31              :     static CcuKernelMgr &GetInstance(const s32 deviceLogicId);
      32              : 
      33              :     HcclResult Init();
      34              :     HcclResult Deinit();
      35              : 
      36              :     CcuResult Register(CcuResPack &resPack, uint32_t dieId, const char *kernelFuncName,
      37              :         const void *kernelFunc, const void **kernelArgs, const uint32_t argNum,
      38              :         CcuKernelHandle &kernelHandle);
      39              : 
      40              :     CcuResult GetKernelResourceRequest(uint32_t dieId, const char *kernelFuncName,
      41              :         const void *kernelFunc, const void **kernelArgs, uint32_t argNum,
      42              :         CcuResReq &resReq, uint32_t &instrCount);
      43              : 
      44              :     CcuResult Translate(const std::vector<CcuKernelHandle> &kernelHandles);
      45              : 
      46              :     CcuKernel *GetKernel(CcuKernelHandle kernelHandle);
      47              :     CcuResult UnRegister(CcuKernelHandle kernelHandle);
      48              : 
      49              :     CcuKernel *GetCurrentKernel();
      50              : 
      51              : private:
      52          198 :     explicit CcuKernelMgr() = default;
      53              :     ~CcuKernelMgr();
      54              : 
      55              :     CcuKernelMgr(const CcuKernelMgr &that) = delete;
      56              :     CcuKernelMgr &operator=(const CcuKernelMgr &that) = delete;
      57              : 
      58              : private:
      59              :     struct CcuTranslatResPack {
      60              :         std::vector<CcuResHandle> handles{};
      61              :     };
      62              : 
      63              : private:
      64              :     CcuResult BuildKernel(uint32_t dieId, const char *kernelFuncName,
      65              :         const void *kernelFunc, const void **kernelArgs, uint32_t argNum);
      66              :     CcuResult PrepareConstValueResources();
      67              :     CcuResult AllocRes(CcuResPack &resPack);
      68              : 
      69              :     HcclResult InstantiationTranslator(const uint16_t dieId);
      70              :     HcclResult TransRepSequenceToMicrocode(const std::vector<CcuKernel *> &kernels,
      71              :         bool isFuncBlock);
      72              :     HcclResult LoadInstruction(const CcuRep::CcuInstrInfo &instrInfo, const uint32_t dieId);
      73              : 
      74              :     HcclResult GetResPackTotalResRepository(const CcuTranslatResPack &resPack,
      75              :         CcuResRepository &totalRes) const;
      76              : 
      77              : private:
      78              :     bool initializedFlag_{false};
      79              :     int32_t devLogicId_{-1};
      80              :     std::mutex kernelMapMutex_{};
      81              :     std::mutex translateMutex_{};
      82              :     CcuKernelHandle kernelId_ = 0;
      83              :     std::unordered_map<CcuKernelHandle, std::unique_ptr<CcuKernel>> kernelMap_{};
      84              :     void *instructionLoadDevMem_{nullptr};
      85              : 
      86              :     std::unordered_map<uint16_t, std::unordered_map<uint16_t, std::shared_ptr<CcuRep::CcuRepTranslator>>> translators;
      87              :     std::unordered_map<uint16_t, std::unordered_map<uint16_t, std::shared_ptr<CcuRep::CcuRepReferenceManager>>> referenceMgrs;
      88              :     CcuTranslatResPack translatorResPack{};
      89              :     std::unique_ptr<CcuKernel> currKernel_{nullptr};
      90              :     std::shared_ptr<CcuInsGeneratorBase> insGenePtr;
      91              :     CcuVersion ccuVersion_{CcuVersion::CCU_INVALID};
      92              : };
      93              : }; // namespace hcomm
      94              : #endif // HCOMM_CCU_KERNEL_MGR_IMP_H
        

Generated by: LCOV version 2.0-1