Skip to content

Commit

Permalink
Fixed makefile to support npu2 (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackl-xilinx authored Feb 6, 2025
1 parent b836d01 commit 04a7dc6
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 228 deletions.
14 changes: 13 additions & 1 deletion programming_examples/vision/color_detect/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include ${srcdir}/../../makefile-common

VPATH := ${srcdir}/../../../aie_kernels/aie2

device = npu
COLORDETECT_WIDTH = 1920
COLORDETECT_HEIGHT = 1080

Expand All @@ -36,21 +37,32 @@ mlir: build/aie2_lineBased_8b_${COLORDETECT_WIDTH}.mlir

build/%.cc.o: %.cc
mkdir -p ${@D}
ifeq ($(device),npu)
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}
else ifeq ($(device),npu2)
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2P_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}
else
echo "Device type not supported"
endif

build/combined_bitwiseOR_gray2rgba_bitwiseAND.a: build/bitwiseOR.cc.o build/gray2rgba.cc.o build/bitwiseAND.cc.o
mkdir -p ${@D}
ar rvs $@ $< $(word 2,$^) $(word 3,$^)

build/aie2_lineBased_8b_${COLORDETECT_WIDTH}.mlir: ${srcdir}/${aie_py_src}
mkdir -p ${@D}
python3 $< ${COLORDETECT_WIDTH} ${COLORDETECT_HEIGHT} > $@
python3 $< ${device} ${COLORDETECT_WIDTH} ${COLORDETECT_HEIGHT} > $@

build/final_${COLORDETECT_WIDTH}.xclbin: build/aie2_lineBased_8b_${COLORDETECT_WIDTH}.mlir build/rgba2hue.cc.o build/threshold.cc.o build/combined_bitwiseOR_gray2rgba_bitwiseAND.a
mkdir -p ${@D}
ifeq ($(device),npu)
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host --alloc-scheme=basic-sequential \
--no-xchesscc --no-xbridge \
--xclbin-name=${@F} --npu-insts-name=insts.txt $(<:%=../%)
else
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host --alloc-scheme=basic-sequential \
--xclbin-name=${@F} --npu-insts-name=insts.txt $(<:%=../%)
endif

${targetname}.exe: ${srcdir}/test.cpp
mkdir -p ${@D}
Expand Down
41 changes: 25 additions & 16 deletions programming_examples/vision/color_detect/color_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@

from aie.iron import Kernel, ObjectFifo, Program, Runtime, Worker
from aie.iron.placers import SequentialPlacer
from aie.iron.device import NPU1Col1
from aie.iron.device import NPU1Col1, NPU2

width = 64
height = 36
if len(sys.argv) == 3:
width = int(sys.argv[1])
height = int(sys.argv[2])
from aie.extras.dialects.ext import arith
from aie.helpers.util import np_ndarray_type_get_shape
from aie.dialects.aie import T

lineWidth = width
lineWidthInBytes = width * 4
tensorSize = width * height * 4 # 4 channels

traceSize = 1024
def color_detect(dev, width, height):
lineWidth = width
lineWidthInBytes = width * 4
tensorSize = width * height * 4 # 4 channels


def color_detect():
traceSize = 1024

# Define types
line_bytes_ty = np.ndarray[(lineWidthInBytes,), np.dtype[np.uint8]]
Expand Down Expand Up @@ -212,8 +209,20 @@ def or_gray2rgba_and_fn(
rt.drain(outOF_L2L3.cons(), O, wait=True)

# Place components (assign them resources on the device) and generate an MLIR module
return Program(NPU1Col1(), rt).resolve_program(SequentialPlacer())


module = color_detect()
return Program(dev, rt).resolve_program(SequentialPlacer())


try:
device_name = str(sys.argv[1])
if device_name == "npu":
dev = NPU1Col1()
elif device_name == "npu2":
dev = NPU2()
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
width = 64 if (len(sys.argv) != 4) else int(sys.argv[2])
height = 36 if (len(sys.argv) != 4) else int(sys.argv[3])
except ValueError:
print("Argument has inappropriate value")
module = color_detect(dev, width, height)
print(module)
Loading

0 comments on commit 04a7dc6

Please sign in to comment.