当前位置: 首页 > 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.jsqmd.com/news/1071181/

相关文章:

  • Gemma-4-31B-StyleTune vs 传统微调:终极VRAM需求对比分析
  • 5个实战项目:用Deep Learning Illustrated代码构建深度学习应用
  • Open3D (C++) 三维轨迹点的等间距三次样条平滑与插值(间距可控)
  • Sapiens2-Pose-0.4B vs 其他姿态估计模型:为什么它是最佳选择?[特殊字符]
  • CANN ops-nn ApplyAdagradD算子
  • Edge-TTS终极指南:专业诊断与高效解决语音合成错误的完整方案
  • CANN/PTO-ISA SET_QUANT_VECTOR指令
  • 如何3分钟上手vite-vue3-chrome-extension-v3?从安装到第一个扩展的完整指南
  • C# vs C++:垃圾回收的“世纪对决“:90%的开发者都选错了!
  • Bernini-R vs 其他视频AI工具:为什么选择GGUF版本的ComfyUI集成方案?[特殊字符]
  • Playground开发者必读:贡献代码与参与社区的最佳实践指南 [特殊字符]
  • CANN/catlass优化矩阵乘法示例
  • 10分钟掌握vite-vue3-chrome-extension-v3国际化:多语言扩展从零开始
  • 快速上手hspec:10分钟学会Haskell BDD测试框架 [特殊字符]
  • JoyAI-Image-Edit-Plus-Diffusers核心功能解析:Diffusers库的增强版图像编辑神器
  • 70款抖音快手封面边框模板设计动漫画电影视解说短剧视频透明图文模版
  • Ngx-restangular 测试策略:单元测试和集成测试完整指南
  • 实战教程:使用 Sapiens2-Pose-0.4B 进行实时人体姿态检测
  • 终极指南:5分钟解决oh-my-posh终端美化所有问题
  • 如何用Gemma-4-26B-A4B-StyleTune提升创作质量?新手必看的AI写作指南 [特殊字符]
  • FastContext-1.0-4B-RL性能评测:如何在SWE-bench上实现5.5%准确率提升
  • Laravel Search String快速入门:5个简单步骤实现智能搜索
  • Caesonia故障排除:OpenBSD邮件服务常见问题解决方案和调试方法
  • Serpl部署与分发:如何打包和发布你的自定义版本到各大平台
  • 终极TypeScript+Vue3开发体验:vite-vue3-chrome-extension-v3类型安全实践指南
  • REL源码解析:深入理解Golang ORM的设计哲学与架构实现 [特殊字符]
  • Sing-Guard-2b核心功能揭秘:6大安全场景全覆盖,动态策略推理如何实现?
  • Bernini-R-GGUF-ComfyUI安装教程:5分钟快速部署AI视频生成环境
  • ClothSimulation在游戏开发中的应用:实时布料模拟实战
  • FreeOpcUa在实际项目中的应用案例:工业自动化系统的集成经验