CANN/ge HcomAllReduce多卡图构建示例

发布时间:2026/9/10 4:46:26

CANN/ge HcomAllReduce多卡图构建示例 Sample Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge1. Function DescriptionThis sample demonstrates how to use HcomAllReduce collective communication operator for graph construction, aimed at helping graph developers quickly understand collective communication definition and usage of this type of operators in graph construction.2. Directory Structurecpp/ ├── src/ | ├── CMakeLists.txt // CMake build file | ├── es_showcase.h // Header file | └── make_pfa_hcom_graph.cpp // sample file ├── rank_table/ | ├── a2/ | | └── rank_table_2p.json // A2(d802) 2-card rank table configuration (v1.0) ├── CMakeLists.txt // CMake build file ├── main.cpp // Program main entry ├── README.md // README file ├── run_sample.sh // Execution script └── utils.h // Utility file3. Usage Instructions3.1. Prepare CANN PackageInstalltoolkitandopspackages correctly following Environment PreparationSet environment variables (assuming package is installed at /usr/local/Ascend/)source /usr/local/Ascend/cann/set_env.sh3.2. Build and Execute1.2.1 Generate ES Interfaces and Build Graph for DUMPSimply run the following command to clean, generate interfaces, construct graph and DUMP graph:bash run_sample.shCurrent run_sample.sh behavior: automatically clean old build, build sample and default execute sample dump. When you see the following message, it indicates successful execution:[Success] sample execution successful, pbtxt dump generated in current directory. The file starts with ge_onnx_ and can be opened in netron for display1.2.2 Output File DescriptionAfter successful execution, the following files will be generated in current directory:ge_onnx_*.pbtxt- protobuf text format of graph structure, can be viewed with netron1.2.3 Build Graph and ExecuteImportant Prerequisite: Ensure your system has at least 2 available NPU devicesPlatform Support Description:A2 Platform:lspci | grep d802has output, script automatically usesrank_table/a2/rank_table_2p.jsonA5 Platform:lspci | grep d806has output, script will exit with error (this form is not supported)Other platforms: Current version does not support, will exit with error directly in scriptBesides basic graph construction and dump functionality, this sample also supports actually executing TP graph on multiple cards.Usage:bash run_sample.sh -t sample_and_runThis command will:Automatically generate ES interfacesCompile sample programAutomatically configure rank table and environment variables (RANK_TABLE_FILE,RANK_ID,DEVICE_ID)Run graph in parallel on 2 NPU devices (device ID automatically read from rank_table, each process corresponds to one rank and one device)Use HcomAllReduce for inter-card data synchronizationNote:Script will automatically identify hardware throughlspciand select corresponding rank table (currently only A2 usesrank_table/a2/rank_table_2p.json; A5 does not support this form)If you need to use other devices (like 2,3 or 4,5), please modifydevice_idin rank table file under corresponding platform directoryrun_sample.shwill automatically set all required environment variables, no manual configuration neededAfter successful execution, you will see:[Success] sample_and_run execution successful, pbtxt and data output dump generated in current directoryYou can view computation results through data file3.3. Log PrintingIf you need log printing to assist debugging during executable program execution, you can set the following environment variables beforebash run_sample.shto print logs to screen:export ASCEND_SLOG_PRINT_TO_STDOUT1 # Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL0 # Log level set to debug level3.4. DUMP Graph During Graph Compilation ProcessIf 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_runto DUMP graph to execution path:export DUMP_GE_GRAPH24. Core Concepts Introduction4.1. Graph Construction StepsCreate 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. Multi-card Running Key ConceptsEnvironment Variable Description:When running multi-card sample, script will automatically set the following environment variables:RANK_ID: Logical process number (0 or 1 in this sample)DEVICE_ID: Physical device ID (0 or 1 in this sample)RANK_TABLE_FILE: Rank table configuration file path (currently only A2:rank_table/a2/rank_table_2p.json; A5 does not support this form)For detailed introduction ofRANK_TABLE_FILE,RANK_ID,DEVICE_ID, please refer to Example a2: rank table configuration resource informationGE Initialization Configuration:std::mapge::AscendString, ge::AscendString config { {ge.exec.deviceId, device_id}, // From environment variable DEVICE_ID {ge.graphRunMode, 0}, {ge.exec.rankTableFile, rank_table_file}, // From environment variable RANK_TABLE_FILE {ge.exec.rankId, rank_id} // From environment variable RANK_ID };4.3. TP Graph ConstructionConcept Explanation:TP (Tensor Parallel) graph refers to graph structure running on multiple cards through tensor parallel method. This sample demonstrates how to use ES operators to build TP graph containing collective communication operators, achieving inter-card data synchronization and parallel computation.Graph Construction API Features:Supports multi-operator combination graph construction, including Flash Attention, matrix multiplication, collective communication operators, etc.Uses HcomAllReduce operator to achieve inter-card data aggregation, requires configuring rank table fileSupports data type conversion, can perform FP32 to FP16 conversion inside graph to improve performanceFor example, HcomAllReduce operator prototype is shown below, ES graph construction generated API is HcomAllReduce (C) or EsHcomAllReduce (C)REG_OP(HcomAllReduce) .INPUT(x, TensorType({DT_FLOAT, DT_INT32, DT_INT8, DT_INT16, DT_FLOAT16, DT_INT64})) .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_INT8, DT_INT16, DT_FLOAT16, DT_INT64})) .REQUIRED_ATTR(reduction, String) .REQUIRED_ATTR(group, String) .ATTR(fusion, Int, 1) .ATTR(fusion_id, Int, -1) .OP_END_FACTORY_REG(HcomAllReduce)Its corresponding function prototype is:Function name: HcomAllReduce (C) or EsHcomAllReduce (C)Parameters: 5 in total, in order: x, reduction, group, fusion (optional, default 1), fusion_id (optional, default -1)Return value: output yC API:EsCTensorHolder *EsHcomAllReduce(EsCTensorHolder *x, const char *reduction, const char *group, int64_t fusion, int64_t fusion_id);C API:EsTensorHolder HcomAllReduce(const EsTensorHolder x, const char *reduction, const char *group, int64_t fusion1, int64_t fusion_id-1);Note: fusion and fusion_id are optional parameters in C API with default values, usually can be omitted【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
延伸阅读

