Skip to content
XilinxPublic

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

1,261 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AIEHLC

AIEHLC (AIE High-Level Compiler) compiles one C++ file -- a host main() plus a __global__ AIE kernel -- into an ELF that runs on an AMD Versal AI Engine array: VCK190 (AIE), VEK280 (AIE-ML), VEK385 (AIE2PS); bare metal or Linux.

Get started (setup guide): 1. with Vitis (full flow) · 2. without Vitis (open-source tools, reduced flow) · 3. developer setup (build aiehlc itself)

  • No DMA, routing or scheduling to write. The kernel says what each core computes and which block of each tensor it reads and writes (aie::load_buffer / aie::store_buffer, indexed by aie::program_id). The compiler derives the DMA buffer descriptors, stream-switch routing, ping-pong buffers, locks and launch schedule from those accesses.
  • CUDA-style host code. Allocate, launch with kernel<<<mesh>>>(...), check the result. The runtime loads a pre-built hardware design (PDI); no FPGA flow is involved.
  • Checked before the board. Out-of-tensor blocks, data used without being loaded, loops a DMA cannot stream and buffers that do not fit are build errors with a source line, not hangs.

Example: conv2d on 16 tiles

A 7x7 stride-2 int8 convolution (224 x 224 x 3 -> 112 x 112 x 64, the ResNet stem) on a 4 x 4 mesh: mesh row pid_h takes 28 output rows, mesh column pid_c 16 of the 64 output channels. This is the whole program:

#include "simpleconv2d_new_load.h"
__global__ void conv2d_spatial(aie::port<input_window_int8 *, aie::IFM, aie::shape<230, 230, 4>> win_a,
                               aie::port<input_window_int8 *, aie::WEIGHTS, aie::shape<64, 7, 7, 4>> win_b,
                               aie::port<output_window_int8 *, aie::OFM, aie::shape<112, 112, 64>> win_c) {
    const int KH = 7, KW = 7, S = 2, C = 4;
    const int oh_t = 7, ow_t = 28, oc_t = 16;
    const int ih_t = (oh_t - 1) * S + KH;
    const int iw_t = (ow_t - 1) * S + KW;
    const int oh_core = 112 / aie::num_programs(0);
    const int pid_h = aie::program_id(0);
    const int pid_c = aie::program_id(1);
    const int8_t *w = aie::load_buffer(win_b, {pid_c * oc_t, 0, 0, 0}, {oc_t, KH, KW, C});

    for (int i = 0; i < oh_core / oh_t; i++) {
        for (int j = 0; j < 112 / ow_t; j++) {
            const int oh0 = pid_h * oh_core + i * oh_t;
            const int ow0 = j * ow_t;
            const int8_t *x = aie::load_buffer(win_a, {oh0 * S, ow0 * S, 0}, {ih_t, iw_t, C});
            int8_t *y = aie::store_buffer(win_c, {oh0, ow0, pid_c * oc_t}, {oh_t, ow_t, oc_t});
            for (int oh = 0; oh < oh_t; oh++)
                for (int ow = 0; ow < ow_t; ow++)
                    for (int oc = 0; oc < oc_t; oc++) {
                        int acc = 0;
                        for (int kh = 0; kh < KH; kh++)
                            for (int kw = 0; kw < KW; kw++)
                                for (int c = 0; c < C; c++)
                                    acc += x[((oh * S + kh) * iw_t + ow * S + kw) * C + c] *
                                           w[((oc * KH + kh) * KW + kw) * C + c];
                        y[(oh * ow_t + ow) * oc_t + oc] = (int8_t)(acc > 127 ? 127 : acc < -128 ? -128 : acc);
                    }
            aie::release(win_a);
            aie::commit(win_c);
        }
    }
    aie::release(win_b);
}
int main() {
    const int in_n = INPUT_H_PAD * INPUT_W_PAD * INPUT_C_ALIGN, w_n = K * NUM_FILTERS, out_n = M * N;
    int8_t *input = (int8_t *)__Runtime_Alloc(in_n), *filter = (int8_t *)__Runtime_Alloc(w_n);
    int8_t *output = (int8_t *)__Runtime_Alloc(out_n);
    memset(output, 0, out_n);
    init_conv2d_test_data(input, filter);
    // kernel call to parallel compute in 4x4 tiles
    aieSetDevice(0);
    aieArray device;
    aieMesh mesh = device.partition({3, 6, 0, 6}, HW_ROWS, HW_COLS);
    conv2d_spatial<<<mesh>>>(input, filter, output, M, N, K);
    return 0;
}

