恒美微站 Logo 恒美微站
  • 首页
  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心
  • 联系我们

CANN/ge可选输入图构建示例

  • 首页
  • 资讯中心
  • /
  • CANN/ge可选输入图构建示例

相关资讯

论文的免费科研元素怎么拆解?按图表公式代码分类 2026/9/10 4:45:15
Authelia 4.39 发布详解:Passkey 无密码登录、OIDC Claims 策略与容器安全加固 2026/9/10 4:45:15
Starship No Nerd Fonts 预设:无需安装 Nerd Font 即可渲染完整符号的提示符配置指南 2026/9/10 4:45:15

最新资讯

持续预训练CPT实战指南:把通用大模型训练成行业专家
Continue 如何通过 apiBase 配置连接远程 Ollama 实例?
Python气象数据分析全流程:爬虫+特征工程+随机森林预测
PON网络运维实战:OLT、ONU与PON口拥塞扩容指南
大模型本地部署实战:从零搭建环境到跑通第一次推理
HTOOL-SL6H便携信号源详解:双通道输出与SCPI自动化测试实战

今日推荐

AI搜索重构内容生态:企业从“流量争夺”转向“答案共建”
AI搜索的信任缺口:企业内容如何在答案时代自证可信
Spring Boot+Vue+Node.js售后服务系统开发实战

本周热门

超人会飞不算本事:系统稳定依赖清晰规则与边界设计
超人VS蜘蛛侠:拆解超级IP的影响力与传播方法论
基于CNN的调制信号识别:MATLAB实现时频图分类实战

本月精选

自研推理加速器Redwood:两周内实现PyTorch模型高效部署的实战教程
V4L2摄像头采集实战:从camera_client.rar到出图全流程解析
从“谁发明了钢琴键”到知识问答智能体:RAG与记忆工程实践

CANN/ge可选输入图构建示例

