cute Internal Tensor slicing #1683
-
Consider the simple 2x10 tensor below auto t = cute::make_counting_tensor(cute::make_layout(cute::make_shape(2, 10), cute::LayoutRight{})); ArithTuple_0 o (2,10):(10,_1):
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19 I want to extract the below 2x4 sub-tensor using machinery that cute provides. 5 6 7 8
15 16 17 18 Unfortunately, even after reading the documentation on tensors and layout algebra, I am unable to do so. Rather, I use the below manual method. auto t_2x4 = cute::make_tensor(t.data() + 5, cute::make_shape(2, 4), cute::make_stride(10, 1)); QuestionMore generally, can you assist with a simple code example using cute (composition, divide, etc.) operations for arbitrary tensor slicing like above? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
We have never had the need for arbitrary tensor slicing and, more generally, find code that does use slicing like the above error prone and less generalizable. CuTe is designed for "regular" tilings, permutations, and slices rather than irregular and unaligned patterns like your example. If you really want to shoehorn this, you could write Tensor t = make_tensor(counting_iterator<int>(0), make_layout(make_shape(2, 10), LayoutRight{}));
// Tiler to extract a regular subtensor
Tensor t_2x8 = composition(t, make_tile(Layout<_2,_1>{}, Layout<Shape<_4,_2>, Stride<_1,_5>>{}));
// The second portion of the 4x2 multimode
Tensor t_2x4 = t_2x8(_, make_coord(_,1));
print_tensor(t_2x4); but that's pretty ugly. |
Beta Was this translation helpful? Give feedback.
We have never had the need for arbitrary tensor slicing and, more generally, find code that does use slicing like the above error prone and less generalizable. CuTe is designed for "regular" tilings, permutations, and slices rather than irregular and unaligned patterns like your example.
If you really want to shoehorn this, you could write
but that's pr…