Skip to content

benchmarks.KernelBench.iree_compilation

Source: benchmarks/KernelBench/iree_compilation.py

benchmarks.KernelBench.iree_compilation

IREE Kernel Compilation Script using iree-turbine

This script automates the compilation of PyTorch models (defined in 'level' directories) into optimized IREE artifacts (.vmfb) for various configurable targets (e.g., NVIDIA GPUs, ARM CPUs, RISC-V CPUs).

It performs the following steps: 1. Parses command-line arguments for input, output, and report directories, as well as kernel levels and target names to compile for. 2. Discovers all '*.py' kernel files in the specified 'level' directories (e.g., third_party/KernelBench/KernelBench/level1). 3. For each kernel file, it dynamically loads the 'Model' class, 'get_init_inputs()', and 'get_inputs()'. 4. For each specified target: a. Determines the correct precision (e.g., torch.float16 or torch.float32) for the target. b. Instantiates the model and inputs in that precision. c. Exports the PyTorch model to Torch MLIR using iree.turbine.aot.export() and saves it as 'kernel.mlir'. d. Compiles 'kernel.mlir' to 'artifact.vmfb' by invoking 'iree-compile' with the target-specific flags. e. Dumps intermediate MLIR stages into a 'compilation_phases' subdirectory. 5. Saves compiled artifacts in a structured output directory (e.g., benchmark/KernelBench/results/level1/A100/kernel_name/artifact.vmfb). 6. Logs all operations to 'iree_compile.log' in the report directory. 7. Generates detailed 'iree_compile_report.json' and 'iree_compile_report.md' summaries in the report directory, including success percentages per-level, per-target, and overall.

compile_kernel_for_target(target_def, input_mlir_path, vmfb_path, mlir_dump_dir)

Invokes iree-compile for a specific target configuration.

Returns:

Type Description
tuple[bool, str | None]

(success: bool, error_message: Optional[str])

generate_reports(report, total_kernels_by_level, active_target_names, json_report_path, md_report_path, start_time, end_time)

Generates JSON and Markdown summary reports with detailed statistics. Returns the total number of failures.

load_kernel_module(kernel_file)

Dynamically loads a Python module from a given file path.

main()

Main execution function.

parse_arguments()

Parses command-line arguments.

setup_logging(log_file_path)

Configures logging to both file and console.