Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/dttest/api/python/ge/ge/_capi/pytensor_runtime_wrapper.py: 88%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-27 10:03 +0800

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3# ------------------------------------------------------------------- 

4# ----------------------------------------------------------------------------------------------------------- 

5# Copyright (c) 2026 Huawei Technologies Co., Ltd. 

6# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 

7# CANN Open Software License Agreement Version 2.0 (the "License"). 

8# Please refer to the License for details. You may not use this file except in compliance with the License. 

9# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 

10# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. 

11# See LICENSE in the root of the software repository for the full text of the License. 

12# ----------------------------------------------------------------------------------------------------------- 

13 

14import ctypes 

15import os 

16 

17from ._lib_loader import load_lib_from_path 

18 

19LIB_NAME = "libge_runtime_wrapper.so" 

20_dir = os.path.dirname(os.path.abspath(__file__)) 

21tensor_runtime_lib = load_lib_from_path(LIB_NAME, _dir) 

22 

23c_void_p = ctypes.c_void_p 

24c_int = ctypes.c_int 

25 

26tensor_runtime_lib.GeApiWrapper_Tensor_ToHost.restype = c_int 

27tensor_runtime_lib.GeApiWrapper_Tensor_ToHost.argtypes = [c_void_p] 

28 

29tensor_runtime_lib.GeApiWrapper_Tensor_ToDevice.restype = c_int 

30tensor_runtime_lib.GeApiWrapper_Tensor_ToDevice.argtypes = [c_void_p] 

31 

32 

33def get_tensor_runtime_lib(): 

34 """Get the tensor runtime wrapper library handle. 

35 

36 Returns: 

37 ctypes.CDLL: The loaded libge_runtime_wrapper.so library handle. 

38 """ 

39 return tensor_runtime_lib 

40 

41 

42def is_tensor_runtime_lib_loaded(): 

43 """Check if tensor runtime library is loaded. 

44 

45 Returns: 

46 bool: True if library is loaded successfully. 

47 """ 

48 return tensor_runtime_lib is not None