发布时间:2026/9/10 4:45:15
CANN/ge可选输入图构建示例 Sample Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge1. Function DescriptionThis sample uses BatchNorm operators optional inputs for graph construction, aiming to help graph construction developers quickly understand the definition of optional inputs and how to use this type of operator for graph construction.2. Directory Structurecpp/ ├── src/ | └── CMakeLists.txt // CMake build file | └── es_showcase.h // Header file | └── make_batchnorm_graph.cpp // Sample file ├── CMakeLists.txt // CMake build file ├── main.cpp // Program main entry ├── README.md // README file ├── run_sample.sh // Execution script ├── utils.h // Utility file3. Usage3.1 Prepare CANN PackageCorrectly installtoolkitandopspackages following the installation guide Environment PreparationSet environment variables (assuming the package is installed in /usr/local/Ascend/)source /usr/local/Ascend/cann/set_env.sh3.2 Build and Execute1.2.1 Generate ES Interface and Build Graph for DUMPSimply run the following command to clean up, generate interface, build graph and DUMP graph:bash run_sample.shThe current behavior of run_sample.sh is: automatically clean up old build, build sample and default execute sample dump. When you see the following message, it means successful execution:[Success] sample executed successfully, pbtxt dump has been generated in current directory. This file starts with ge_onnx_ and can be opened in netron for display1.2.2 Output File DescriptionAfter successful execution, the following file 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 ExecuteBesides basic graph building and dump functionality, esb_sample supports building graph and actually executing computation.bash run_sample.sh -t sample_and_runThis command will:Automatically generate ES interfaceCompile sample programGenerate dump graph, run graph and output computation resultsAfter successful execution, you will see:[Success] sample_and_run executed successfully, pbtxt and data output dump have been generated in current directoryYou can check computation results through data file3.3 Log PrintingIf log printing is needed during executable program execution to assist debugging, set the following environment variables before bash run_sample.sh to print logs to screen:export ASCEND_SLOG_PRINT_TO_STDOUT1 #Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL0 #Log level set to debug level1.4 Graph Compilation DUMPIf DUMP graph is needed during executable program execution to assist graph compilation debugging, set the following environment variables before bash run_sample.sh -t sample_and_run to DUMP graph to execution path:export DUMP_GE_GRAPH24. Core Concept Introduction4.1 Graph Construction StepsCreate graph builder (to provide context, workspace and build-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 endpoints of computation results)4.2 Concept DescriptionOptional input refers to certain inputs of an operator that are non-mandatory inputs.For example, BatchNorm operator prototype is shown below, ES graph construction generated API isBatchNorm(), supporting use at C layerREG_OP(BatchNorm) .INPUT(x, TensorType({DT_FLOAT16,DT_FLOAT})) .INPUT(scale, TensorType({DT_FLOAT})) .INPUT(offset, TensorType({DT_FLOAT})) .OPTIONAL_INPUT(mean, TensorType({DT_FLOAT})) .OPTIONAL_INPUT(variance, TensorType({DT_FLOAT})) .OUTPUT(y, TensorType({DT_FLOAT16,DT_FLOAT})) .OUTPUT(batch_mean, TensorType({DT_FLOAT})) .OUTPUT(batch_variance, TensorType({DT_FLOAT})) .OUTPUT(reserve_space_1, TensorType({DT_FLOAT})) .OUTPUT(reserve_space_2, TensorType({DT_FLOAT})) .OUTPUT(reserve_space_3, TensorType({DT_FLOAT})) .ATTR(epsilon, Float, 0.0001f) .ATTR(data_format, String, NHWC) .ATTR(is_training, Bool, true) .ATTR(exponential_avg_factor, Float, 1.0) .OP_END_FACTORY_REG(BatchNorm)Its corresponding function prototype is:Function name: BatchNormParameters: Total 9, sequentially x, scale, offset, mean (optional input), variance (optional input), epsilon, data_format, is_training, exponential_avg_factorReturn values: Outputs y, batch_mean, batch_variance, reserve_space_1, reserve_space_2, reserve_space_3In C API:EsBatchNormOutput EsBatchNorm(EsCTensorHolder *x, EsCTensorHolder *scale, EsCTensorHolder *offset, EsCTensorHolder *mean, EsCTensorHolder *variance, float epsilon, const char *data_format, bool is_training, float exponential_avg_factor); typedef struct { EsCTensorHolder *y; EsCTensorHolder *batch_mean; EsCTensorHolder *batch_variance; EsCTensorHolder *reserve_space_1; EsCTensorHolder *reserve_space_2; EsCTensorHolder *reserve_space_3; } EsBatchNormOutput;In C API:BatchNormOutput BatchNorm(const EsTensorLike x, const EsTensorLike scale, const EsTensorLike offset, const EsTensorLike meannullptr, const EsTensorLike variancenullptr, float epsilon0.000100, const char *data_formatNHWC, bool is_trainingtrue, float exponential_avg_factor1.000000); struct BatchNormOutput { EsTensorHolder y; EsTensorHolder batch_mean; EsTensorHolder batch_variance; EsTensorHolder reserve_space_1; EsTensorHolder reserve_space_2; EsTensorHolder reserve_space_3; };Note: Use TensorLike type to express input, to support cases where actual parameters can directly pass numeric values【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

关于恒美微站

恒美微站专注于为个体商户、工作室提供极简自助建站服务,让每个人都能轻松拥有专业网站。

快速链接

  • 关于我们
  • 建站服务
  • 主题模板
  • 案例展示
  • 资讯中心

服务项目

  • 可视化建站
  • 拖拽编辑
  • 主题定制
  • SEO 优化
  • 网站托管

联系方式

  • 📍 地址:北京市朝阳区建国路 88 号
  • 📞 电话:400-888-8888
  • ✉️ 邮箱:info@hmyw.cn
  • 🕐 时间:周一至周日 9:00-18:00

© 2024 恒美微站 hmyw.cn 版权所有 | 京 ICP 备 12345678 号