Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/dttest/api/python/ge/ge/onnx_plugin/_bridge.py: 100%
15 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 10:20 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 10:20 +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"""Bridge-facing callback dispatch for Python ONNX Plugins."""
15from ge.graph.operator import create_operator
17from .bootstrap import load_onnx_plugins
18from ._native import OnnxNode
19from .registry import (
20 get_registered_onnx_plugin_by_origin_type,
21 get_registered_onnx_plugin_dicts,
22)
25def load_and_get_onnx_plugin_descriptors() -> list:
26 load_onnx_plugins()
27 return get_registered_onnx_plugin_dicts()
30def call_parse_node(origin_type: str, node: OnnxNode, operator_handle) -> None:
31 """Dispatch one parser-owned ONNX node to its registered parse_node callback.
33 ``node`` and ``operator_handle`` are borrowed objects supplied by the C++
34 bridge for the duration of the callback.
35 """
37 descriptor = get_registered_onnx_plugin_by_origin_type(origin_type)
38 if descriptor is None:
39 raise KeyError(f"python ONNX Plugin is not registered: {origin_type}")
41 with create_operator(operator_handle) as target:
42 result = descriptor.parser_node(node, target)
43 if result is not None:
44 raise TypeError("ONNX Plugin parse_node callback must return None")