当前位置: 首页 > 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.gsyq.cn/news/1583140.html

相关文章:

  • 性能优化秘籍:TP=2 vs TP=4配置对比,找到最佳GPU资源利用方案
  • Gemma-4-31B-StyleTune vs 传统微调:终极VRAM需求对比分析
  • CANN ops-nn ApplyAdagradD算子
  • 98个公共Tracker完整指南:彻底解决BT下载卡顿难题
  • TruecallerJS实战应用:10个真实场景下的电话号码查询解决方案
  • 5个实战项目:用Deep Learning Illustrated代码构建深度学习应用
  • ComfyUI-LTXVideo完整指南:如何在ComfyUI中轻松生成高质量AI视频
  • CANN运行时设备到主机同步内存复制示例
  • 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框架的完整指南 [特殊字符]