This document is relevant for: Trn2, Trn3

nki.isa.scalar_store#

nki.isa.scalar_store(dst: NkiTensor, value: NkiScalar, engine=None) → None[source]#

Store a scalar value to a 1x1 tensor in memory.

Scalar stores operate on internal tiles in SBUF and HBM. You cannot use kernel input or output tensors with this API. For an output tile, store the scalar in an internal tile and then use nki.isa.dma_copy() to copy the result to the output tensor. Kernel arguments and returned tensors cannot be used directly as dst; the same restriction applies to slices and views on such tiles.

PSUM cannot be used with scalar_store either. Use nki.isa.tensor_copy() to copy a stored value from SBUF to PSUM.

Like nki.isa.scalar_load(), this accepts nl.int64 as well as nl.int32 and nl.uint32.

dst must have the same dtype as value. A 32-bit scalar cannot be stored into an nl.int64 tile, nor a 64-bit scalar into an nl.int32 one, so store at the scalar’s own width.

value must be a NkiScalar.

dst must name exactly one element, as src must for nki.isa.scalar_load(), so a 1x1 slice such as tile[0:1, 2:3] works and a wider destination will be rejected at this call.

Always pass engine; storing without it is discouraged. Without engine the store is replicated onto every sequencer the kernel uses: each one writes the same value to dst, the next instruction that reads dst waits for all of those writes, and value has to be available on every engine, so a value bound to one sequencer is rejected.

With engine only that sequencer writes dst, and value only has to exist there: it may be bound to that engine or available on all of them, and a value bound to a different engine is an error.

Parameters:
  • dst – An internal SBUF or HBM tile naming one element, with dtype nl.int32, nl.uint32 or nl.int64, matching the dtype of value.

  • value – A NkiScalar to store.

  • engine – the sequencer to run the store on, e.g. nisa.engine.sync. Defaults to None, meaning every engine, which is discouraged; see above.

Example:

out_buf = nl.ndarray((1, 1), dtype=nl.int32, buffer=nl.sbuf)
nisa.scalar_store(out_buf, result, engine=nisa.engine.sync)

This document is relevant for: Trn2, Trn3