更多相关文章

2026/9/10 4:46:26

无官网也能做GEO?一文搞懂生成式引擎优化的底层逻辑与落地路径

1. 先搞清楚一件事:GEO 到底优化的是什么先说个最常见的误解。很多人一听到“AI 搜索引擎优化”,第一反应就是“我得有个网站,然后让 ChatGPT、Perplexity 这些 AI 引擎能抓取到我的页面”。这个想法没错,但它只覆盖了一半场景——…

2026/9/10 4:41:26

硬件应届生核心竞争力:工具实操、故障归因与成本意识

1. 招聘启事里没写的“真实需求清单”“硬件工程师(应届)”——这行字在招聘网站上出现的频率,可能比你每天喝的咖啡次数还高。但真正点开详情页,你会发现:JD(职位描述)写得像一份通用说明书&am…

2026/9/10 5:51:33

ERP Migration - Status Notes (March 2026)

ERP Migration - Status Notes (March 2026) 【免费下载链接】gpt-researcher An autonomous agent that conducts deep research on any data using any LLM providers 项目地址: https://gitcode.com/GitHub_Trending/gp/gpt-researcher Migration from legacy system…

2026/9/10 5:51:32

堆垛机变频器双闭环控制技术:从选型到调试的实战指南

只要你碰过自动化立体仓库,就不可能绕开堆垛机。巷道里那台十几米高、跑起来像小火车一样的大家伙,每一次水平行走、垂直升降、货叉伸缩,背后都是变频器在推着电机干活。很多人觉得堆垛机变频器无非就是个调速器,电机转快转慢而已…

