This tutorial demonstrates on how to perform a ‘negative’ of a grey image in AMD Ryzen AI Phoenix using AIE DIALECTS and AIE API
RequirementsAMD Ryzen AI Phoenix.Linux® based development environmentPython® (for test automation and result validation)IRON API and MLIR-based AI Engine ToolchainOpenCV (Open Source Computer Vision Library)
Project BriefThe SOC is designed to accelerate the AIE-ML algorithms to deliver a good, exceptional performance. The NPU complex has
- 16 AI Cores for computation
- 4 Memory Tiles for fast memory access
- 4 SHIM DMA to Move data in and out of L3 Memory
Note : This project is customised for Phoenix.
Features covered in this sessionImplementation of the "Grayscale Image to Negative Image Conversion" algorithm on the AI NPU, along with the data movement from the external memory.
ArchitectureA negative image is a total inversion of a normal image, where light areas appear dark and dark areas appear light.
The grey negative image formula is s = L - 1 - r, where r is the original pixel's intensity, s is the new negative pixel's intensity, and L is the total number of gray levels (e.g., 256 for 8-bit images, making L-1 = 255). This formula inverts pixel intensities (black becomes white, white becomes black) to create a photographic negative effect, enhancing detail in dark areas.
Formula Breakdown
- s: The output (negative) pixel intensity.
- r: The input (original) pixel intensity.
- L: The total number of gray levels (e.g., 256 for 8-bit images).
- L - 1: The maximum possible intensity value in the image (e.g., 255 for 8-bit).
Example (8-bit image, L=256)Black (r=0): s = 255 - 0 = 255 (White).White (r=255): s = 255 - 255 = 0 (Black).Mid-gray (r=128): s = 255 - 128 = 127 (Also mid-gray)
AIE implementation using AIE APIAIE API provides a programming interface for AIE accelerators with which programmers can efficiently code.https://xilinx.github.io/aie_api/index.html
/*Vector load of s 64 pixels*/
tempR = aie::load_v<64>( inSPtr );
/*Vector subtraction of 64 pixels s = l-1-r*/
tempS = aie::sub( tempL ,tempR);
/*Vector store of 64 s pixels*/
aie::store_v( outSPtr, tempS );In this section, SHIM DMA(0, 0) and Core(0, 2) of column 0 are used. A 1920x1080 8-bit image is sent to Core (0, 2) from L3 Memory. The core then calculates the negative of each pixel and then routes the converted pixels back to L3 memory.
How to Build and RunTo compile the placed design:
env use_placed=1 make
make conv_to_negative.exeTo run the design:
./conv_to_negative.exe -x build/final_1920.xclbin -i build/insts.bin -k MLIR_AIE --image input_image.jpgInput image:
Output image:
https://www.hackster.io/541340/amd-ryzen-ai-npu-tool-chain-installation-and-execution-b252fa
ConclusionThis tutorial demonstrates how to use the "IRON API and MLIR-based AI Engine Toolchain" and "AIE API" to write a kernel to perform the "negative of the image".










Comments