Data Movement#
This guide shows how to move tensor data between global memory, shared memory, and thread-local registers. The instruction determines the source and destination spaces, while tensor views select the values to transfer. All three instruction families take the destination first:
Instruction |
Operands |
Data movement |
|---|---|---|
|
|
Memory to the executing thread’s registers |
|
|
Registers to memory |
|
|
Register values within the same thread |
Register Copies and Initialization#
Inside this kernel, we can save loaded values before reusing registers
for another read. Insert the following statements after its global load:
saved = T.alloc_local((4, 1), "float32", layout="default")
T.cuda.tile.apply(T.ptx["mov.b32"], saved, registers.view(4, 1))
The view exposes four repeats, each ending in a single-register atom
(1,). The call copies the four words into saved. Later operations
can use that copy after registers has been overwritten.
A scalar source broadcasts to every repeat. For example, the following call initializes all four saved values to zero:
T.cuda.tile.apply(T.ptx["mov.b32"], saved, T.float32(0))
mov preserves the bits within the same thread. A numeric type change
uses cvt, covered in Arithmetic and Type Conversion. Transfers between threads use
shared memory or another communication instruction.
Cache qualifiers, predication, and destination preservation are described in the memory instruction reference and register move reference.