# Optimizer Optimizer is the main component responsible for performance. It is a collection of passes with the two most important purposes being optimizing tensor memory layouts and selecting optimal operation configurations. ## Prerequisites To use the optimizer: - A physical Tenstorrent device must be present on the machine - Build of `tt-mlir` must be with OpModel support enabled: ```bash cmake -G Ninja -B build -DTTMLIR_ENABLE_OPMODEL=ON ``` ## Basic Usage Optimizer is disabled by default. To enable it, use the `enable-optimizer` option: ```bash ttmlir-opt --ttir-to-ttnn-runtime-pipeline="enable-optimizer=true" input.mlir ``` ## Optimizer Options The optimizer provides additional configuration options: - **`optimization-level`** (default: `0`) - 0: Optimizer disabled, 1: Optimizer enabled without sharding, 2: Full optimization with sharding - Automatically sets `enable-optimizer` and `memory-layout-analysis-enabled` based on level - **`enable-optimizer`** (default: `false`) - Enables the optimizer pass - Must be set to `true` to use any other optimizer options - **`memory-layout-analysis-enabled`** (default: `true`) - Enables memory layout optimization - Shards tensors to maximize usage of fast L1 memory instead of DRAM - **`max-legal-layouts`** (default: `8`) - Maximum number of different layouts to generate for each operation during analysis - Higher values may provide better results but increase compile time ### Example ```bash # Enable optimizer with default settings ttmlir-opt --ttir-to-ttnn-runtime-pipeline="enable-optimizer=true memory-layout-analysis-enabled=true max-legal-layouts=8" input.mlir ``` ## Design Documentation For detailed information about the optimizer's architecture, algorithms, and implementation, see the [TTNN Optimizer Design Specification](./specs/ttnn-optimizer.md).