Macro for Device Architectures - 2023.2 English

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2023-12-04
Version
2023.2 English

Macro __AIE_ARCH__

AI Engine compiler supports predefined macro __AIE_ARCH__ to differentiate different architectures:

  • __AIE_ARCH__=10: AI Engine device has a predefined value of 10.
  • __AIE_ARCH__=20: AI Engine-ML device has a predefined value of 20.

The macro can be used inside AI Engine kernel or AI Engine graph code. When designing for different architectures, the macro can be used to guard for specific architectures.

For example, in the kernel code, the macro is used to choose architecture specific API:

void fir24(input_buffer<cint16,...> &iwin, output_buffer<cint16> &owin) {
  ...
  #if __AIE_ARCH__==10
    acc=aie::sliding_mul_sym<4,4>(...);
  #elif __AIE_ARCH__==20
    acc=aie::sliding_mul<4,8>(...);
  #endif
  ...
}

Following example shows how to use the macro in the graph code to choose buffer sizes based on a specific architecture:

//Using __AIE_ARCH__ macro to define buffer size for AI Engine device
#if __AIE_ARCH__==10
  static const int NUM=4096;
//Using __AIE_ARCH__ macro to define buffer size for AI Engine-ML device
#elif __AIE_ARCH__==20
  static const int NUM=8192;
//Covering rest of the cases - recommended for PS compilation
#else
  static const NUM=4096; 
#endif

using namespace adf;
class topgraph: public adf::graph
{
public:
	kernel k;
	
	topgraph(){
            ......
            k=kernel::create(mykernel);
            dimensions(k.in[0])={NUM};
            dimensions(k.out[0])={NUM};
	}
};
Note: If the graph code is included in the PS code compilation, you must add -D__AIE_ARCH__=<NUM> preprocessor definition to the Arm cross compiler to differentiate the devices.