Skip to content

Commit 04a7dc6

Browse files
authored
Fixed makefile to support npu2 (#2037)
1 parent b836d01 commit 04a7dc6

File tree

3 files changed

+248
-228
lines changed

3 files changed

+248
-228
lines changed

programming_examples/vision/color_detect/Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ include ${srcdir}/../../makefile-common
1212

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

15+
device = npu
1516
COLORDETECT_WIDTH = 1920
1617
COLORDETECT_HEIGHT = 1080
1718

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

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

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

4552
build/aie2_lineBased_8b_${COLORDETECT_WIDTH}.mlir: ${srcdir}/${aie_py_src}
4653
mkdir -p ${@D}
47-
python3 $< ${COLORDETECT_WIDTH} ${COLORDETECT_HEIGHT} > $@
54+
python3 $< ${device} ${COLORDETECT_WIDTH} ${COLORDETECT_HEIGHT} > $@
4855

4956
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
5057
mkdir -p ${@D}
58+
ifeq ($(device),npu)
5159
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host --alloc-scheme=basic-sequential \
5260
--no-xchesscc --no-xbridge \
5361
--xclbin-name=${@F} --npu-insts-name=insts.txt $(<:%=../%)
62+
else
63+
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host --alloc-scheme=basic-sequential \
64+
--xclbin-name=${@F} --npu-insts-name=insts.txt $(<:%=../%)
65+
endif
5466

5567
${targetname}.exe: ${srcdir}/test.cpp
5668
mkdir -p ${@D}

programming_examples/vision/color_detect/color_detect.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@
99

1010
from aie.iron import Kernel, ObjectFifo, Program, Runtime, Worker
1111
from aie.iron.placers import SequentialPlacer
12-
from aie.iron.device import NPU1Col1
12+
from aie.iron.device import NPU1Col1, NPU2
1313

14-
width = 64
15-
height = 36
16-
if len(sys.argv) == 3:
17-
width = int(sys.argv[1])
18-
height = int(sys.argv[2])
14+
from aie.extras.dialects.ext import arith
15+
from aie.helpers.util import np_ndarray_type_get_shape
16+
from aie.dialects.aie import T
1917

20-
lineWidth = width
21-
lineWidthInBytes = width * 4
22-
tensorSize = width * height * 4 # 4 channels
2318

24-
traceSize = 1024
19+
def color_detect(dev, width, height):
20+
lineWidth = width
21+
lineWidthInBytes = width * 4
22+
tensorSize = width * height * 4 # 4 channels
2523

26-
27-
def color_detect():
24+
traceSize = 1024
2825

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

214211
# Place components (assign them resources on the device) and generate an MLIR module
215-
return Program(NPU1Col1(), rt).resolve_program(SequentialPlacer())
216-
217-
218-
module = color_detect()
212+
return Program(dev, rt).resolve_program(SequentialPlacer())
213+
214+
215+
try:
216+
device_name = str(sys.argv[1])
217+
if device_name == "npu":
218+
dev = NPU1Col1()
219+
elif device_name == "npu2":
220+
dev = NPU2()
221+
else:
222+
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
223+
width = 64 if (len(sys.argv) != 4) else int(sys.argv[2])
224+
height = 36 if (len(sys.argv) != 4) else int(sys.argv[3])
225+
except ValueError:
226+
print("Argument has inappropriate value")
227+
module = color_detect(dev, width, height)
219228
print(module)

0 commit comments

Comments
 (0)