LCOV - code coverage report
Current view: top level - aicpu_cust_schedule/core - aicpusd_drv_manager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.9 % 28 26
Test Date: 2026-07-28 10:54:05 Functions: 100.0 % 11 11

            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 CORE_AICPUSD_DRV_MANAGER_H
      12              : #define CORE_AICPUSD_DRV_MANAGER_H
      13              : #include <string>
      14              : #include <vector>
      15              : #include <sys/types.h>
      16              : #include "ascend_hal.h"
      17              : #include "feature_ctrl.h"
      18              : 
      19              : namespace AicpuSchedule {
      20              :     class AicpuDrvManager {
      21              :     public:
      22              :         static AicpuDrvManager &GetInstance();
      23              : 
      24              :         int32_t GetNormalAicpuInfo(const uint32_t deviceId);
      25              : 
      26              :         /**
      27              :         * @ingroup AicpuDrvManager
      28              :         * @brief it is used to init.
      29              :         * @param [in] deviceId : device id.
      30              :         * @param [in] hostPid : host pid
      31              :         * @param [in] vfId : vf id
      32              :         * @param [in] hasThread : has thread flag.
      33              :         * @return AICPU_SCHEDULE_OK: success, other: error code
      34              :         */
      35              :         int32_t InitDrvMgr(const uint32_t deviceId, const pid_t hostPid,
      36              :                            const uint32_t vfId, const bool hasThread);
      37              : 
      38              :         /**
      39              :         * @ingroup AicpuDrvManager
      40              :         * @brief it is used to init driver sched module.
      41              :         * @param [in] grpId : the group id.
      42              :         * @return AICPU_SCHEDULE_OK: success, other: error code
      43              :         */
      44              :         int32_t InitDrvSchedModule(const uint32_t grpId);
      45              : 
      46           63 :         uint32_t GetDeviceId() const
      47              :         {
      48           63 :             return deviceId_;
      49              :         }
      50              : 
      51            9 :         uint32_t GetUniqueVfId() const
      52              :         {
      53            9 :             return uniqueVfId_;
      54              :         }
      55              : 
      56           22 :         pid_t GetHostPid() const
      57              :         {
      58           22 :             if (isInit_) {
      59           19 :                 return hostPid_;
      60              :             }
      61            3 :             return drvDeviceGetBareTgid();
      62              :         }
      63              : 
      64            5 :         uint32_t GetGroupId() const
      65              :         {
      66            5 :             return groupId_;
      67              :         }
      68              : 
      69           15 :         uint32_t GetVfId() const
      70              :         {
      71           15 :             return vfId_;
      72              :         }
      73              : 
      74              :         bool HasThread() const
      75              :         {
      76              :             return hasThread_;
      77              :         }
      78              : 
      79              :         uint32_t GetAicpuNum() const;
      80              : 
      81            6 :         uint32_t GetAicpuPhysIndex(const uint32_t aicpuLogIndex) const
      82              :         {
      83            6 :             if (FeatureCtrl::IsAosCore()) {
      84              :                 // connot overflow
      85            0 :                 return ((aicpuBaseId_ + aicpuNum_) * deviceId_) + aicpuBaseId_ + aicpuLogIndex;
      86              :             } else {
      87            6 :                 return (coreNumPerDev_ * deviceId_) + aicpuIdVec_[aicpuLogIndex];
      88              :             }
      89              :         }
      90              : 
      91            2 :         uint32_t GetAicpuPhysIndexInVfMode(const uint32_t aicpuLogIndex, const uint32_t deviceId) const
      92              :         {
      93            2 :             if (FeatureCtrl::IsVfModeDie1(deviceId)) {
      94            0 :                 return coreNumPerDev_ + aicpuIdVec_[static_cast<size_t>(aicpuLogIndex)];
      95              :             }
      96            2 :             return aicpuIdVec_[static_cast<size_t>(aicpuLogIndex)];
      97              :         }
      98              : 
      99              :         void GetDcpuRange(uint32_t &dcpuBase, uint32_t &dcpuNum) const
     100              :         {
     101              :             dcpuBase = dcpuBase_;
     102              :             dcpuNum = dcpuNum_;
     103              :         }
     104              : 
     105              :         int32_t CheckBindHostPid() const;
     106              : 
     107              :         int32_t GetCcpuInfo(const uint32_t deviceId);
     108              : 
     109           16 :         std::vector<uint32_t> GetCcpuList()
     110              :         {
     111           16 :             return ccpuIdVec_;
     112              :         }
     113              : 
     114           10 :         bool GetSafeVerifyFlag() const
     115              :         {
     116           10 :             return needSafeVerify_;
     117              :         }
     118              :     private:
     119            3 :         AicpuDrvManager() : deviceId_(0U), coreNumPerDev_(0U), hostPid_(0), vfId_(0U), groupId_(0U), hasThread_(false),
     120            6 :                             isInit_(false), aicpuNum_(0U), aicpuBaseId_(0U), aicpuIdVec_({}), dcpuBase_(0U),
     121            3 :                             dcpuNum_(0U), uniqueVfId_(0U), needSafeVerify_(true) {}
     122              : 
     123            3 :         ~AicpuDrvManager() = default;
     124              : 
     125              :         AicpuDrvManager(const AicpuDrvManager &) = delete;
     126              : 
     127              :         AicpuDrvManager &operator=(const AicpuDrvManager &) = delete;
     128              : 
     129              :         void InitSocType(const uint32_t deviceId);
     130              : 
     131              :         void SetSafeVerifyFlag(const uint32_t deviceId);
     132              : 
     133              :         // the id of the chip.
     134              :         uint32_t deviceId_;
     135              : 
     136              :         // core num of device
     137              :         uint32_t coreNumPerDev_;
     138              : 
     139              :         // the pid of host process
     140              :         pid_t hostPid_;
     141              : 
     142              :         // vf id
     143              :         uint32_t vfId_;
     144              : 
     145              :         // the id is used to group in process.
     146              :         uint32_t groupId_;
     147              : 
     148              :         // it is used to mark which is in call mode or multi-thread mode.
     149              :         bool hasThread_;
     150              : 
     151              :         // init function called or not, lhisi is will be false
     152              :         bool isInit_;
     153              : 
     154              :         // aicpu core num
     155              :         uint32_t aicpuNum_;
     156              : 
     157              :         // aicpu base index
     158              :         uint32_t aicpuBaseId_;
     159              : 
     160              :         // aicpu index
     161              :         std::vector<uint32_t> aicpuIdVec_;
     162              : 
     163              :         // dcpu base index
     164              :         uint32_t dcpuBase_;
     165              : 
     166              :         // dcpu number
     167              :         uint32_t dcpuNum_;
     168              : 
     169              :         // calc by deviceId and vfId for vfId uniqueization
     170              :         uint32_t uniqueVfId_;
     171              : 
     172              :         std::vector<uint32_t> ccpuIdVec_;
     173              : 
     174              :         bool needSafeVerify_;
     175              :     };
     176              : }
     177              : #endif // CORE_AICPUSD_DRV_MANAGER_H
        

Generated by: LCOV version 2.0-1