LCOV - code coverage report
Current view: top level - acl/aclrt_c/common - acl_rt.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 52 52 100.0 %
Date: 2026-08-27 13:24:42 Functions: 7 7 100.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             : #include <string.h>
      11             : #include "log_inner.h"
      12             : #include "runtime/rt.h"
      13             : #include "ge_executor_rt.h"
      14             : #include "mmpa_api.h"
      15             : #include "ref_obj.h"
      16             : #include "acl/acl.h"
      17             : 
      18             : #ifdef __cplusplus
      19             : extern "C"{
      20             : #endif
      21             : 
      22             : static RefObj gInitRefCount;
      23             : 
      24          13 : static inline bool PathIsLegal(const char *cfg) {
      25          13 :   mmFileHandle *fd = mmOpenFile(cfg, FILE_READ);
      26          13 :   if (fd == NULL) {
      27          10 :     return false;
      28             :   }
      29           3 :   (void)mmSeekFile(fd, 0, MM_SEEK_FILE_END);
      30           3 :   bool isLegal = mmTellFile(fd) == 0 ? false : true;
      31           3 :   mmCloseFile(fd);
      32           3 :   return isLegal;
      33             : }
      34             : 
      35          15 : static void *InitHookFunc(RefObj *obj, const void *userData) {
      36          15 :   const rtError_t rtErr = rtInit();
      37          15 :   if (rtErr != RT_ERROR_NONE) {
      38           1 :     ACL_LOG_INNER_ERROR("rt init fail, ret = %d", rtErr);
      39           1 :     return NULL;
      40             :   }
      41          14 :   Status ret = GeInitialize();
      42          14 :   if (ret != (Status)SUCCESS) {
      43           1 :     ACL_LOG_INNER_ERROR("ge init fail, ret = %d", ret);
      44           1 :     (void)rtDeinit();
      45           1 :     return NULL;
      46             :   }
      47          13 :   const char *configPath = (const char *)userData;
      48          13 :   if (PathIsLegal(configPath)) {
      49           3 :     ret = GeDbgInit(configPath);
      50           3 :     if (ret != (Status)SUCCESS) {
      51           1 :       (void)GeFinalize();
      52           1 :       (void)rtDeinit();
      53           1 :       return NULL;
      54             :     }
      55             :   }
      56          12 :   return obj;
      57             : }
      58             : 
      59          16 : aclError aclInit(const char *configPath) {
      60          16 :   if (GetObjRefWithUserData(&gInitRefCount, configPath, InitHookFunc) == NULL) {
      61           3 :     ACL_LOG_ERROR("Add refCount err");
      62           3 :     return ACL_ERROR_INTERNAL_ERROR;
      63             :   }
      64          13 :   ACL_LOG_INFO("Increased refCount: %lu", (uint64_t)gInitRefCount.refCount);
      65          13 :   return ACL_SUCCESS;
      66             : }
      67             : 
      68          12 : static void DeinitHookFunc(RefObj *obj) {
      69             :   (void)obj;
      70          12 :   (void)GeDbgDeInit();
      71          12 :   (void)GeFinalize();
      72          12 :   (void)rtDeinit();
      73          12 : }
      74          13 : aclError aclFinalize() {
      75          13 :   ReleaseObjRef(&gInitRefCount, DeinitHookFunc);
      76          13 :   ACL_LOG_INFO("Decreased refCount: %lu", (uint64_t)gInitRefCount.refCount);
      77          13 :   return ACL_SUCCESS;
      78             : }
      79             : 
      80           2 : aclError aclrtGetVersion(int32_t *majorVersion, int32_t *minorVersion,
      81             :                          int32_t *patchVersion) {
      82           2 :   ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(majorVersion);
      83           1 :   ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(minorVersion);
      84           1 :   ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(patchVersion);
      85             :   // Acl version is (*majorVersion).(*minorVersion).(*patchVersion) 
      86           1 :   *majorVersion = ACL_MAJOR_VERSION;
      87           1 :   *minorVersion = ACL_MINOR_VERSION;
      88           1 :   *patchVersion = ACL_PATCH_VERSION;
      89           1 :   ACL_LOG_INFO("acl version is %d.%d.%d", *majorVersion, *minorVersion,
      90             :                *patchVersion);
      91             : 
      92           1 :   return ACL_SUCCESS;
      93             : }
      94             : 
      95           2 : const char *aclGetRecentErrMsg() {
      96           2 :   return GetErrorMessage();
      97             : }
      98             : 
      99             : #ifdef __cplusplus
     100             : }
     101             : #endif

Generated by: LCOV version 1.14