news 2026/6/24 6:13:29

CANN/runtime模型流切换示例

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/runtime模型流切换示例

2_model_switch

【免费下载链接】runtime本项目提供CANN运行时组件和维测功能组件。项目地址: https://gitcode.com/cann/runtime

Description

This sample demonstrates how to use aclmdlRIBuildBegin interface to create a model instance, and implements Stream jumping and Stream activation in tasks.

Product Support

Key interfaces in this sample have the following support status on different products:

InterfaceAtlas A3 training series products/Atlas A3 inference series productsAtlas A2 training series products/Atlas A2 inference series products
aclmdlRIBuildBeginYesYes
aclmdlRIBindStreamYesYes
aclmdlRIEndTaskYesYes
aclmdlRIBuildEndYesYes
aclmdlRIUnbindStreamYesYes
aclmdlRIExecuteAsyncYesYes
aclrtSwitchStreamNoYes
aclrtActiveStreamNoYes

Build and Run

For environment installation details and running details, see README in the example directory.

Run steps:

# Replace ${install_root} with CANN installation root directory, default installation at /usr/local/Ascend source ${install_root}/cann/set_env.sh export ASCEND_INSTALL_PATH=${install_root}/cann # Replace ${ascend_name} with Ascend AI processor model, obtained by checking Name field using npu-smi info and removing spaces, for example ascend910b3 export SOC_VERSION=${ascend_name} # Some samples involve calling AscendC operators, need to configure AscendC compiler ascendc.cmake path, for example ${install_root}/cann/aarch64-linux/tikcpp/ascendc_kernel_cmake # Find ascendc_kernel_cmake under CANN package installation path, for example find ./ -name ascendc_kernel_cmake, and replace ${cmake_path} with ascendc_kernel_cmake directory path export ASCENDC_CMAKE_DIR=${cmake_path} # Build and run bash run.sh

CANN RUNTIME API

Key features and interfaces in this sample:

  • Initialization
    • Call aclInit interface to initialize AscendCL configuration.
    • Call aclFinalize interface to deinitialize AscendCL.
  • Device Management
    • Call aclrtSetDevice interface to specify Device for computation.
    • Call aclrtResetDeviceForce interface to forcibly reset current computation Device and reclaim Device resources.
  • Context Management
    • Call aclrtCreateContext interface to create Context.
    • Call aclrtDestroyContext interface to destroy Context.
  • Stream Management
    • Call aclrtCreateStream interface to create Stream.
    • Call aclrtSynchronizeStream interface to block waiting for Stream task completion.
    • Call aclrtDestroyStreamForce interface to forcibly destroy Stream, discarding all tasks.
    • Call aclrtCreateStreamWithConfig interface to create Stream with special config.
    • Call aclrtSwitchStream interface to jump between Streams based on condition.
    • Call aclrtActiveStream interface to activate Stream.
  • Model Management
    • Call aclmdlRIBuildBegin interface to start building a model runtime instance.
    • Call aclmdlRIBindStream interface to bind model runtime instance to Stream.
    • Call aclmdlRIEndTask interface to mark task dispatch end.
    • Call aclmdlRIBuildEnd interface to finish building model runtime instance.
    • Call aclmdlRIUnbindStream interface to unbind model runtime instance from Stream.
    • Call aclmdlRIExecuteAsync interface to asynchronously execute model inference.
    • Call aclmdlRIDestroy interface to destroy model runtime instance.
  • Memory Management
    • Call aclrtMalloc interface to allocate Device memory.
    • Call aclrtFree interface to release Device memory.
  • Data Transfer
    • Call aclrtMemcpy interface to implement data transfer by memory copy.
    • Call aclrtMemcpyAsync interface to perform asynchronous memory copy.

Known Issues

None

【免费下载链接】runtime本项目提供CANN运行时组件和维测功能组件。项目地址: https://gitcode.com/cann/runtime

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/24 6:12:50

Javinizer元数据聚合策略:多源数据合并与优先级设置技巧

Javinizer元数据聚合策略:多源数据合并与优先级设置技巧 【免费下载链接】Javinizer (NSFW) Organize your local Japanese Adult Video (JAV) library 项目地址: https://gitcode.com/gh_mirrors/ja/Javinizer Javinizer是一款功能强大的日本成人视频库管理…

作者头像 李华
网站建设 2026/6/24 6:08:22

KeyDive实战案例:从Xiaomi到Samsung设备的DRM密钥提取全过程

KeyDive实战案例:从Xiaomi到Samsung设备的DRM密钥提取全过程 【免费下载链接】KeyDive Extract Widevine L3 keys from Android devices effortlessly, spanning multiple Android versions for DRM research and education. 项目地址: https://gitcode.com/gh_mi…

作者头像 李华
网站建设 2026/6/24 5:56:18

10分钟自主搭建零成本内网穿透:bore轻量级隧道实战指南

10分钟自主搭建零成本内网穿透:bore轻量级隧道实战指南 【免费下载链接】bore 🕳 bore is a simple CLI tool for making tunnels to localhost 项目地址: https://gitcode.com/gh_mirrors/bo/bore 还在为内网服务暴露烦恼?付费穿透工…

作者头像 李华
网站建设 2026/6/24 5:55:43

ER存档编辑器:3分钟掌握《艾尔登法环》游戏数据自由编辑

ER存档编辑器:3分钟掌握《艾尔登法环》游戏数据自由编辑 【免费下载链接】ER-Save-Editor Elden Ring Save Editor. Compatible with PC and Playstation saves. 项目地址: https://gitcode.com/GitHub_Trending/er/ER-Save-Editor 还在为《艾尔登法环》的存…

作者头像 李华