This Session demonstrates how to perform a ‘negative’ of a Colour 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 customized for Phoenix.
Features covered in this sessionImplementation of the "Color 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 vice versa.
The 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 the 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 );For a color Image, the negative is calculated for each component separately.
In column 0, the data path starts at the SHIM DMA (0, 0), passes through the MEM tile (0, 1), and then feeds three compute cores: Core (0, 2) for Red, Core (0, 3) for Green, and Core (0, 4) for Blue. An 8-bit 1920×1080 RGB image is read from L3 memory and streamed to the MEM tile one row at a time, with the R, G, and B components of each row delivered to their respective cores.
Data Flow for ComputationThe core then calculates the negative of each pixel and then routes the converted pixels back to L3 memory.
Input images
Output images
To 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.jpgTo run the Trace:
make traceTracehttps://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 Tool-chain” and “AIE API” to write a kernel to perform the “negative of a colored image”. Trace reveals how the cores are in the “Lock Stall”.







Comments