ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

CANN/ge离线图编译执行示例

CANN/ge离线图编译执行示例 Sample Usage Guide【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge1. Function DescriptionThis sample demonstrates the offline graph compilation and execution workflow. For more information about compiling graphs into offline models, refer to Generating Offline Models.2. Directory Structurecpp/ ├── CMakeLists.txt // CMake build file ├── main.cpp // Program main entry ├── run_sample.sh // Execution script ├── README.md // README file └── src/ ├── CMakeLists.txt // CMake build file ├── common.h / common.cpp // Common logic files ├── single_model/ // Single model compilation and inference └── bundle_model/ // Bundle compilation and inference3. Usage3.1 Prepare CANN PackageCorrectly installtoolkitandopspackages through Environment Preparation section Method 3: Manual Package Installation Scenario 1: Experience master version capabilities or develop based on master versionSet environment variables (assuming package is installed in /usr/local/Ascend/)source /usr/local/Ascend/cann/set_env.sh3.2 Graph Compilation and ExecutionExecute single model sample:bash run_sample.sh -t sample_and_runThis command will:Compile C executable programBuildAddgraph, compile offline and generateadd_sample.omLoad and execute the offline modelExecute bundle sample:bash run_sample.sh -t sample_and_run_bundleThis command will:Compile C executable programBundleAddgraph andMulgraph, compile offline and generatebundle_sample.omLoad Bundle and execute two sub-models separatelyFor offline compilation in cardless scenarios where you need to specify target chip version, add--soc-version:bash run_sample.sh -s Ascend910B1 -t sample_and_run bash run_sample.sh -s Ascend910B1 -t sample_and_run_bundleYou can also split into graph compilation only and graph execution only phases:bash run_sample.sh -t build_model bash run_sample.sh -t run_infer bash run_sample.sh -t build_bundle_model bash run_sample.sh -t run_bundle_inferrun_infer/run_bundle_inferrequires om model to already existAfter successful execution you will see:[Success] sample execution successfulOutput Files DescriptionAfter successful execution, the following files are generated in the current directory:add_sample.om- Single model offline filebundle_sample.om- Bundle offline model file3.3 Log PrintingIf you need log printing to help troubleshoot during executable program execution, you can set the following environment variables beforebash run_sample.shto print logs to screenexport ASCEND_SLOG_PRINT_TO_STDOUT1 # Print logs to screen export ASCEND_GLOBAL_LOG_LEVEL0 # Log level is debug4. Core Workflow Introduction4.1 Single Model Offline Compilation and ExecutionUseaclgrphBuildInitializeto initialize compilation environmentBuildGraphand generate offline model viaaclgrphBuildModelSaveomfile usingaclgrphSaveModelExecute offline model viaaclmdlLoadFromFile,aclmdlExecute4.2 Bundle Offline Compilation and ExecutionOrganize Bundle using multipleGraphBuild Bundle model at once viaaclgrphBundleBuildModelSavebundle_sample.omusingaclgrphBundleSaveModelLoad Bundle viaaclmdlBundleLoadFromFileand execute sub-models sequentially【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表