﻿# CuTe coalesce: preserve the index function without assuming the same mode hierarchy

Understand CuTe coalesce guarantees, statically known unit modes, and profile-directed simplification before relying on hierarchical indexing after a layout transformation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-cute-coalesce-mapping-versus-mode-hierarchy/
Language: en

## Separate address mapping from structural shape

The [CuTe layout-algebra tutorial](https://docs.nvidia.com/cutlass/4.5.0/media/docs/cpp/cute/02_layout_algebra.html) presents `coalesce` as simplification of a layout viewed as an integer-to-integer function. Its documented guarantees preserve domain size and mapped results for linear coordinates while allowing the mode structure to simplify. This is an algebraic operation on a descriptor, not a kernel that rearranges stored tensor values into a new physical buffer.

## Recognize mergeable modes

The [versioned layout implementation](https://raw.githubusercontent.com/NVIDIA/cutlass/v4.5.0/include/cute/layout.hpp) implements coalescing through shape and stride structure. Statically known unit modes and compatible contiguous modes offer simplification opportunities. A dynamic value that happens to equal a unit extent does not necessarily permit the same type-level simplification, because tuple structure is determined at compilation. Consequently, different printed layouts can describe equivalent mappings without providing an identical compile-time rank or nested shape to generic code.

## Preserve a hierarchy when it has meaning

The algebra tutorial also describes profile-directed coalescing for selected sublayouts. This is useful when an algorithm expects an outer grouping, such as separate tile and residual modes, even though inner address calculations can simplify. The [layout tutorial](https://docs.nvidia.com/cutlass/4.5.0/media/docs/cpp/cute/01_layout.html) explains hierarchical access. Choose the transformation against the consumer's structural contract rather than assuming that preserving a flat enumeration makes all previous hierarchical coordinate expressions valid unchanged.

## Diagnose a generic helper regression

Imagine a helper that coalesces every incoming layout and then extracts a nested mode using a previously fixed path. A mapping-level test can pass while that structural assumption fails or selects another grouping. Test the promised property directly: compare mapped offsets for the supported coordinate form and separately inspect the hierarchy consumed by later code. This distinguishes algebraic equivalence from interface equivalence without claiming that fewer displayed modes always produce a faster compiled kernel.

## Verify semantics before reporting simplification

Record the original descriptor, transformed descriptor, supported coordinates, required grouping, and generated-code measurements. Guides to [tensor strides](/journal/tensor-strides-transpose-contiguous/) and [tensor axes](/journal/tensor-axes-batch-sequence-hidden/) provide context. Use small enumerated layouts to establish mapping behavior before benchmarking. A successful simplification retains the properties the algorithm needs; a shorter printed descriptor is evidence of a structural change, not proof of preserved nested indexing or a measured improvement in GPU execution.
