CANN/ge动态输出操作符示例指南

发布时间:2026/9/10 21:35:55
CANN/ge动态输出操作符示例指南 Sample Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge1. Function DescriptionThis sample demonstrates graph construction using dynamic output operators, aimed at helping graph developers quickly understand dynamic output definition and usage.2. Directory Structurepython/ ├── src/ | └── make_split_graph.py // sample file ├── CMakeLists.txt // Build script ├── README.md // README file ├── run_sample.sh // Execution script3. 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 ExecuteNote: Compared with C/C graph construction, Python graph construction requires additional LD_LIBRARY_PATH and PYTHONPATH settings (refer to configuration in sample)bash run_sample.sh -t sample_and_run_pythonThis command will:Automatically generate ES interfacesCompile sample programGenerate dump graph and run the graphAfter 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 displayOutput 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 netron3.3. Log PrintingIf 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_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_run_pythonto 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. Dynamic OutputConcept Explanation:Dynamic output refers to operators whose output count is not fixed; for example, Split operator is a dynamic output operator.Graph Construction API Features:Need a parameter to pass dynamic output countFor example, Split operator prototype is shown below, ES graph construction generated API isSplit(), supporting use in PythonREG_OP(Split) .INPUT(split_dim, TensorType({DT_INT32})) .INPUT(x, TensorType({DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16, DT_INT32, DT_INT64, DT_INT8, DT_QINT16, DT_QINT32, DT_QINT8, DT_QUINT16, DT_QUINT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8, DT_BF16, DT_BOOL})) .DYNAMIC_OUTPUT(y, TensorType({DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16, DT_INT32, DT_INT64, DT_INT8, DT_QINT16, DT_QINT32, DT_QINT8, DT_QUINT16, DT_QUINT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8, DT_BF16, DT_BOOL})) .REQUIRED_ATTR(num_split, Int) .OP_END_FACTORY_REG(Split)Its corresponding function prototype is:Function name: Split()Parameters: 4 in total, in order: split_dim, x, y_num, num_splitReturn value: output yNote: Because current IR definition does not explicitly describe input/attribute → dynamic output count mapping relationship, graph construction API cannot automatically deduce output count, so output count needs to be manually specified;Python API:Split(split_dim: Union[TensorHolder, TensorLike], x: Union[TensorHolder, TensorLike], y_num: int, *, num_split: int) - List[TensorHolder]:Note:Use TensorLike type to express input, to support case where actual parameter can directly pass numeric values【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询