Skip to content

C++ AIE kernels

This is the compute code that runs on an individual AIE tile. A Worker places one of these functions on a compute tile; the kernel does the actual vectorized math on the data streamed to it by ObjectFifos.

Kernels are written in C++ and compiled for the AIE core (by Peano or, when available, xchesscc). They are a separate layer from the Python API: IRON handles placement and data movement, while the kernel handles the arithmetic.

Where they live

The aie_kernels directory holds a library of example kernels, organized by family (activation, conv, linalg, norm, ...). Each family directory matches a module under aie.iron.kernels. One source serves AIE2 and AIE2P. Where the two architectures need different code, the family holds X_aie2.h and X_aie2p.h and a small X.cc that includes the right one. Helpers shared across families live in common/.

See the aie_kernels README for the full per-kernel catalog (name, coding style, purpose, datatypes).

How they are written

Kernels use one of three coding styles, in decreasing order of portability:

  • AIE API — a C++ header-only library (#include <aie_api/aie.hpp>) of vector types and operations that lower to efficient per-generation intrinsics. This is the recommended style; see the AIE API User Guide.
  • Low-level intrinsics — architecture-specific intrinsics used directly when the AIE API does not expose a needed operation.
  • Plain C — scalar code with no vectorization, portable across generations.
#include <aie_api/aie.hpp>

template <typename T>
void scale_vectorized(T *__restrict a, T *__restrict c, int32_t factor,
                      const int32_t N) {
  event0();
  for (int i = 0; i < N; i += 16) {
    aie::vector<T, 16> v = aie::load_v<16>(a + i);
    aie::store_v(c + i, aie::mul(v, factor));
  }
  event1();
}

Using a kernel from IRON

A C++ kernel is bound into a design as a Kernel (a pre-compiled object file) or an ExternalFunction (C/C++ source compiled at JIT time), then handed to a Worker. The kernel vectorization walkthrough in the Programming Guide works through writing and tuning one of these kernels.

For ready-made kernels callable directly from Python without writing C++, see the Python Kernel Library.