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

Generated by: LCOV version 2.0-1