tvm_tirx.backend.cuda.runtime.locality_domain

Contents

tvm_tirx.backend.cuda.runtime.locality_domain#

CUDA locality domains: per-domain device memory and topology queries.

Some GPUs (e.g. Rubin) split their SMs and device memory into locality domains; an SM reads memory of its own domain faster than memory of another one. A tensor is placed in domain k by allocating it with the memory scope global.locality_domain.<k>. On a GPU with multiple locality domains:

from tvm_tirx.backend.cuda.runtime import locality_domain

dev = tvm_tirx.cuda(0)
for k in range(locality_domain.get_num_locality_domains(dev)):
    scope = locality_domain.locality_domain_scope(k)  # "global.locality_domain.<k>"
    x = tvm_tirx.runtime.empty((n,), "float32", dev, mem_scope=scope)
    assert locality_domain.get_locality_domain_id(x) == k

The query names and their semantics follow torch.cuda.green_contexts (get_num_locality_domains, is_localization_supported) and torch’s locality_domain_id. Each query wraps the tvm-ffi function runtime.cuda.<Name> of the same name, e.g. get_num_locality_domains is runtime.cuda.GetNumLocalityDomains.

Like cudaMalloc memory, a localized tensor is ready on every stream once it is allocated, and freeing it waits for the work on every stream of the device.

A kernel reads the domain of the SM it runs on with T.cuda.mov_sreg(32, "locality_domain_id") (PTX ISA 9.5) and can then work on the data of its own domain. Memory of any domain stays accessible from every SM; only the access speed differs. A device without locality domains, or with a CUDA build or driver older than 13.4, reports one domain: global.locality_domain.0 then behaves like global, and get_locality_domain_id returns None for its memory.

Functions#

get_num_locality_domains([device])

Return the number of locality domains of a CUDA device.

is_localization_supported([device])

Return whether memory can be localized on a CUDA device.

get_num_sms_per_locality_domain([device])

Return the number of SMs guaranteed to each locality domain of a CUDA device.

get_locality_domain_id(tensor)

Return the locality domain a CUDA tensor's memory belongs to.

locality_domain_scope(locality_domain_id)

Return the memory scope that places an allocation in a locality domain.