news 2026/9/10 4:48:57

CANN/ge动态输入算子示例

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/ge动态输入算子示例

Sample Usage Guide

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

1. Functional Description

This sample uses dynamic input operators for graph construction, aiming to help graph construction developers quickly understand the definition and usage of dynamic input

2. Directory Structure

python/ ├── src/ | └── make_concatv2_graph.py // sample file ├── CMakeLists.txt // Compilation script ├── README.md // README file ├── run_sample.sh // Execution script

3. Usage

3.1. Prepare CANN Package

  • Correctly installtoolkitandopspackages through installation guide Environment Preparation
  • Set environment variables (assuming packages are installed in /usr/local/Ascend/)
source /usr/local/Ascend/cann/set_env.sh

3.2. Compilation and Execution

  • Note: Compared with C/C++ graph construction, Python graph construction requires additional LD_LIBRARY_PATH and PYTHONPATH (refer to sample configuration)
bash run_sample.sh -t sample_and_run_python

This command will:

  1. Automatically generate ES interfaces
  2. Compile sample program
  3. Generate dump graph and run the graph

After successful execution you will see:

[Success] sample executed successfully, pbtxt dump generated in current directory. This file starts with ge_onnx_ and can be opened in netron for display
Output File Description

After successful execution, the following files will be generated in the current directory:

  • ge_onnx_*.pbtxt- Graph structure protobuf text format, can be viewed with netron

3.3. Log Printing

If you need log printing to assist debugging during executable program execution, you can set the following environment variables before bash run_sample.sh -t sample_and_run_python to print logs to screen

export ASCEND_SLOG_PRINT_TO_STDOUT=1 #Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL=0 #Log level is debug level

3.4. DUMP Graph During Graph Compilation Process

During executable program execution, if you need to DUMP graph to assist debugging graph compilation process, you can set the following environment variable before bash run_sample.sh -t sample_and_run_python to DUMP graph to execution path

export DUMP_GE_GRAPH=2

4. Core Concept Introduction

4.1. Graph Construction Steps

  • Create graph builder (used to provide context, workspace and construction-related methods needed for graph construction)
  • Add start nodes (start nodes refer to nodes without input dependencies, usually including graph inputs (like Data nodes) and weight constants (like Const nodes))
  • Add intermediate nodes (intermediate nodes are computation nodes with input dependencies, usually generated by user graph construction logic, and connected through existing nodes as inputs)
  • Set graph output (explicitly specify graph output nodes as endpoints of computation results)

4.2. Dynamic Input

Concept Description:Dynamic input refers to operators whose input count is not fixed; for example, ConcatV2 operator, which is a dynamic multi-input operator

The prototype of ConcatV2 operator is shown below, the ES graph construction generated API isConcatV2(), supports usage in Python

REG_OP(ConcatV2) .DYNAMIC_INPUT(x, TensorType({BasicType(), DT_BOOL, DT_STRING})) .INPUT(concat_dim, TensorType::IndexNumberType()) .OUTPUT(y, TensorType({BasicType(), DT_BOOL, DT_STRING})) .ATTR(N, Int, 1) .OP_END_FACTORY_REG(ConcatV2)

Its corresponding function prototype is:

  • Function name: ConcatV2
  • Parameters: 3 in total, namely x, concat_dim, N
  • Return value: output y

In Python API:

ConcatV2(x: List[Union[TensorHolder, TensorLike]], concat_dim: Union[TensorHolder, TensorLike], *, N: int =1) -> TensorHolder:

Note: 1. Use TensorLike type to express input, to support the case where actual parameters can directly pass values

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/10 4:48:38

考虑隐私保护的分布式联邦学习电力负荷预测附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,擅长毕业设计辅导、数学建模、数据处理、算法改进、程序设计科研仿真。🍎 往期回顾关注个人主页:完整代码获取 定制创新 论文复现私信🍊个人信条:做科研&#xff0c…

作者头像 李华
网站建设 2026/9/10 4:47:57

鸿蒙人脸识别门禁选型实战:从芯片到工程落地关键点

最近被问得最多的一件事,就是鸿蒙人脸识别门禁到底怎么选型。不是市面上没产品,而是大多数方案还停留在“能演示”阶段,真要拉到园区、写字楼、工地上批量部署,问题就全冒出来了。我陪客户跑了深圳好几家方案商,云识客…

作者头像 李华
网站建设 2026/9/10 4:42:59

AI编程入门实战:30天从零构建可控代码能力

1. 这不是“学完30天就能写代码”的速成课,而是帮你把AI编程真正踩进地里的实操复盘我带过27个零基础学员走完这30天AI编程入门流程,从连终端命令都打不全,到能独立用AI辅助完成一个带数据库的天气查询小工具。这不是鸡汤文,也不是…

作者头像 李华
网站建设 2026/9/10 4:42:50

2026大模型工程师能力图谱:AI工程化实战指南

1. 这不是职业名称,而是一张动态能力地图:拆解“2026年AI大模型工程师”的真实含义“2026年AI大模型工程师”这个标题,乍看像一个招聘JD里的岗位名称,但实际它根本不是静态头衔,而是一张正在高速演化的能力坐标系快照。…

作者头像 李华