warp.sparse.BsrTripletMap#

class warp.sparse.BsrTripletMap(capacity=0, device=None)[source]#

Reusable mapping from COO triplets to an existing BSR topology.

Build this mapping with bsr_set_from_triplets() through its build_mapping argument, then update the matrix values with bsr_set_from_mapped_values(). Every map caches a triplet-to-block lookup for atomic accumulation and block-grouped triplet indices for atomic-free gather reduction.

Constructing a map preallocates its storage. Passing it as build_mapping then rebuilds it in place, without allocating as long as its capacity covers the triplet count. This allows, for instance, allocating the storage outside of a CUDA graph capture and building the map within it, so that the map does not depend on the graph’s lifetime.

The map is built without host synchronization, so its arrays are sized by the triplet count, which is an upper bound on the destination block count. The actual block count is read on the device from the destination offsets.

The destination matrix topology must remain unchanged while the map is in use. Its numerical values may be replaced freely.

Parameters:
  • capacity (int) – Number of triplets to preallocate storage for. The storage grows as needed when the map is built for more triplets.

  • device (warp.DeviceLike) – Device on which to allocate the storage.

Methods

validate(dest)

Raise if dest dimensions or topology storage differ from those recorded by this map.

Attributes

capacity

Number of triplets the map can be built for without reallocating its storage.

device

Device on which the map storage is allocated.

triplet_count

Number of input triplets the map was last built for.

triplet_count#

Number of input triplets the map was last built for.

property device: Device[source]#

Device on which the map storage is allocated.

property capacity: int[source]#

Number of triplets the map can be built for without reallocating its storage.

validate(dest)[source]#

Raise if dest dimensions or topology storage differ from those recorded by this map.

This check compares dimensions and array identities only. It cannot detect topology data modified in place.

Parameters:

dest (BsrMatrix)

Return type:

None