Sample Usage Guide
【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge
1. Function Description
This sample uses Sigmoid private attributes for graph construction, aiming to help graph construction developers quickly understand the definition of private attributes and how to use private attributes for graph construction.
2. Directory Structure
cpp/ ├── src/ | └── CMakeLists.txt // CMake build file | └── es_showcase.h // Header file | └── make_sigmoid_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. Usage
3.1 Prepare CANN Package
- Correctly install
toolkitandopspackages following the installation guide Environment Preparation - Set environment variables (assuming the package is installed in /usr/local/Ascend/)
source /usr/local/Ascend/cann/set_env.sh3.2 Build and Execute
1.2.1 Generate ES Interface and Build Graph for DUMP
Simply 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 Description
After 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 Execute
Besides 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 interface
- Compile sample program
- Generate dump graph, run graph and output computation results
After 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 file
3.3 Log Printing
If 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_STDOUT=1 #Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL=0 #Log level set to debug level1.4 Graph Compilation DUMP
If 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_GRAPH=24. Core Concept Introduction
4.1 Graph Construction Steps
- Create 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 Description
Private attributes refer to custom attributes that don't exist in IR definition, ES graph construction provides corresponding interfaces to complete custom attribute settings
【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考