LCOV - code coverage report
Current view: top level - acl/aclrt_c/runtime - device.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.2 % 54 46
Test Date: 2026-08-13 17:07:01 Functions: 100.0 % 5 5

            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 "acl/acl_rt.h"
      11              : #include "log_inner.h"
      12              : #include "securec.h"
      13              : #include "runtime/rt.h"
      14              : #include "ge_executor_rt.h"
      15              : 
      16              : #ifdef __cplusplus
      17              : extern "C" {
      18              : #endif
      19              : 
      20              : #define ACL_ENUM_DESC_LEN 32U
      21              : 
      22            1 : static const char* GetRunModeDesc(const aclrtRunMode runMode, char* const unknownDesc, const size_t unknownDescLen)
      23              : {
      24            1 :     switch (runMode) {
      25            0 :         case ACL_DEVICE:
      26            0 :             return "DEVICE(0)";
      27            1 :         case ACL_HOST:
      28            1 :             return "HOST(1)";
      29            0 :         default:
      30            0 :             if ((unknownDesc == NULL) || (unknownDescLen == 0U)) {
      31            0 :                 return "UNKNOWN";
      32              :             }
      33            0 :             (void)snprintf_s(unknownDesc, unknownDescLen, unknownDescLen - 1U, "UNKNOWN(%d)", (int32_t)runMode);
      34            0 :             unknownDesc[unknownDescLen - 1U] = '\0';
      35            0 :             return unknownDesc;
      36              :     }
      37              : }
      38              : 
      39            8 : aclError aclrtSetDevice(int32_t deviceId)
      40              : {
      41            8 :     const rtError_t rtErr = rtSetDevice(deviceId);
      42            8 :     if (rtErr != RT_ERROR_NONE) {
      43            1 :         ACL_LOG_CALL_ERROR("open device %d failed, rt ret = %d.", deviceId, (int32_t)(rtErr));
      44            1 :         return rtErr;
      45              :     }
      46            7 :     Status ret = GeNofifySetDevice(0, (uint32_t)deviceId);
      47            7 :     if (ret != SUCCESS) {
      48            1 :         ACL_LOG_CALL_ERROR("prof notify device %d fail, result = %d.", deviceId, (int32_t)(ret));
      49            1 :         return ret;
      50              :     }
      51            6 :     ACL_LOG_INFO("set deviceId = %d success", deviceId);
      52            6 :     return ACL_SUCCESS;
      53              : }
      54              : 
      55            8 : aclError aclrtResetDevice(int32_t deviceId)
      56              : {
      57            8 :     const rtError_t rtErr = rtDeviceReset(deviceId);
      58            8 :     if (rtErr != RT_ERROR_NONE) {
      59            1 :         ACL_LOG_CALL_ERROR("reset device %d failed, rt ret = %d.", deviceId, (int32_t)(rtErr));
      60            1 :         return rtErr;
      61              :     }
      62            7 :     ACL_LOG_INFO("reset deviceId = %d success.", deviceId);
      63            7 :     return ACL_SUCCESS;
      64              : }
      65              : 
      66            3 : aclError aclrtGetDevice(int32_t* deviceId)
      67              : {
      68            3 :     if (deviceId == NULL) {
      69            1 :         ACL_LOG_ERROR("deviceId is NULL");
      70            1 :         return ACL_ERROR_INVALID_PARAM;
      71              :     }
      72            2 :     const rtError_t rtErr = rtGetDevice(deviceId);
      73            2 :     if (rtErr != RT_ERROR_NONE) {
      74            1 :         ACL_LOG_INFO("can not get device id, rt ret = %d.", (int32_t)(rtErr));
      75            1 :         return rtErr;
      76              :     }
      77            1 :     return ACL_SUCCESS;
      78              : }
      79              : 
      80            4 : aclError aclrtGetRunMode(aclrtRunMode* runMode)
      81              : {
      82            4 :     if (runMode == NULL) {
      83            1 :         ACL_LOG_ERROR("runMode is NULL");
      84            1 :         return ACL_ERROR_INVALID_PARAM;
      85              :     }
      86              :     rtRunMode rtMode;
      87            3 :     const rtError_t rtErr = rtGetRunMode(&rtMode);
      88            3 :     if (rtErr != RT_ERROR_NONE) {
      89            1 :         ACL_LOG_CALL_ERROR("get runMode failed ret = %d.", (int32_t)(rtErr));
      90            1 :         return rtErr;
      91              :     }
      92            2 :     if (rtMode == RT_RUN_MODE_OFFLINE) {
      93            1 :         *runMode = ACL_DEVICE;
      94            1 :         return ACL_SUCCESS;
      95              :     }
      96            1 :     *runMode = ACL_HOST;
      97            1 :     char runModeDesc[ACL_ENUM_DESC_LEN] = {0};
      98            1 :     ACL_LOG_INFO("get runMode success, runMode = %s.", GetRunModeDesc(*runMode, runModeDesc, sizeof(runModeDesc)));
      99            1 :     return ACL_SUCCESS;
     100              : }
     101              : #if defined(__cplusplus)
     102              : }
     103              : #endif
        

Generated by: LCOV version 2.0-1