TECHNOLOGY

Triton masked memory: a protected load and a protected store are separate

In this article
THE QUICK TAKE

A load mask suppresses selected reads; a store mask suppresses selected writes, and masked values still need a defined arithmetic role.

Separate address validity from arithmetic

A GPU tile can contain more lanes than the logical tensor has elements. Triton’s vector-add tutorial demonstrates a mask for the incomplete tail. That mask is a condition attached to a memory operation, not a general promise that all later operations automatically become safe. Track which pointer positions are valid and which arithmetic values are defined before combining the tile with reductions or additional memory accesses.

Give masked reads a deliberate fallback

The current load API states that a false mask suppresses the corresponding read. Its other argument supplies the returned value for that position; omitting it can leave that value undefined. Choose a fallback according to the subsequent computation rather than treating every masked position as a harmless zero. A value excluded from an input read can still influence arithmetic if later code includes it in a reduction or address calculation.

Guard writes independently

The store API applies its own mask to output pointers. A correctly masked input load does not protect an unmasked output store. Likewise, input and output may have different logical boundaries in a more complex operation. Inspect the write condition at the actual store site, including any broadcasting used to create the pointer tensor, rather than assuming that an earlier mask implicitly covers every output address.

Preserve the installed API contract

Current pointer-based load and store signatures differ from examples written for older block-pointer interfaces. Verify supported arguments in the installed Triton release before combining snippets from different tutorials. A historical boundary-check option should not be inserted into a current call just because its name appears to express the desired safety property. The actual operation must receive a valid pointer representation and the masking mechanism supported by that implementation.

Test the incomplete tile on purpose

Include a logical length that does not fill the selected tile, and check surrounding output storage as well as valid values. Use a trusted reference operation and suitable memory diagnostics; a successful divisible example cannot reveal every tail error. The guides to tensor padding and kernel address arithmetic explain adjacent ideas. Triton’s specific boundary is explicit: read suppression, fallback arithmetic and write suppression are separate responsibilities in a custom kernel.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles