news 2026/9/10 4:44:37

昇腾/GE异步操作符重载示例

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
昇腾/GE异步操作符重载示例

Sample Usage Guide

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

1. Function Description

This sample demonstrates graph construction using operator overload, aimed at helping graph developers quickly understand operator overload definition. Unlikeoperator_overload, this directory usesSession.run_graph_with_stream_asyncinterface during execution phase. For more information about asynchronous execution, please refer to Asynchronous Execution.

2. Directory Structure

python/ ├── src/ | ├── common.py // Common logic: constants, graph construction, input tensors, GE lifecycle | ├── make_add_graph.py // Asynchronous execution sample | └── make_add_graph_custom_allocator.py // Register custom SamplePoolAllocator asynchronous execution sample ├── README.md // README file ├── run_sample.sh // Execution script

3. Usage Instructions

3.1. Prepare CANN Package

  • This sample requires installing two sets of CANN simultaneously: latest development package for graph compilation, officially released package from website providespyACLmodule for graph execution. "Compilation" and "execution" in this text specifically refer to graph compilation and graph execution, not GE engineering source code compilation.
  • Installation please refer to:
    • Latest development package, for graph compilation, provides latest GE/Python capabilities required by this sample. Installation please refer to Environment Preparation "Method 3: Manual installation of software packages > Scenario 1: Experience master version capabilities or develop based on master version", install latest version oftoolkitandopspackages
    • Officially released CANNtoolkitandopspackages, for graph execution, providepyACL. Installation please refer to Environment Preparation "Method 3: Manual installation of software packages > Scenario 2: Experience released version capabilities or develop based on released version", install officially released software packages
  • Set environment variables (assuming latest development package is installed at /usr/local/Ascend/, officially released package is installed at /usr/local/Ascend-release/)
source /usr/local/Ascend/cann/set_env.sh export PYTHONPATH="$PYTHONPATH:/usr/local/Ascend-release/cann/python/site-packages"

3.2. Execute

This directory provides two optional targets:

3.2.1. Default allocator sample
bash run_sample.sh -t sample_and_run_python

This command will:

  1. Generate dump graph and use GE built-in allocator to asynchronously execute the graph

After successful execution, you will see:

[Success] sample execution successful, pbtxt dump generated in current directory. The file starts with ge_onnx_ and can be opened in netron for display
3.2.2. Custom allocator sample
bash run_sample.sh -t sample_and_run_python_custom_allocator

This command on basis of default sample, throughSession.register_external_allocatorregisters customSamplePoolAllocatorto GE. This class inheritsge.allocator.Allocatorbase class: maintains free block list byexact byte count, hits then reuse, otherwiseacl.rt.mallocallocate;freetime puts block back to pool (not immediatelyacl.rt.free). When object is recycled, in__del__uniformlyacl.rt.freecached blocks.

After successful execution, terminal will show output in following format (specific line count depends on GE allocation/release for output Tensor; address andsizebased on actual execution):

[Info] SamplePoolAllocator registered to stream [SamplePool] new : addr=0x<device memory address> size=<byte count> B [Info] Asynchronous Graph execution successful! [SamplePool] cache : addr=0x<device memory address> size=<byte count> B [Info] SamplePoolAllocator unregistered [SamplePool] destroy: freed <N> cached blocks [Info] Running environment cleaned [Success] sample execution successful, pbtxt dump generated in current directory. The 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 current directory:

  • ge_onnx_*.pbtxt- protobuf text format of graph structure, 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 beforebash run_sample.sh -t sample_and_run_pythonto print logs to screen:

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

3.4. DUMP Graph During Graph Compilation Process

If you need to DUMP graph to assist debugging graph compilation process during executable program execution, you can set the following environment variables beforebash run_sample.sh -t sample_and_run_pythonto DUMP graph to execution path:

export DUMP_GE_GRAPH=2

4. Core Concepts Introduction

4.1. Graph Construction Steps

  • Create graph builder (provides context, workspace and construction-related methods needed for graph construction)
  • Add starting nodes (starting 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 using existing nodes as inputs)
  • Set graph output (explicitly specify graph output nodes as computation result endpoints)

4.2. Operator Overload

Concept Explanation:Operator overload is a syntax sugar provided by ES API, with syntax encapsulation for AI operators, making graph construction code more concise and intuitive.

Graph Construction API Features:

  • Operator overload maintains the same type checking and constraints as function calls

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

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

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

CamoFox-Browser:基于Firefox ESR的反爬伪装运行时方案

1. 项目概述&#xff1a;CamoFox-Browser不是浏览器&#xff0c;而是一套“隐身式”自动化控制方案你搜“camofox-browser”&#xff0c;页面上跳出来的全是Firefox、C、Playwright、Puppeteer这些词——但根本找不到一个叫“CamoFox Browser”的官方产品、GitHub仓库或下载链接…

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

AST驱动的规约协同开发:手机端指挥Kiro+Claude+Codex工作流

1. 项目概述&#xff1a;这不是一个“手机App”&#xff0c;而是一套可落地的规约协同工作流 你看到标题里写着“手机端掌控 Kiro”&#xff0c;第一反应可能是——又一个吹嘘移动端功能的营销话术&#xff1f;别急&#xff0c;我用三台不同型号的安卓手机&#xff08;Pixel 7、…

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

免费物联网云平台选型与组态实操:从OneNET到FUXA

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

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

微信里装进Claude Code:Grix实现AI编程与群聊协作实战

# 把 Claude Code 装进“微信”&#xff1a;用 Grix 随时随地指挥 AI 编程与群聊协作实战接触 Claude Code 一段时间后&#xff0c;我最大的感受是&#xff1a;这玩意儿在电脑前确实能打&#xff0c;可一旦离开工位就抓瞎。命令行工具绑死在终端里&#xff0c;手机上没法直接调…

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

Claude Code Router 接入 LINE:AgentClaw 消息接力完整配置指南

Claude Code Router 接入 LINE&#xff1a;AgentClaw 消息接力完整配置指南 【免费下载链接】claude-code-router One local control plane for every AI agent: route across models, fuse new capabilities, orchestrate tools, and stay fully in control. 项目地址: http…

作者头像 李华