The full file, simpleconv2dkernel_port_less.cc, also checks every output against a CPU convolution (PASS: 0 mismatches out of 802816 on the board); tutorial 1b walks through it line by line.

Quick start

After setup:

source script/setup.sh
source script/aiehlc.sh --aie-version 5 \
    --runtime-source-file ./example/tileprogram/ccode/simpleconv2dkernel_port_less.cc   # -> aout/main.elf

--aie-version: 1 VCK190, 2 VEK280, 5 VEK385. Running it on the simulator or a board: doc/setup.md; other platforms (PetaLinux, llvm-aie): doc/reference/build_and_run.md.

Learn

Start with What it teaches
tutorial/aieprogram The programming model by operator family (GEMM, conv2d, elementwise, reduction, data movement, indexing), then GEMM optimization step by step
tutorial/compilerinside One GEMM from 0.01 % to 85 % of peak, one source change per step, with the compiler IR at each level
tutorial/model Whole models on the AIE: ResNet18, yolov26, tiny SD UNet
doc/tutorial_aiegraph.md aiegraph: ONNX / PyTorch model -> int8 C, AIE-offloaded layers, board ELF
doc/tutorial_userkernel.md Plugging your own AIE kernel into one layer of a model
tutorial/hip2aie, tutorial/cuda2aie Bringing a HIP or CUDA GEMM to the AIE
tutorial/aiednn Writing a library ML kernel for AIEDNN
tutorial/tutorial.md The low-level driver API: one kernel loaded, routed and run by hand

How it works

architecture: 6 MLIR dialects

  1. Kernel analysis. The kernel runs once per core on x86; every load_buffer / store_buffer is recorded and fitted to base * program_id + step * loop index, which is a DMA pattern (broadcast along a mesh row or column, gather of each core's output).
  2. MLIR lowering, one concern per dialect: routing -> dmap (logical streams) -> dmaphop (physical tiles and paths) -> dfscheblueprint / dfschedule (buffer descriptors, locks, launch order) and routinghw (stream-switch connections).
  3. Code generation: host.cc (Arm), kernel.cc (each core) and routing.cc (switch setup); the AIE compiler builds the kernel, which is embedded in the host ELF.

Every stage with real IR: tutorial 1a, section 5; the passes: doc/tilinglinalg.md.

Supported

Devices Versal AI Core / AI Edge: AIE (--aie-version 1), AIE-ML (2), AIE2PS (5). Not Ryzen AI.
Platforms bare metal (APU, RPU), PetaLinux, the AIE simulator
Kernel compilers Synopsys xchesscc (default, with Vitis), llvm-aie (experimental)
I/O GMIO (DDR <-> array) with the pre-built PDIs in tutorial/hw; no PLIO
Operators end to end contraction (GEMM, conv2d); elementwise, reduction, data movement and indexing pass the kernel analysis, lowering in progress (status)
Not expressible data-dependent addressing (gather / scatter by runtime index)

Results

int8 GEMM, 7680 x 512 x 2560, 4 x 4 mesh 85.5 % of the array's int8 peak on a VEK385, bit-exact (gemm_plan.cc)
HIP / CUDA GEMM -> AIE 85.3 % (HIP MFMA) and 87.1 % (CUDA __dp4a) of peak with hip2aie / cuda2aie
Qwen3.5-9B, int4 weights, one VEK385 14.7 tok/s decode with speculative decoding, bare metal (src/APP/qwen)
conv2d stem over the control-packet plane 185 us per launch (conv2dstem)

At these sizes control often dominates a launch: a register write over AXI-MM costs ~372 ns, through a control packet ~2.9 ns (measured). More numbers: doc/reference/performance.md; a launch-time predictor that needs no board: src/costmodel.

Reference

Topic
Setup and building aiehlc doc/setup.md, doc/build.md
Build and run: platforms, llvm-aie, simulator doc/reference/build_and_run.md
aiehlc.sh options doc/reference/build_options.md
Pragmas: debug level, core trace, control plane, kernel config offload debug level, core trace, control plane, config offload
Debug tools (aiediag, the debug UI) doc/reference/debug_tools.md
Design documents doc/

Contributing

source script/setup.sh --dev installs the clang-format pre-commit hook; see the developer setup.

License

Apache License, Version 2.0; see LICENSE.

Copyright© 2025-2026 Advanced Micro Devices, Inc.

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages