nki.isa.rng#
- nki.isa.rng(dst, engine=engine.unknown, name=None)[source]#
Generate pseudo random numbers using the Vector or GpSimd Engine.
This instruction generates 32 random bits per element and writes them to the destination tensor. Depending on the size of the dtype, the instruction truncates each 32-bit random value to the specified data type, taking the least significant bits.
Example use case: To generate random FP32 numbers between 0.0 and 1.0, follow the Rng instruction with a normalization instruction (e.g., write 16 random bits as UINT16, then divide by (2^16-1) to get a random FP32 number between 0.0 and 1.0).
Memory types.
The output
dsttile can be in SBUF or PSUM.Data types.
The output
dsttile must be an integer type: int8, int16, int32, uint8, uint16, or uint32.Tile size.
The partition dimension size of
dstmust not exceed 128. The number of elements per partition ofdstmust not exceed the physical size of each SBUF/PSUM partition.Constraints.
Supported arch versions: NeuronCore-v2+.
Supported engines: NeuronCore-v2: Vector. NeuronCore-v3+: GpSimd, Vector.
Since GpSimd Engine cannot access PSUM,
dstmust be in SBUF when using GpSimd Engine.
- Parameters:
dst – the destination tensor to write random values to
engine – specify which engine to use:
nki.isa.vector_engine,nki.isa.gpsimd_engine, ornki.isa.unknown_engine(default, the best engine will be selected)