asc.experimental.asctile.gather
- asc.experimental.asctile.gather(src: GlobalTensor, offsets: Iterable[PlainValue | int], dim: int, index: LocalTensor, check_bounds: bool = True, num_indices: PlainValue | int | None = None, pad_value: PlainValue | int | float | None = None) LocalTensor
Gather subtensors from a global tensor at positions given by an index tensor.
For each index value
index[i], the subtensor ofsrclocated at[offsets[0], ..., offsets[dim-1], offsets[dim] + index[i]]is copied toresult[i]. The copied subtensor spans dimensionsdim+1, ..., src.rank-1ofsrc.The
indextensor must have an integer dtype (int8,int16,int32,int64).- Parameters:
src – The source global tensor to gather from.
offsets – The offsets into
srcfor dimensions0..dim. Must containdim + 1values.dim – The dimension of
srcused for indexing.index – The index tensor. Must be a rank-1 tensor in
UBwith an integer dtype.check_bounds – If True, out-of-bounds indices produce
pad_valueelements. If False, no bounds checking is performed and the caller must guarantee all indices are valid. Default is True.num_indices – The number of indices in
indexto process. If None, all elements ofindexare processed.pad_value – The value used to pad out-of-bounds indices and to align the last dimension of the result to 32 bytes. If not specified, 0 is used.
- Returns:
- A tensor with shape
[index.shape[0], src.shape[dim+1], ..., src.shape[src.rank-1]]and the same dtype as
src, located inUB. The last dimension is aligned to 32 bytes and padded withpad_value.
- A tensor with shape
- Return type:
- Raises:
TypeError – If
srcis not a GlobalTensor orindexis not a LocalTensorRuntimeError – If
indexdoes not have an integer dtype or is not located inUBValueError – If
offsetsdoes not containdim + 1values,dimis out of range forsrc.rank,indexis not rank 1, orsrchas a dynamic dimension afterdimNotImplementedError – If
dimis the last dimension ofsrc
Note
Dimensions
dim+1, ..., src.rank-1ofsrcmust be static.Examples
Read full rows by outermost dimension.
srchas shape [1024, 128] andtilehas shape [256, 128]:index = asctile.copy_in(index_gm, [0], [256]) tile = asctile.gather(src, [0], 0, index)
Read every other row. If the inputs have the following contents:
src = [[0, 1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23], [24, 25, 26, 27, 28, 29, 30, 31], ..., [248, 249, 250, 251, 252, 253, 254, 255]] # shape [32, 8] index = [0, 2, 4, 6, ..., 30]
Then
tile = asctile.gather(src, [0], 0, index)results in:tile = [[0, 1, 2, 3, 4, 5, 6, 7], [16, 17, 18, 19, 20, 21, 22, 23], ..., [240, 241, 242, 243, 244, 245, 246, 247]] # shape [16, 8]