LCOV - code coverage report
Current view: top level - acl/aclrt_c/runtime - context.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 40 40 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             : 
      14             : #ifdef __cplusplus
      15             : extern "C" {
      16             : #endif
      17             : 
      18           3 : aclError aclrtCreateContext(aclrtContext *context, int32_t deviceId) {
      19           3 :   if (context == NULL) {
      20           1 :     ACL_LOG_ERROR("context is NULL");
      21           1 :     return ACL_ERROR_INVALID_PARAM;
      22             :   }
      23             : 
      24           2 :   rtContext_t rtCtx = NULL;
      25             :   const rtError_t rtErr =
      26           2 :     rtCtxCreateEx(&rtCtx, (uint32_t)(RT_CTX_NORMAL_MODE), deviceId);
      27           2 :   if (rtErr != RT_ERROR_NONE) {
      28           1 :     ACL_LOG_CALL_ERROR(
      29             :         "create context failed, device is %d, ret=%d",
      30             :         deviceId, (int32_t)(rtErr));
      31           1 :     return rtErr;
      32             :   }
      33             : 
      34           1 :   *context = (aclrtContext)(rtCtx);
      35           1 :   return ACL_SUCCESS;
      36             : }
      37             : 
      38           3 : aclError aclrtDestroyContext(aclrtContext context) {
      39           3 :   if (context == NULL) {
      40           1 :     ACL_LOG_ERROR("context is NULL");
      41           1 :     return ACL_ERROR_INVALID_PARAM;
      42             :   }
      43           2 :   const rtError_t rtErr = rtCtxDestroyEx((rtContext_t)(context));
      44           2 :   if (rtErr != RT_ERROR_NONE) {
      45           1 :     ACL_LOG_CALL_ERROR("destroy context failed, ret=%d",
      46             :                        (int32_t)(rtErr));
      47           1 :     return rtErr;
      48             :   }
      49           1 :   return ACL_SUCCESS;
      50             : }
      51             : 
      52           3 : aclError aclrtSetCurrentContext(aclrtContext context) {
      53           3 :   if (context == NULL) {
      54           1 :     ACL_LOG_ERROR("context is NULL");
      55           1 :     return ACL_ERROR_INVALID_PARAM;
      56             :   }
      57           2 :   const rtError_t rtErr = rtCtxSetCurrent((rtContext_t)(context));
      58           2 :   if (rtErr != RT_ERROR_NONE) {
      59           1 :     ACL_LOG_CALL_ERROR("set current context failed, ret=%d",
      60             :                        (int32_t)(rtErr));
      61           1 :     return rtErr;
      62             :   }
      63           1 :   return ACL_SUCCESS;
      64             : }
      65             : 
      66           3 : aclError aclrtGetCurrentContext(aclrtContext *context) {
      67           3 :   if (context == NULL) {
      68           1 :     ACL_LOG_ERROR("context is NULL");
      69           1 :     return ACL_ERROR_INVALID_PARAM;
      70             :   }
      71             : 
      72           2 :   rtContext_t rtCtx = NULL;
      73           2 :   const rtError_t rtErr = rtCtxGetCurrent(&rtCtx);
      74           2 :   if (rtErr != RT_ERROR_NONE) {
      75           1 :     ACL_LOG_INFO("can not get current context, ret=%d",
      76             :                  (int32_t)(rtErr));
      77           1 :     return rtErr;
      78             :   }
      79             : 
      80           1 :   *context = rtCtx;
      81           1 :   return ACL_SUCCESS;
      82             : }
      83             : 
      84             : #if defined(__cplusplus)
      85             : }
      86             : #endif

Generated by: LCOV version 1.14