
ES API Generation Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geThis document explains howEager Style (ES) APIis generated in the current test framework, and where to modify whenES API graph construction for other operatorsis needed.I. How ES API is Currently Generated1.1 Overall ProcessES API is generated using theoperator prototype generate_es_package.cmake functionapproach:Operator Prototype: Add operator prototypes inproto/test_ops.husingREG_OP(OpName)...OP_END_FACTORY_REG(OpName).Prototype Library: Compile the above file into a dynamic librarytest_ops_prot, which registers all operators in GE when loaded.Code Generation: CMake invokes thegen_esbtool during configuration/build to generate C/C ES graph construction APIs for each operator.Artifacts: Generateses_ge_test_ops.h,es_ge_test_ops_c.h, and correspondinges_OpType.cpp,es_OpType.hfor each operator, compiled into libraryes_ge_test.Therefore:Operators that can participate in ES API generation must first be registered with REG_OP inproto/test_ops.h.1.2 Key Components and PathsComponentPath/DescriptionOperator Prototype Definitiontests/framework/eager_style_graph_builder/proto/test_ops.h(andtest_ops.ccin the same directory)Generation Scriptcmake/generate_es_package.cmake(providesadd_es_library)This Directorys CMaketests/framework/eager_style_graph_builder/CMakeLists.txtGenerated Artifacts DirectoryUnder build directoryeager_style_graph_builder/build/es_output/, headers ininclude/es_ge_test/1.3 Generation Trigger Method (CMake)Intests/framework/eager_style_graph_builder/CMakeLists.txt:Include the cmake function for generating operators viainclude(generate_es_package.cmake).First define and compile the operator prototype librarytest_ops_prot(source file isproto/test_ops.cc, which includes REG_OP fromtest_ops.h).Then call:add_es_library( ES_LINKABLE_AND_ALL_TARGET es_ge_test OPP_PROTO_TARGET test_ops_prot OUTPUT_PATH ${ES_OUTPUT_PATH} )add_es_librarywill:Derive the directory where operator prototypes are located fromtest_ops_protoutput pathSetASCEND_OPP_PATHduring build and executegen_esbgen_esb loads operator libraries from that path and generates C/C codeCompile the generated code intoes_ge_testdynamic library and install toES_OUTPUT_PATHTherefore:The ES API operator set is entirely determined by the operator prototypes loaded by gen_esb, which is currently the REG_OP included intest_ops_prot.1.4 Correspondence with gen_esbgen_esb input: The directory pointed to by environment variableASCEND_OPP_PATH(i.e., the OPP path derived fromtest_ops_prot).gen_esb loads operator .so files from that path, reads operator metadata registered via REG_OP, and then for each operator generates:C interface:es_OpType.cpp declaration ines_ge_test_ops_c.hC interface:es_OpType.h, aggregated ines_ge_test_ops.hII. Where to Modify When Needing ES API Graph Construction for Other OperatorsIf you want to usemore operatorsES API for graph construction, just ensure these operators are registered in the operator prototype library when gen_esb runs. Currently, this library istest_ops_protbuilt fromproto/in this directory.2.1 Adding New OperatorsModification Location:tests/framework/eager_style_graph_builder/proto/test_ops.h(or in conjunction withproto/test_ops.cc)Operation:Add a line intest_ops.hfollowing the existing format:REG_OP(NewOpName)...OP_END_FACTORY_REG(NewOpName), defining inputs/outputs/attributes (refer to existing operator prototypes in the same file).If header file alone is sufficient for registration, only modifytest_ops.h.If the operator already has a REG_OP definition in other modules, you can also#includethe corresponding header file intest_ops.cc, ensuring its linked intotest_ops_prot.so.After saving and rebuilding, gen_esb will generate corresponding ES operators and include them ines_ge_test_ops.h/es_ge_test_ops_c.h. In test cases, you can then:Use C:#include es_ge_test_ops.h, calles::NewOpName(...), etc.Use C:#include es_ge_test_ops_c.h, call generated C functions.For moreadd_es_libraryparameters and behavior, see comments insidecmake/generate_es_package.cmake.【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考