LCOV - code coverage report
Current view: top level - aicpu_schedule/core - aicpusd_interface_process.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-08-31 10:07:09 Functions: - 0 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              : #ifndef CORE_AICPUSD_INTERFACE_PROCESS_PROC_H
      12              : #define CORE_AICPUSD_INTERFACE_PROCESS_PROC_H
      13              : 
      14              : #include <atomic>
      15              : #include <functional>
      16              : #include <map>
      17              : #include <mutex>
      18              : #include <thread>
      19              : #include <vector>
      20              : #include "aicpusd_status.h"
      21              : #include "aicpusd_common.h"
      22              : #include "aicpusd_interface.h"
      23              : #include "ascend_hal.h"
      24              : #include "event_custom_api_struct.h"
      25              : #include "ts_api.h"
      26              : #include "aicpu_context.h"
      27              : 
      28              : namespace AicpuSchedule {
      29              : class AicpuScheduleInterface {
      30              : public:
      31              :     __attribute__((visibility("default"))) static AicpuScheduleInterface& GetInstance();
      32              : 
      33              :     /**
      34              :      * @ingroup AicpuScheduleInterface
      35              :      * @brief it use to load the task and stream info for helper.
      36              :      * @param [in] ptr : the address of the task and stream info
      37              :      * @return AICPU_SCHEDULE_OK: success
      38              :      */
      39              :     int32_t LoadModelWithQueue(const void* const ptr) const;
      40              : 
      41              :     /**
      42              :      * @ingroup AicpuScheduleInterface
      43              :      * @brief it use to load the task and stream info for helper.
      44              :      * @param [in] ptr : the address of the task and stream info
      45              :      * @return AICPU_SCHEDULE_OK: success
      46              :      */
      47              :     int32_t LoadModelWithEvent(const void* const ptr) const;
      48              : 
      49              :     /**
      50              :      * @ingroup AicpuScheduleInterface
      51              :      * @brief it use to load the task and stream info.
      52              :      * @param [in] ptr : the address of the task and stream info
      53              :      * @return AICPU_SCHEDULE_OK: success
      54              :      */
      55              :     int32_t LoadProcess(const void* const ptr, const ModelCfgInfo* const cfg = nullptr) const;
      56              : 
      57              :     /**
      58              :      * @ingroup AicpuScheduleInterface
      59              :      * @param [in] modelId
      60              :      * @brief it use to destroy one model.
      61              :      */
      62              :     int32_t Destroy(const uint32_t modelId) const;
      63              : 
      64              :     /**
      65              :      * @ingroup AicpuScheduleInterface
      66              :      * @brief it use to destroy all model.
      67              :      * @return AICPU_SCHEDULE_OK:success, other failed.
      68              :      */
      69              :     int32_t Destroy() const;
      70              : 
      71              :     /**
      72              :      * @ingroup AicpuScheduleInterface
      73              :      * @brief it use to initialize aicpu schedule.
      74              :      * @param [in] deviceId
      75              :      * @param [in] hostPid: the process id of host
      76              :      * @param [in] pidSign: the signature of pid ,it is used in drv.
      77              :      * @param [in] profilingMode: the mode of profiling
      78              :      * @param [in] vfId: vf id
      79              :      * @param [in] isOnline: true-process mode; false-thread mode
      80              :      * @param [in] hostProcName: host process name
      81              :      * @return AICPU_SCHEDULE_OK: success, other: error code
      82              :      */
      83              :     __attribute__((visibility("default"))) int32_t InitAICPUScheduler(
      84              :         const std::vector<uint32_t>& deviceVec, const pid_t hostPid, const std::string& pidSign,
      85           72 :         const uint32_t profilingMode, const uint32_t vfId, const bool isOnline, const std::string& hostProcName = "");
      86              : 
      87              :     /**
      88              :      * @ingroup AicpuScheduleInterface
      89              :      * @brief it use to stop AICPU scheduler.
      90              :      * @param [in] deviceId
      91              :      * @param [in] hostPid :the process id of host
      92              :      * @return AICPU_SCHEDULE_OK: success, other: error code
      93              :      */
      94              :     __attribute__((visibility("default"))) int32_t StopAICPUScheduler(
      95              :         const std::vector<uint32_t>& deviceVec, const pid_t hostPid);
      96              : 
      97              :     __attribute__((visibility("default"))) void SetBatchLoadMode(const uint32_t aicpuProcNum);
      98              : 
      99              :     int32_t StopAICPUSchedulerWithFlag(
     100              :         const std::vector<uint32_t>& deviceVec, const pid_t hostPid, bool waitThreadStop);
     101              : 
     102              :     /**
     103              :      * @ingroup AicpuScheduleInterface
     104              :      * @brief it use to get the errorcode for external module by the model status.
     105              :      * @return AICPU_SCHEDULE_SUCCESS: success, other: error code
     106              :      */
     107              :     ErrorCode GetErrorCode(const uint32_t modelId) const;
     108              : 
     109              :     /**
     110              :      * @ingroup AicpuScheduleInterface
     111              :      * @brief execute model async.
     112              :      * @param [in] modelId: model id.
     113              :      * @return AICPU_SCHEDULE_OK: success, other: error code
     114              :      */
     115              :     int32_t ExecuteModelAsync(const uint32_t modelId) const;
     116              : 
     117              :     /**
     118              :      * @ingroup IsInitialized
     119              :      * @brief Get initFlag
     120              :      * @return true or false
     121              :      */
     122              :     bool IsInitialized(const uint32_t deviceId);
     123              : 
     124              :     int32_t Stop(const uint32_t modelId) const;
     125              : 
     126              :     int32_t Restart(const uint32_t modelId) const;
     127              : 
     128              :     int32_t ClearInput(const uint32_t modelId) const;
     129              : 
     130              :     int32_t CheckKernelSupported(const std::string& kernelName) const;
     131              : 
     132              :     void UpdateOrInsertStartFlag(const uint32_t deviceId, const bool flag);
     133              : 
     134              :     void SetAicpuCustSdProcId(const int32_t aicpuCustSdPid);
     135              : 
     136              :     int32_t GetAicpuCustSdProcId() const;
     137              : 
     138              :     void SetAicpuSdProcId(const pid_t aicpuSdPid);
     139              : 
     140              :     int32_t ProcessException(const DataFlowExceptionNotify* const exceptionInfo) const;
     141              : 
     142              :     bool NeedLoadKernelSo() const;
     143              : 
     144              : private:
     145              :     AicpuScheduleInterface();
     146              : 
     147              :     ~AicpuScheduleInterface();
     148              : 
     149              :     AicpuScheduleInterface(AicpuScheduleInterface&) = delete;
     150              : 
     151              :     AicpuScheduleInterface& operator=(AicpuScheduleInterface&) = delete;
     152              : 
     153              :     int32_t BuildAndSetContext(const uint32_t deviceId, const pid_t hostPid, const uint32_t vfId);
     154              : 
     155              :     /**
     156              :      * @ingroup AicpuScheduleInterface
     157              :      * @brief Get current call mode
     158              :      * @return AICPU_SCHEDULE_OK: success, other: error code
     159              :      */
     160              :     int32_t GetCurrentRunMode(const bool isOnline);
     161              : 
     162              :     /**
     163              :      * @ingroup AicpuScheduleInterface
     164              :      * @brief it use to bind host pid.
     165              :      * @param [in] pidSign: the signature of pid ,it is used in drv.
     166              :      * @param [in] vfId: vf id
     167              :      * @return AICPU_SCHEDULE_OK: success, other: error code
     168              :      */
     169              :     int32_t BindHostPid(const std::string& pidSign, const uint32_t vfId) const;
     170              : 
     171              :     /**
     172              :      * @ingroup AicpuScheduleInterface
     173              :      * @brief it use to send message to tscpu.
     174              :      * @param [in] deviceId
     175              :      */
     176              :     void SendMsgToTsCpu(const uint32_t deviceId) const;
     177              : 
     178              :     int32_t DettachDeviceInDestroy(const std::vector<uint32_t>& deviceVec) const;
     179              : 
     180              : private:
     181              :     // the Mode decide if profiling open
     182              :     ProfilingMode profilingMode_;
     183              : 
     184              :     // it is used to mark which is in call mode or multi-thread mode.
     185              :     std::atomic<bool> noThreadFlag_;
     186              : 
     187              :     // it is used in updating model status.
     188              :     std::mutex mutexForInit_;
     189              : 
     190              :     // it is used to record whether is init.
     191              :     bool initFlag_;
     192              : 
     193              :     uint32_t eventBitMap_;
     194              : 
     195              :     // aicpu run mode
     196              :     aicpu::AicpuRunMode runMode_;
     197              : 
     198              :     std::map<uint32_t, bool> aicpusdInitFlagMap_;
     199              : 
     200              :     std::atomic<int32_t> aicpuCustSdPid_;
     201              : 
     202              :     bool isNeedBatchLoadSo_;
     203              : };
     204              : } // namespace AicpuSchedule
     205              : #endif
        

Generated by: LCOV version 2.0-1