LCOV - code coverage report
Current view: top level - acl/aclrt_c/runtime - device.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 43 43 100.0 %
Date: 2026-08-27 13:24:42 Functions: 4 4 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 "acl/acl_rt.h"
      11             : #include "log_inner.h"
      12             : #include "runtime/rt.h"
      13             : #include "ge_executor_rt.h"
      14             : 
      15             : #ifdef __cplusplus
      16             : extern "C" {
      17             : #endif
      18             : 
      19           8 : aclError aclrtSetDevice(int32_t deviceId) {
      20           8 :   const rtError_t rtErr = rtSetDevice(deviceId);
      21           8 :   if (rtErr != RT_ERROR_NONE) {
      22           1 :     ACL_LOG_CALL_ERROR("open device %d failed, rt ret = %d.", deviceId,
      23             :                        (int32_t)(rtErr));
      24           1 :     return rtErr;
      25             :   }
      26           7 :   Status ret = GeNofifySetDevice(0, (uint32_t)deviceId);
      27           7 :   if (ret != SUCCESS) {
      28           1 :     ACL_LOG_CALL_ERROR("prof notify device %d fail, result = %d.", deviceId,
      29             :                        (int32_t)(ret));
      30           1 :     return ret;
      31             :   }
      32           6 :   ACL_LOG_INFO("set deviceId = %d success", deviceId);
      33           6 :   return ACL_SUCCESS;
      34             : }
      35             : 
      36           8 : aclError aclrtResetDevice(int32_t deviceId) {
      37           8 :   const rtError_t rtErr = rtDeviceReset(deviceId);
      38           8 :   if (rtErr != RT_ERROR_NONE) {
      39           1 :     ACL_LOG_CALL_ERROR("reset device %d failed, rt ret = %d.", deviceId,
      40             :                        (int32_t)(rtErr));
      41           1 :     return rtErr;
      42             :   }
      43           7 :   ACL_LOG_INFO("reset deviceId = %d success.", deviceId);
      44           7 :   return ACL_SUCCESS;
      45             : }
      46             : 
      47           3 : aclError aclrtGetDevice(int32_t *deviceId) {
      48           3 :   if (deviceId == NULL) {
      49           1 :     ACL_LOG_ERROR("deviceId is NULL");
      50           1 :     return ACL_ERROR_INVALID_PARAM;
      51             :   }
      52           2 :   const rtError_t rtErr = rtGetDevice(deviceId);
      53           2 :   if (rtErr != RT_ERROR_NONE) {
      54           1 :     ACL_LOG_INFO("can not get device id, rt ret = %d.", (int32_t)(rtErr));
      55           1 :     return rtErr;
      56             :   }
      57           1 :   ACL_LOG_INFO("get device success, deviceId = %d.", *deviceId);
      58           1 :   return ACL_SUCCESS;
      59             : }
      60             : 
      61           4 : aclError aclrtGetRunMode(aclrtRunMode *runMode) {
      62           4 :   if (runMode == NULL) {
      63           1 :     ACL_LOG_ERROR("runMode is NULL");
      64           1 :     return ACL_ERROR_INVALID_PARAM;
      65             :   }
      66           3 :   rtRunMode rtMode;
      67           3 :   const rtError_t rtErr = rtGetRunMode(&rtMode);
      68           3 :   if (rtErr != RT_ERROR_NONE) {
      69           1 :     ACL_LOG_CALL_ERROR("get runMode failed ret = %d.", (int32_t)(rtErr));
      70           1 :     return rtErr;
      71             :   }
      72           2 :   if (rtMode == RT_RUN_MODE_OFFLINE) {
      73           1 :     *runMode = ACL_DEVICE;
      74           1 :     return ACL_SUCCESS;
      75             :   }
      76           1 :   *runMode = ACL_HOST;
      77           1 :   ACL_LOG_INFO("get runMode success, runMode = %d.", (int32_t)(*runMode));
      78           1 :   return ACL_SUCCESS;
      79             : }
      80             : #if defined(__cplusplus)
      81             : }
      82             : #endif

Generated by: LCOV version 1.14