1 /****************************************************************************** 2 * Copyright (c) Intel Corporation - All rights reserved. * 3 * This file is part of the LIBXSMM library. * 4 * * 5 * For information on the license, see the LICENSE file. * 6 * Further information: https://github.com/hfp/libxsmm/ * 7 * SPDX-License-Identifier: BSD-3-Clause * 8 ******************************************************************************/ 9 /* Alexander Heinecke, Hans Pabst (Intel Corp.) 10 ******************************************************************************/ 11 #ifndef LIBXSMM_RNG_H 12 #define LIBXSMM_RNG_H 13 14 #include "libxsmm_typedefs.h" 15 16 /** 17 * create a new external state for thread-save execution managed 18 * by the user. We do not provide a function for drawing the random numbers 19 * the user is supposed to call the LIBXSMM_INTRINSICS_MM512_RNG_EXTSTATE_PS 20 * or LIBXSMM_INTRINSICS_MM512_RNG_XOSHIRO128P_EXTSTATE_EPI32 intrinsic. 21 * */ 22 LIBXSMM_API unsigned int* libxsmm_rng_create_avx512_extstate(unsigned int/*uint32_t*/ seed); 23 24 /** free a previously created rng_avx512_extstate */ 25 LIBXSMM_API void libxsmm_rng_destroy_avx512_extstate(unsigned int* stateptr); 26 27 /** Set the seed of libxsmm_rng_* (similar to srand). */ 28 LIBXSMM_API void libxsmm_rng_set_seed(unsigned int/*uint32_t*/ seed); 29 30 /** 31 * This SP-RNG is using xoshiro128+ 1.0, work done by 32 * David Blackman and Sebastiano Vigna (vigna@acm.org). 33 * It is their best and fastest 32-bit generator for 34 * 32-bit floating-point numbers. They suggest to use 35 * its upper bits for floating-point generation, what 36 * we do here and generate numbers in [0,1(. 37 */ 38 LIBXSMM_API void libxsmm_rng_f32_seq(float* rngs, libxsmm_blasint count); 39 40 /** 41 * Returns a (pseudo-)random value based on rand/rand48 in the interval [0, n). 42 * This function compensates for an n, which is not a factor of RAND_MAX. 43 * Note: libxsmm_rng_set_seed must be used if one wishes to seed the generator. 44 */ 45 LIBXSMM_API unsigned int libxsmm_rng_u32(unsigned int n); 46 47 /** Sequence of random data based on libxsmm_rng_u32. */ 48 LIBXSMM_API void libxsmm_rng_seq(void* data, libxsmm_blasint nbytes); 49 50 /** 51 * Similar to libxsmm_rng_u32, but returns a DP-value in the interval [0, 1). 52 * Note: libxsmm_rng_set_seed must be used if one wishes to seed the generator. 53 */ 54 LIBXSMM_API double libxsmm_rng_f64(void); 55 56 #endif /* LIBXSMM_RNG_H */ 57 58