Kernels are computation functions that form the fundamental building
blocks of the data flow graph specifications. Kernels are declared as ordinary C/C++
functions that return void
and can use special data
types as arguments (discussed in Window and Streaming Data API).
Each kernel must be defined in its own source file. This organization is recommended for
reusability and faster compilation. Furthermore, the kernel source files should include
all relevant header files to allow for independent compilation.
-
#include "aie_api/aie.hpp"
-
#include "aie_api/aie_adf.hpp"
It is recommended that a header file (kernels.h
in this documentation) should declare the function prototypes
for all kernels used in a graph. An example is as follows.
#ifndef FUNCTION_KERNELS_H
#define FUNCTION_KERNELS_H
void simple(input_window<cint16> * in, output_window<cint16> * out);
#endif
In the example, the #ifndef
and #endif
are present to ensure that the include file is only
included once, which is good C/C++ practice.
The kernels.cc is the implementation file for the
simple function. The kernel implementation declares two complex int 16 variables
c1
and c2
. It then reads the complex int16 input
data into c1
using the window_readincr
API, adds the real and imaginary values and assigns it back to c2.real
.
It also subtracts the imaginary value from the real value and assign it to
c2.imag
. Finally c2
is written back to the output
window using the window_writeincr
API.
/* A simple kernel */
#include <adf.h>
#include "include.h"
void simple(input_window<cint16> * in, output_window<cint16> * out) {
cint16 c1, c2;
for (unsigned i=0; i<NUM_SAMPLES; i++) {
c1 = window_readincr(in);
c2.real = c1.real+c1.imag;
c2.imag = c1.real-c1.imag;
window_writeincr(out, c2);
}
}