Skip to content

Tiling

Tiling action for MLIR loop transformations.

This module implements the tiling transformation action, which applies loop tiling to operations with configurable tile sizes.

Tiling(parameters, state=None, /, *, process_params=True, **extras)

Bases: Action

Class representing Tiling action

Source code in mlir_rl_artifact/actions/tiling.py
def __init__(
    self,
    parameters: list[int],
    state: Optional[OperationState] = None,
    /, *,
    process_params: bool = True,
    **extras
):
    if state and process_params:
        # Case where parameters need processing

        tile_sizes = []
        for param, loop in zip(parameters, state.operation_features.nested_loops):
            if param == 0:
                tile_sizes.append(0)
            else:
                ts = 2 ** (param - 1)
                assert loop.upper_bound % ts == 0 and loop.upper_bound != ts, \
                    f'Tiling parameter {param} is not a factor of loop upper bound {loop.upper_bound}'
                tile_sizes.append(ts)
        parameters = tile_sizes
    super().__init__(parameters, state, **extras)

__get_tiles_count(ub) staticmethod

Get the number of tiling candidates for a given loop upper bound.

Parameters:

Name Type Description Default
ub int

The loop upper bound.

required

Returns:

Type Description
int

The number of candidates.

Source code in mlir_rl_artifact/actions/tiling.py
@staticmethod
def __get_tiles_count(ub: int) -> int:
    """Get the number of tiling candidates for a given loop upper bound.

    Args:
        ub: The loop upper bound.

    Returns:
        The number of candidates.
    """
    for i in range(Config().num_tile_sizes):
        ts = 2 ** i
        if ub % ts != 0 or ub == ts:
            return i + 1
    return Config().num_tile_sizes + 1