当前位置: 首页 > news >正文

CANN运行时设备到主机同步内存复制示例

3_d2h_sync_memory_copy

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

Description

This sample demonstrates synchronous memory copy from Device to Host using theaclrtMemcpyAPI for data transfer.

Product Support

This sample supports the following products:

ProductSupported
Ascend 950PR/Ascend 950DT
Atlas A3 Training Series Products/Atlas A3 Inference Series Products
Atlas A2 Training Series Products/Atlas A2 Inference Series Products

Build and Run

  1. Download the sample code to an environment where CANN software is installed, and switch to the sample directory.
cd ${git_clone_path}/example/1_basic_features/memory/3_d2h_sync_memory_copy
  1. Set environment variables.
# Replace ${install_root} with the CANN installation root directory, which is installed in `/usr/local/Ascend` by default source ${install_root}/cann/set_env.sh export ASCEND_INSTALL_PATH=${install_root}/cann # Set SOC_VERSION and ASCENDC_CMAKE_DIR # -SOC_VERSION: The model of the Ascend AI processor, such as Ascend910_9362, Ascend910B2, and so on # -ASCENDC_CMAKE_DIR: The sample involves calling AscendC operators. Configure the AscendC compiler ascendc.cmake path, such as /usr/local/Ascend/cann/x86_64-linux/tikcpp/ascendc_kernel_cmake source ${git_clone_path}/example/set_sample_env.sh
  1. Run the following command to execute the sample.
bash run.sh

CANN RUNTIME API

The key functionality points and their corresponding APIs in this sample are as follows:

  • Initialization
    • CallaclInitto perform initialization configuration.
    • CallaclFinalizeto perform deinitialization.
  • Device Management
    • CallaclrtSetDeviceto specify the Device for computation.
    • CallaclrtResetDeviceForceto forcibly reset the current Device and reclaim Device resources.
  • Stream Management
    • CallaclrtCreateStreamto create a Stream.
    • CallaclrtDestroyStreamForceto forcibly destroy a Stream and discard all tasks.
  • Memory Management
    • CallaclrtMallocHostto allocate memory on the Host.
    • CallaclrtMallocto allocate memory on the Device.
    • CallaclrtFreeHostto free memory on the Host.
    • CallaclrtFreeto free memory on the Device.
  • Data Transfer
    • CallaclrtMemcpyto implement Device-to-Host data transfer using memory copy.

Sample Output

[INFO] Allocate memory on the host memory 0x... successfully [INFO] Allocate memory on the device memory 0x... successfully [INFO] Write the data 123 to the virtual memory 0x... [INFO] Copy memory from memory 0x... to memory 0x... [INFO] Destination data: 123 CANN Version: 1.0.0, TimeStamp: ... Source data: 123

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

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

http://www.gsyq.cn/news/1583131.html

相关文章:

  • Bernini-R-GGUF-ComfyUI核心功能解析:为什么它是视频创作者的终极工具
  • 快速上手hspec:10分钟学会Haskell BDD测试框架 [特殊字符]
  • 如何3分钟上手vite-vue3-chrome-extension-v3?从安装到第一个扩展的完整指南
  • CANN/catlass优化矩阵乘法示例
  • JoyAI-Image-Edit-Plus-Diffusers核心功能解析:Diffusers库的增强版图像编辑神器
  • Ngx-restangular 测试策略:单元测试和集成测试完整指南
  • 如何用Gemma-4-26B-A4B-StyleTune提升创作质量?新手必看的AI写作指南 [特殊字符]
  • Bernini-R-GGUF-ComfyUI安装教程:5分钟快速部署AI视频生成环境
  • FreeOpcUa在实际项目中的应用案例:工业自动化系统的集成经验
  • Agora-Flutter-SDK高级功能实战:美颜、虚拟背景与空间音频实现
  • The Lightmapper对比分析:与其他Blender光照贴图插件的优劣比较
  • XRCarouselView源码解析:理解iOS轮播控件的核心实现原理
  • 10个CatSniffer实用技巧:从基础嗅探到高级攻击的完整教程
  • Continuum部署指南:从GitHub Releases到Discoverium的应用分发
  • sniffer源码解析:Go语言实现高性能网络流量捕获的关键技术
  • JoyAI-VL-Interaction-Preview技术架构深度解析:8B规模视觉优先模型的设计哲学
  • Haskell测试框架hspec:为什么它是现代Haskell开发的必备工具?[特殊字符]
  • TensorFlow Data Validation 与Apache Beam集成:大规模数据验证的完整解决方案
  • 提升laravel-money性能:处理大量货币数据的优化技巧
  • Pinia状态管理在vite-vue3-chrome-extension-v3中的终极指南:5个技巧让组件通信不再头疼
  • HalfStyle插件扩展开发指南:构建自定义字符分割插件
  • Easy-PHP:从零构建高性能轻量级PHP框架的完整指南 [特殊字符]
  • 如何快速上手cssplot:从安装到创建第一个柱状图的完整指南
  • CANN/catlass GEMM内核开发详解
  • Javinizer元数据聚合策略:多源数据合并与优先级设置技巧
  • 3大实战技巧:深度掌握TRL模型微调的核心价值
  • 3步搞定OrcaSlicer安装配置:新手快速上手3D打印切片终极指南
  • 开发者必看:Sing-Guard-2b API接口详解与集成示例
  • Super Productivity容器化部署实战:构建企业级时间管理系统的技术架构解析
  • 950基础矩阵乘法TLA示例