cann/runtime随机数生成示例

发布时间:2026/11/15 1:55:59
cann/runtime随机数生成示例 Launch Random Number Sample【免费下载链接】runtime本项目提供CANN运行时组件和维测功能组件。项目地址: https://gitcode.com/cann/runtimeOverviewThis 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 SupportThis sample has the following support status on the following products:ProductSupportedAtlas A3 training series products/Atlas A3 inference series productsYesAtlas A2 training series products/Atlas A2 inference series productsYesBuild and RunFor 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.shCANN RUNTIME APIKey features and interfaces in this sample:InitializationCall aclInit interface to initialize AscendCL configuration.Call aclFinalize interface to deinitialize AscendCL.Device ManagementCall aclrtSetDevice interface to specify Device for computation.Call aclrtResetDeviceForce interface to forcibly reset current computation Device and reclaim Device resources.Stream ManagementCall aclrtCreateStream interface to create Stream.Call aclrtSynchronizeStream interface to block waiting for Stream task execution completion.Memory ManagementCall aclrtMalloc interface to allocate Device output buffer and random number counter buffer.Call aclrtFree interface to release Device memory.Data TransferCall aclrtMemcpy interface to copy generated random numbers back to Host side for checking.Random Number Task ExecutionCall aclrtRandomNumAsync interface to asynchronously dispatch random number task, generating uniform, normal distribution results and dropout bitmask.Core APIaclrtRandomNumAsyncaclError aclrtRandomNumAsync( const aclrtRandomNumTaskInfo* taskInfo, // Random number task information aclrtStream stream, // Stream void* reserve // Reserved field );aclrtRandomNumTaskInfo Structuretypedef struct { aclDataType dataType; aclrtRandomNumFuncParaInfo randomNumFuncParaInfo; void *randomParaAddr; void *randomResultAddr; void *randomCounterAddr; aclrtRandomParaInfo randomSeed; aclrtRandomParaInfo randomNum; uint8_t rsv[10]; } aclrtRandomNumTaskInfo;Random Number Generation Types1. Uniform DistributionSupported data types:Floating-point types:ACL_FLOAT,ACL_FLOAT16,ACL_BF16Integer types:ACL_INT32,ACL_INT64,ACL_UINT32,ACL_UINT64Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_UNIFORM_DISParameter description:min: Minimum valuemax: Maximum value2. Normal DistributionSupported data types:ACL_FLOAT,ACL_FLOAT16,ACL_BF16Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_NORMAL_DISParameter description:mean: Mean valuestddev: Standard deviation3. Truncated Normal DistributionSupported data types:ACL_FLOAT,ACL_FLOAT16,ACL_BF16Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_TRUNCATED_NORMAL_DISParameter description:mean: Mean valuestddev: Standard deviation4. Dropout Bitmask GenerationUsed to generate bit mask for random dropout (Dropout), supports generation by ratio.Function type identifier:ACL_RT_RANDOM_NUM_FUNC_TYPE_DROPOUT_BITMASKParameter description:ratio: Dropout ratio (supported data typesACL_FLOAT,ACL_FLOAT16,ACL_BF16)Random Number AlgorithmsAlgorithmFeaturesPhilox4_32_10- Supports all distribution types- Counter is 128bit, requires 16Byte storageMemory RequirementsCounter Memory: Fixed 16 bytes, any byte-aligned address is acceptableOutput Memory: Dynamically allocated based on data type and random number countParameter Memory: Mean, standard deviation, range, and other parameters can use immediate values or device memoryKnown IssuesNone【免费下载链接】runtime本项目提供CANN运行时组件和维测功能组件。项目地址: https://gitcode.com/cann/runtime创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询