
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),仅供参考