Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/dttest/api/python/ge/ge/_capi/pyge_utils_wrapper.py: 100%
22 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-27 10:02 +0800
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-27 10:02 +0800
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# -----------------------------------------------------------------------------------------------------------
4# Copyright (c) 2026 Huawei Technologies Co., Ltd.
5# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
6# CANN Open Software License Agreement Version 2.0 (the "License").
7# Please refer to the License for details. You may not use this file except in compliance with the License.
8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.
11# -----------------------------------------------------------------------------------------------------------
13"""ctypes wrapper for GE utility APIs."""
15import ctypes
16import os
18from ._lib_loader import load_lib_from_path
20LIB_NAME = "libge_utils_wrapper.so"
21_dir = os.path.dirname(os.path.abspath(__file__))
22ge_utils_lib = load_lib_from_path(LIB_NAME, _dir)
24# 常用C类型别名
25c_void_p = ctypes.c_void_p
26c_char_ptr = ctypes.POINTER(ctypes.c_char)
27c_bool = ctypes.c_bool
28c_int64 = ctypes.c_int64
29c_size_t = ctypes.c_size_t
30c_uint32 = ctypes.c_uint32
32# ============ GeUtils C API ============
34ge_utils_lib.GeApiWrapper_GeUtils_InferShape.argtypes = [
35 c_void_p,
36 ctypes.POINTER(c_int64),
37 c_size_t,
38 ctypes.POINTER(c_size_t),
39 c_size_t,
40]
41ge_utils_lib.GeApiWrapper_GeUtils_InferShape.restype = c_uint32
43ge_utils_lib.GeApiWrapper_GeUtils_CheckNodeSupportOnAicore.argtypes = [
44 c_void_p,
45 ctypes.POINTER(c_bool),
46 ctypes.POINTER(c_char_ptr),
47]
48ge_utils_lib.GeApiWrapper_GeUtils_CheckNodeSupportOnAicore.restype = c_uint32
50ge_utils_lib.GeApiWrapper_GeUtils_FreeString.argtypes = [c_char_ptr]
51ge_utils_lib.GeApiWrapper_GeUtils_FreeString.restype = None
54def get_ge_utils_lib():
55 """Get the GE utils wrapper library handle.
57 Returns:
58 ctypes.CDLL: The loaded libge_utils_wrapper.so library handle.
59 """
60 return ge_utils_lib
63def is_ge_utils_lib_loaded():
64 """Check if GE utils library is loaded.
66 Returns:
67 bool: True if library is loaded successfully.
68 """
69 return ge_utils_lib is not None