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

cann/runtime随机数生成示例

Launch Random Number Sample

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

Overview

This sample demonstrates how to use CANN RuntimeaclrtRandomNumAsyncAPI to generate random numbers. Supports multiple random number distribution types and data types, used to meet random number generation requirements in different scenarios.

Product Support

This sample has the following support status on the following products:

ProductSupported
Atlas A3 training series products/Atlas A3 inference series productsYes
Atlas A2 training series products/Atlas A2 inference series productsYes

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 # 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.
  • Stream Management
    • Call aclrtCreateStream interface to create Stream.
    • Call aclrtSynchronizeStream interface to block waiting for Stream task execution completion.
  • Memory Management
    • Call aclrtMalloc interface to allocate Device output buffer and random number counter buffer.
    • Call aclrtFree interface to release Device memory.
  • Data Transfer
    • Call aclrtMemcpy interface to copy generated random numbers back to Host side for checking.
  • Random Number Task Execution
    • Call aclrtRandomNumAsync interface to asynchronously dispatch random number task, generating uniform, normal distribution results and dropout bitmask.

Core API

aclrtRandomNumAsync

aclError aclrtRandomNumAsync( const aclrtRandomNumTaskInfo* taskInfo, // Random number task information aclrtStream stream, // Stream void* reserve // Reserved field );

aclrtRandomNumTaskInfo Structure

typedef struct { aclDataType dataType; aclrtRandomNumFuncParaInfo randomNumFuncParaInfo; void *randomParaAddr; void *randomResultAddr; void *randomCounterAddr; aclrtRandomParaInfo randomSeed; aclrtRandomParaInfo randomNum; uint8_t rsv[10]; } aclrtRandomNumTaskInfo;

Random Number Generation Types

1. Uniform Distribution

Supported data types:

  • Floating-point types:ACL_FLOAT,ACL_FLOAT16,ACL_BF16
  • Integer types:ACL_INT32,ACL_INT64,ACL_UINT32,ACL_UINT64

Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_UNIFORM_DIS

Parameter description:

  • min: Minimum value
  • max: Maximum value

2. Normal Distribution

Supported data types:

  • ACL_FLOAT,ACL_FLOAT16,ACL_BF16

Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_NORMAL_DIS

Parameter description:

  • mean: Mean value
  • stddev: Standard deviation

3. Truncated Normal Distribution

Supported data types:

  • ACL_FLOAT,ACL_FLOAT16,ACL_BF16

Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_TRUNCATED_NORMAL_DIS

Parameter description:

  • mean: Mean value
  • stddev: Standard deviation

4. Dropout Bitmask Generation

Used to generate bit mask for random dropout (Dropout), supports generation by ratio.

Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_DROPOUT_BITMASK

Parameter description:

  • ratio: Dropout ratio (supported data typesACL_FLOAT,ACL_FLOAT16,ACL_BF16)

Random Number Algorithms

AlgorithmFeatures
Philox4_32_10- Supports all distribution types
- Counter is 128bit, requires 16Byte storage

Memory Requirements

  1. Counter Memory: Fixed 16 bytes, any byte-aligned address is acceptable
  2. Output Memory: Dynamically allocated based on data type and random number count
  3. Parameter Memory: Mean, standard deviation, range, and other parameters can use immediate values or device memory

Known Issues

None

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

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

http://www.jsqmd.com/news/1071192/

相关文章:

  • 002 使用单片机实现的逻辑分析仪——扩展篇
  • find、stat、touch、tree、scp、crontab指令相关应用
  • 5个实用技巧:用TimetableLayout打造专业级Android时间表应用
  • 性能优化秘籍:TP=2 vs TP=4配置对比,找到最佳GPU资源利用方案
  • TruecallerJS API深度解析:如何构建专业的电话号码验证系统
  • 解锁Java生态宝藏:从零构建企业级知识图谱的技术架构深度剖析
  • 98个公共Tracker完整指南:彻底解决BT下载卡顿难题
  • Bernini-R-GGUF-ComfyUI核心功能解析:为什么它是视频创作者的终极工具
  • ComfyUI-LTXVideo完整指南:如何在ComfyUI中轻松生成高质量AI视频
  • TruecallerJS实战应用:10个真实场景下的电话号码查询解决方案
  • CANN运行时设备到主机同步内存复制示例
  • 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终端美化所有问题