news 2026/9/10 21:34:08

CANN/ge离线图编译执行示例

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/ge离线图编译执行示例

Sample Usage Guide

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

1. Function Description

This sample demonstrates the offline graph compilation and execution workflow. For more information about compiling graphs into offline models, refer to Generating Offline Models.

2. Directory Structure

cpp/ ├── CMakeLists.txt // CMake build file ├── main.cpp // Program main entry ├── run_sample.sh // Execution script ├── README.md // README file └── src/ ├── CMakeLists.txt // CMake build file ├── common.h / common.cpp // Common logic files ├── single_model/ // Single model compilation and inference └── bundle_model/ // Bundle compilation and inference

3. Usage

3.1 Prepare CANN Package

  • Correctly installtoolkitandopspackages through Environment Preparation section "Method 3: Manual Package Installation > Scenario 1: Experience master version capabilities or develop based on master version"
  • Set environment variables (assuming package is installed in /usr/local/Ascend/)
source /usr/local/Ascend/cann/set_env.sh

3.2 Graph Compilation and Execution

Execute single model sample:

bash run_sample.sh -t sample_and_run

This command will:

  1. Compile C++ executable program
  2. BuildAddgraph, compile offline and generateadd_sample.om
  3. Load and execute the offline model

Execute bundle sample:

bash run_sample.sh -t sample_and_run_bundle

This command will:

  1. Compile C++ executable program
  2. BundleAddgraph andMulgraph, compile offline and generatebundle_sample.om
  3. Load Bundle and execute two sub-models separately

For offline compilation in cardless scenarios where you need to specify target chip version, add--soc-version:

bash run_sample.sh -s Ascend910B1 -t sample_and_run bash run_sample.sh -s Ascend910B1 -t sample_and_run_bundle

You can also split into "graph compilation only" and "graph execution only" phases:

bash run_sample.sh -t build_model bash run_sample.sh -t run_infer bash run_sample.sh -t build_bundle_model bash run_sample.sh -t run_bundle_infer

run_infer/run_bundle_inferrequires om model to already exist

After successful execution you will see:

[Success] sample execution successful
Output Files Description

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

  • add_sample.om- Single model offline file
  • bundle_sample.om- Bundle offline model file

3.3 Log Printing

If you need log printing to help troubleshoot during executable program execution, you can set the following environment variables beforebash run_sample.shto 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

4. Core Workflow Introduction

4.1 Single Model Offline Compilation and Execution

  • UseaclgrphBuildInitializeto initialize compilation environment
  • BuildGraphand generate offline model viaaclgrphBuildModel
  • Saveomfile usingaclgrphSaveModel
  • Execute offline model viaaclmdlLoadFromFile,aclmdlExecute

4.2 Bundle Offline Compilation and Execution

  • Organize Bundle using multipleGraph
  • Build Bundle model at once viaaclgrphBundleBuildModel
  • Savebundle_sample.omusingaclgrphBundleSaveModel
  • Load Bundle viaaclmdlBundleLoadFromFileand execute sub-models sequentially

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

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

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

Java大数据技术在智能医疗中的应用与实践

1. 智能医疗时代的数据革命电子病历数据正以每年40%的速度增长,三甲医院平均每天产生超过5TB的临床记录。这些数据如果只是静态存储,就如同埋在地下的石油,无法发挥其真正的价值。我在参与某省级医疗大数据平台建设时,亲眼见证过这…

作者头像 李华
网站建设 2026/9/10 21:32:17

AI网关日志裸奔事件复盘:构建可落地的AI安全防线

2026年3月的一个凌晨,我被一通告警电话从床上拽了起来。电话那头,值班同学的嗓子是哑的:“出事了,日志接口在外面裸奔。” 那段时间我正好带着团队做 AI 网关的安全加固,听到这句话,脑子里的第一反应不是“…

作者头像 李华
网站建设 2026/9/10 21:22:21

豆包学习法:构建高效知识管理系统的技术实践

1. 为什么豆包能成为学习神器? 作为一个每天要处理大量信息的知识工作者,我试过市面上几乎所有主流学习工具,直到去年偶然发现豆包这个不起眼的小工具,彻底改变了我的学习效率。你可能在社交平台刷到过"豆包学习法"的分…

作者头像 李华