CANN/ge HcomAllReduce多卡图构建示例

发布时间:2026/11/5 12:29:46

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/11/3 9:00:49

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

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

2026/11/5 12:29:46

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

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

2026/11/5 12:29:32

Text to SQL系统第三层实现:复杂查询意图识别与优化

1. 项目概述Text to SQL系统作为自然语言处理与数据库技术交叉领域的重要应用,正在深刻改变着非技术人员与数据库交互的方式。这个看似简单的"输入问题,输出SQL"功能背后,隐藏着复杂的实现逻辑和技术挑战。今天我们就来拆解这个系统…

2026/11/5 12:29:32

Text-to-SQL系统架构解析与性能优化实践

1. 文本到SQL转换系统的核心价值 在数据驱动的时代,SQL作为与数据库交互的标准语言,其重要性不言而喻。但编写SQL查询需要专业技能,这成为了许多非技术用户获取数据的障碍。Text-to-SQL系统正是为解决这一痛点而生,它允许用户用自…

2026/11/5 12:29:32

钉钉办公自动化:OpenClaw Skill原理与应用

1. 项目概述 OpenClaw Skill是一个基于自动化原理设计的办公效率工具,专门针对钉钉平台的操作优化。它能模拟人工操作流程,实现消息自动收发、审批流程处理、考勤数据管理等高频办公场景的自动化。我在实际使用中发现,这个工具特别适合需要频…

2026/11/5 12:29:32

AI编程辅助工具:5个提升代码可用性的Prompt模板

1. 项目背景与核心价值 去年团队引入AI编程辅助工具时,我们经历了从"玩具demo"到"生产级应用"的艰难跨越。最深的体会是:需求沟通的质量直接决定了AI产出的可用性。那些模糊的"做个用户管理系统"之类的需求,AI…

2026/11/5 12:24:32

云原生智能体协同架构在城市轨道交通中的应用

1. 新一代城市轨道交通云原生智能体协同架构概述城市轨道交通作为现代都市的"大动脉",其运营效率和服务质量直接影响着千万市民的日常生活。近年来,随着云计算、人工智能等技术的快速发展,传统的轨道交通智能化系统架构正面临着前所…

2026/11/5 12:14:29

Stimulsoft Reports 2019.2.2 落地指南:老系统兼容与版本陷阱规避

简介:Stimulsoft Reports 2019.2.2 是一款面向.NET开发者的专业报表控件,适用于WinForms、ASP.NET及WPF平台,帮助开发者快速构建数据可视化报表与打印输出功能,尤其适合中高级C#工程师在企业级管理系统、BI看板或财务报表模块中集…

2026/11/4 12:38:23

面向复杂光照与角度的宠物面部识别鲁棒性增强策略

在智慧养宠时代,基于视觉的宠物身份识别技术正逐步从实验室走向家庭应用。然而,与配合度高的人类不同,宠物是典型的“非合作生物识别对象”——它们不会主动配合摄像头调整姿态,更无法控制光照环境。实际应用中,我们常…

2026/11/4 21:04:25

SSM电子书店源码全解析:结构、原理、部署与排错实战

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

2026/11/5 0:02:07

多智能体协作系统架构设计与实践优化

1. 多智能体协作系统的时代背景2017年Transformer架构的诞生彻底改变了人工智能的发展轨迹。当行业还沉浸在单一大模型带来的性能突破时,Anthropic的研究团队已经将目光投向了更前沿的领域——如何让多个智能体通过协作产生超越单体能力的系统智能。这就像交响乐团中…

2026/11/5 0:02:07

大模型系统性入门实战指南:从原理到部署微调的全链路路线

提到大模型的系统性入门,我先说个结论:这事真不难,难的是资料太散、路线太多,今天这个框架明天那个工具,新人很容易在“收藏夹吃灰”和“教程看到一半放弃”之间反复横跳。市面上关于大模型的内容少说有几十万篇&#…

2026/11/5 0:02:07

鸿蒙文件系统沙箱机制解析与开发实践

1. 鸿蒙文件系统沙箱机制深度解析作为一名从Android转向鸿蒙开发的工程师,我深刻体会到文件系统访问是迁移过程中最先遇到的"拦路虎"。在Android上运行良好的文件读写代码,在鸿蒙真机环境却频频出现文件写入后神秘消失或直接抛出权限拒绝错误的…

2026/11/4 12:38:23

面向复杂光照与角度的宠物面部识别鲁棒性增强策略

在智慧养宠时代,基于视觉的宠物身份识别技术正逐步从实验室走向家庭应用。然而,与配合度高的人类不同,宠物是典型的“非合作生物识别对象”——它们不会主动配合摄像头调整姿态,更无法控制光照环境。实际应用中,我们常…

2026/11/4 21:04:25

SSM电子书店源码全解析:结构、原理、部署与排错实战

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

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

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

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