SPA 5.0:
SETLMEMBASE
Ra
{&req_6}
{&rdN}
{?sched}
;
// Ra is a 64 bit vector2 register
SETLMEMBASE allows a thread to modify the base address of its local memory backing store so that the local memory low/high and the CRS region can be switched to another location in memory. The base of local memory is a per warp state that is shared by all the threads in the warp. If multiple threads execute SETLMEMBASE operation within a warp, HW arbitrarily chooses one thread as the "last" writer.
This instruction updates per warp [WARP].LMEMBASE state (in the warpLocalBase_t. structure).
In order to guard against reordered accesses to [WARP].LMEMBASE by LDL/STL/LD-to-local/ST-to-global ops, either before or after SETLMEMBASE, software should always put an ?OFF_DECK_DRAIN on this op. E.g.:
SETLMEMBASE R0 ?OFF_DECK_DRAIN ;
The useManagedBasePtr flag specifies if per warp local memory base pointer is managed by software (via the warpLocalBasePtr field) or a default hardware generated (controlled by class methods) address is to be used as warp local base (in which case warpLocalBasePtr field is ignored).
SOFTWARE NOTE: HW will enforce memory ordering guarantees between local and global memory accesses and SETLMEMBASE, however, HW will not enforce cache coherence across a SETLMEMBASE instruction. It is generally recommended that during a SETLMEMBASE operation, SW ensures the warp's call return stack is empty and all its local memory entries in L1 have been invalidated during a SETLMEMBASE operation.
In addition, if SETLMEMBASE be used outside the trap handler, it must be used when no live local data exists, (such as at CTA launch): Prior to a SETLMEMBASE that is used outside the trap handler, a trap could be taken just before the SETLMEMBASE instruction. Since SW cannot guarantee that the L1 entries for that warp are all invalidated anymore, this can then corrupt data after the SETLMEMBASE executes.
The per warp useManagedBasePtr flag is reset only on engine reset and context reset. It is the responsibility of SW to switch the local memory base pointer to the default class based allocation before the warp exits.
Reverting to the default (hardware managed) backing store is straightforward:
SETLMEMBASE Rz;
SETLMEMBASE R2;