Skip to content

Commit

Permalink
Modify test 08 to use aircc
Browse files Browse the repository at this point in the history
  • Loading branch information
erwei-xilinx committed Feb 24, 2025
1 parent 7467761 commit 02ed29d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# aie.py -*- Python -*-
# gen.py -*- Python -*-
#
# Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
# Copyright (C) 2025, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: MIT

import air
import air.compiler.util
from air.dialects import linalg, tensor, arith, func, memref
from air.backend.xrt import XRTBackend
from air.ir import *
import air.passmanager
from air.dialects import air as airdialect
from air.compiler.util import run_transform
import sys

with air.ir.Context() as ctx, Location.unknown():

################################################
## Tiling
## Input SCF and Linalg IR
################################################

air_tiled_ir_string = """
Expand Down Expand Up @@ -125,111 +120,10 @@
pm.run(air_module.operation)

###############################################
# Extract event dependency and optimize schedule
# Run compile and load
###############################################

pipeline = (
"builtin.module("
+ ",".join(
[
"air-dependency",
"air-dependency-schedule-opt",
"air-specialize-dma-broadcast",
"air-dma-to-channel",
"canonicalize",
"cse",
"air-dependency-canonicalize",
"canonicalize",
"cse",
"func.func(air-loop-fusion)",
"air-label-scf-for-to-ping-pong",
]
)
+ ")"
)
pm = air.passmanager.PassManager.parse(pipeline)
pm.run(air_module.operation)
# Not sure why parsing the ir solves the segmentation fault...
air_module = Module.parse(str(air_module))
pipeline = (
"builtin.module("
+ ",".join(
[
"air-ping-pong-transform",
"canonicalize",
"cse",
"func.func(air-opt-memtile-dma-bds{device=npu1_4col})",
"canonicalize",
"cse",
]
)
+ ")"
)
pm = air.passmanager.PassManager.parse(pipeline)
pm.run(air_module.operation)

################################################
## Place herd to segment
################################################

air_async_module = Module.parse(str(air_module))
pipeline = (
"builtin.module("
+ ",".join(
[
"func.func(air-collapse-herd)",
"canonicalize",
"cse",
"air-place-herds{num-rows=4 num-cols=1 row-anchor=2 col-anchor=0}",
"canonicalize",
"cse",
"func.func(air-renumber-dma)",
]
)
+ ")"
)
pm = air.passmanager.PassManager.parse(pipeline)
pm.run(air_module.operation)

################################################
## MLIR-AIR to MLIR-AIE
################################################

pipeline = (
"builtin.module("
+ ",".join(
[
"air-to-aie{row-offset=2 col-offset=0 device=npu1_4col emit-while-loop=true}",
"canonicalize",
]
)
+ ")"
backend = XRTBackend(
air_loop_fusion=True,
)
pm = air.passmanager.PassManager.parse(pipeline)
pm.run(air_module.operation)

################################################
## MLIR-AIR runtime lowering
################################################

pipeline = (
"builtin.module("
+ ",".join(
[
"func.func(air-opt-shim-dma-bds{device=npu1_4col})",
"air-to-std",
"canonicalize",
"symbol-dce",
"func.func(affine-loop-opt{affine-opt-tile-sizes=4,4})",
"func.func(air-unroll-outer-affine-loops{depth=2})",
"affine-expand-index-ops",
"airrt-to-npu",
"canonicalize",
]
)
+ ")"
)
pm = air.passmanager.PassManager.parse(pipeline)
pm.run(air_module.operation)
with open("aie.mlir", "w") as f:
f.write(str(air_module))
module_function = backend.compile_and_load(air_module)
5 changes: 2 additions & 3 deletions test/xrt/08_gemm_extern_vec/run.lit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// REQUIRES: ryzen_ai, valid_xchess_license

// RUN: xchesscc_wrapper aie2 -c %S/mm.cc -o mm.o
// RUN: %python %S/aie.py
// RUN: %python aiecc.py --xchesscc --xbridge --no-aiesim --aie-generate-cdo --aie-generate-npu --no-compile-host --xclbin-name=aie.xclbin --npu-insts-name=insts.txt aie.mlir
// RUN: %python %S/gen.py
// RUN: g++-13 %S/test.cpp -o test.exe -std=c++23 -Wall %xrt_flags -lrt -lstdc++ -lboost_program_options -lboost_filesystem
// RUN: %run_on_npu ./test.exe -x aie.xclbin -k MLIR_AIE -i insts.txt
// RUN: %run_on_npu ./test.exe -x air.xclbin -k MLIR_AIE -i air.insts.txt

0 comments on commit 02ed29d

Please sign in to comment.