7.6 KiB
7.6 KiB
In [ ]:
import cutlass
import cutlass.cute as cute
from cutlass.cute.runtime import from_dlpack, make_ptr
@cute.jit
def customized_layout():
def inner(c):
x, y = c
return x, y + 1
layout = cute.make_composed_layout(
inner, (1, 0), cute.make_identity_layout(shape=(8, 4))
)
print(layout)
cute.printf(layout(0))
customized_layout()In [ ]:
import torch
@cute.jit
def gather_tensor(
offset_tensor: cute.Tensor, data_ptr: cute.Pointer, shape: cute.Shape
):
def inner(c):
return offset_tensor[c]
gather_layout = cute.make_composed_layout(inner, 0, cute.make_layout(shape))
for i in cutlass.range_constexpr(cute.size(shape)):
cute.printf("%d -> %d", i, gather_layout(i))
# TODO: support in future
# gather_tensor = cute.make_tensor(data_ptr, gather_layout)
# cute.printf(gather_tensor[0])
shape = (16,)
offset_tensor = torch.randint(0, 256, shape, dtype=torch.int32)
data_tensor = torch.arange(0, 256, dtype=torch.int32)
gather_tensor(
from_dlpack(offset_tensor),
make_ptr(cutlass.Int32, data_tensor.data_ptr(), cute.AddressSpace.generic),
shape,
)