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 asdst; the same restriction applies to slices and views on such tiles.PSUM cannot be used with
scalar_storeeither. Usenki.isa.tensor_copy()to copy a stored value from SBUF to PSUM.Like
nki.isa.scalar_load(), this acceptsnl.int64as well asnl.int32andnl.uint32.dstmust have the same dtype asvalue. A 32-bit scalar cannot be stored into annl.int64tile, nor a 64-bit scalar into annl.int32one, so store at the scalar’s own width.valuemust be aNkiScalar.dstmust name exactly one element, assrcmust fornki.isa.scalar_load(), so a 1x1 slice such astile[0:1, 2:3]works and a wider destination will be rejected at this call.Always pass
engine; storing without it is discouraged. Withoutenginethe store is replicated onto every sequencer the kernel uses: each one writes the same value todst, the next instruction that readsdstwaits for all of those writes, andvaluehas to be available on every engine, so a value bound to one sequencer is rejected.With
engineonly that sequencer writesdst, andvalueonly 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.uint32ornl.int64, matching the dtype ofvalue.value – A
NkiScalarto store.engine – the sequencer to run the store on, e.g.
nisa.engine.sync. Defaults toNone, 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