How nod-ai/iree-amd-aie works
Main Components
• Compiler Plugins:
• There is a “compiler” directory containing two key subdirectories (“plugins/preprocessing” and “plugins/target”). The preprocessing plugin (including the “XDNA-OPLIB” submodule) is responsible for any source transformations needed before further compilation, whereas the target plugins (such as AMD-AIE and AIEVec) handle the lowering and generation of code specific to the AMD AI Engine.
• Under “plugins/target/AMD-AIE” you see files for dialect definitions, transformation passes, and even test MLIR examples. This layer interacts with the IREE compiler infrastructure to generate target-specific IR (intermediate representation).
• Runtime Support:
• The “runtime” directory contains subdirectories (e.g., “runtime/src/iree-amd-aie”) that provide the runtime library for device execution. This includes driver implementations (like the xrt-lite drivers) that interface directly with the AMD hardware, as well as utility modules for runtime configuration and testing.
• This layer handles device-specific actions: hardware configuration, scheduling (e.g., via the AI Engine router and control packets), and communication between the compiled code and AMD NPUs.
• Build and Continuous Integration (CI) Infrastructure:
• The “build_tools” and “.github/workflows” directories house scripts and configurations (e.g., build scripts, CI pipelines, testing scripts) that automate build, test, and integration flows.
• The build_tools directory includes various shell and Python scripts that assist with building a distribution, compiling tests, and interfacing with external hardware/software (e.g., Peano/llvm-aie and Chess).
• Experimental and Delegation Components:
• The “experimental” folder includes experimental delegate kernels and example MLIR files. They are likely used to trial new approaches or extensions to the plugin’s functionality with AMD NPUs.
• Third-party and External Dependencies:
• The tree includes directories for “third_party” libraries (e.g., XRT and aie-rt) and even dedicated cmake modules for integrating with these external components.
• The README details external requirements, such as the xdna-driver, llvm-aie (Peano), and Chess installations, which are all critical for both compile-time and runtime environments.
Relationships and Interactions
• The Compiler Plugin Layer interacts directly with the core IREE compiler. It accepts MLIR modules and applies passes (preprocessing, dialect-specific rewriting, and lowering) before handing off final IR to the runtime.
• The Runtime Layer then utilizes the lowered IR to set up and invoke execution on AMD NPUs. The AIE runtime interacts with hardware drivers (such as those in xrt-lite) to deliver the final low-level control and data movement commands.
• The Build and CI layer (with scripts in “build_tools” and GitHub workflows) automates the overall process—from checking out submodules to invoking build & test scripts and packaging the plugin.
• External dependencies (xdna-driver, llvm-aie, and Chess) reside outside the repository but are integrated via build scripts and CMake configuration. They form part of the “environment layer” that the plugin expects in order to fully function.
Architectural Patterns and Design Principles
• Plugin/Extension Pattern: The integration into IREE is done via compilers’ “plugin” mechanism. The design separates target-independent (IREE core) from target-specific transformation (AMD-AIE plugins).
• Modularization: There is a clear separation into compilations stages (preprocessing vs. lowering) and into runtime drivers vs. supporting utility functions.
• CI/CD and Automated Build Integration: The existence of extensive CI scripts and build tools shows that repeatable builds, testing, and cross-platform integration (Linux, Windows, macOS) are top-level design concerns.