2026/9/9 13:11:35

超人会飞不算本事:系统稳定依赖清晰规则与边界设计

开头先不绕弯子。“#斯坦李吐槽dc 所以超人是无缘无故会飞的嘛哈哈哈哈哈哈哈锤哥真是技术人才啊!#雷神 #复联”这类调侃式短标题,第一波冲击力在于它把两个宇宙的角色塞进同一个吐槽箱里,但细想一下就能发现,它真正碰到的根本不是…

2026/9/8 7:15:15

超人VS蜘蛛侠:拆解超级IP的影响力与传播方法论

把“蜘蛛侠 vs 超人”放在 CSDN 上聊,可能很多人第一反应是走错片场了。但如果把这两个角色看成“两个持续运营了 80 多年的文化产品”,你会发现,这场比较本质上是两个不同 IP 策略的长期结果对比:超人赢在定义了整个超级英雄题材…

2026/9/9 16:31:09

基于CNN的调制信号识别:MATLAB实现时频图分类实战

简介:本资源是一套面向通信工程与信号处理方向学习者、研究者的深度学习实践方案,聚焦调制信号自动检测与识别这一典型无线通信任务,解决传统方法依赖人工特征、低信噪比下性能下降等痛点。压缩包共12个文件(10.73MB)&…

2026/9/10 0:00:55

目录对比去重实战:用哈希算法精准清理重复文件

我电脑里现在还有一块换了三次机的“数据墓地”硬盘,里面存着2016年以前所有旧笔记本的完整备份。平时不觉得有什么,直到前阵子想把它整理归档,发现同一个安装包、同一批照片、同一份论文草稿,在几个不同的备份目录里反复出现。更…

2026/9/10 0:00:55

Leaflet离线地图完整Demo合集:内网部署与坐标纠偏实战

简介:这是一份面向Web GIS开发者的LeafLet离线地图示例合集,帮助开发者快速掌握离线地图从搭建到交互的完整流程。压缩包共723个文件,大小14.06MB,以319个js脚本、175个html页面和29个css样式文件为主体,配合png/svg图…

2026/9/10 0:00:55

MATLAB读取Rinex 3.02观测文件:多系统GNSS数据解析实战

简介:基于MATLAB开发的Rinex3.02版观测文件(o文件)读取代码包,面向卫星定位导航方向的学习者与研究人员,用于解决新版观测文件的数据解析、历元提取与时间转换问题。压缩包共4个文件,包含两个m脚本、一个19…

2026/9/7 16:23:03

USB Type-C PCB布局分区设计:电源、高速信号与PD协议全攻略

做硬件这行,Type-C接口算是典型的“看着简单,做起来全坑”的东西。光引脚就24个,高低速信号、电源、控制线全部塞在一个小小的连接器里,如果PCB布局不做规划,打样回来基本就是“插上没反应”、“高速掉线”、“静电一打…

2026/9/7 22:46:00

系统编程学习原型如何补齐稳定性边界

系统编程学习原型如何补齐稳定性边界预算有限时&#xff0c;我先优化明显多余的复制&#xff0c;而不是猜测性地换容器。用借用传递只读数据通常就能减少分配&#xff1a; fn parse(line: &str) -> Result<Item, Error> { /* ... */ }用基准确认热点确实在分配&am…

2026/9/9 10:21:54

雨花区哪家财务公司代理记账比较好?

在雨花区&#xff0c;企业处理财税事务常常面临诸多挑战&#xff0c;选择一家靠谱的财务公司至关重要。湖南巨勤财务管理咨询有限公司就是本地正规实体财税服务机构&#xff0c;深耕本地工商财税行业多年&#xff0c;熟悉当地工商局、税务局最新政策与申报流程。主营公司注册、…

还想了解更多?直接咨询顾问

免费诊断 + 免费方案 + 透明报价。

全国咨询热线400-8866-253
免费获取方案
咨询二维码