Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[program examples] lit test on Makefile #1397

Merged
merged 31 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e3d7dff
lit test on Makefile
denolf Apr 24, 2024
a1b9080
Add basic makefiles to lit
jgmelber Apr 24, 2024
06701e7
Remove deprecated env var
jgmelber Apr 24, 2024
a673db5
Fix passthrough hardware
jgmelber Apr 24, 2024
6b53ae5
Don't lock for xclbin build
jgmelber Apr 24, 2024
b9c556b
Change vec_scal_add examples to vec_scal_mul and cleaned up README re…
jackl-xilinx Apr 24, 2024
d2a4d53
run with run_on_npu
denolf Apr 24, 2024
99233e1
run_makefile run_on_npu
jgmelber Apr 24, 2024
11ed6ac
Rename vector_vector
jgmelber Apr 24, 2024
f03d0c1
Merge branch 'makefileLitTested' of https://github.com/Xilinx/mlir-ai…
jgmelber Apr 24, 2024
d8083a2
Revert "Change vec_scal_add examples to vec_scal_mul and cleaned up R…
jgmelber Apr 24, 2024
f27156b
Fix vector vector
jgmelber Apr 24, 2024
d62d868
Fix exp
jgmelber Apr 24, 2024
49c8afb
More fixes
jgmelber Apr 24, 2024
22beb5d
fix makefile for trace
denolf Apr 24, 2024
7271f61
Update programming_examples/basic/passthrough_kernel/aie2.py
jgmelber Apr 24, 2024
dbd56e3
fix for makefile run lit
denolf Apr 24, 2024
22341ee
remove run.lit
denolf Apr 25, 2024
c6908c5
no python test
denolf Apr 25, 2024
adf5f88
fix for local common makefile
denolf Apr 25, 2024
4ed66ea
fix run.lit
denolf Apr 25, 2024
2e93859
fix sizes
denolf Apr 25, 2024
903d2d6
fixes
denolf Apr 25, 2024
bda300a
fixes
denolf Apr 25, 2024
687fd74
Update programming_examples/basic/vector_vector_mul/test.cpp
denolf Apr 25, 2024
4b8c3e3
Update programming_examples/basic/vector_vector_add/test.cpp
denolf Apr 25, 2024
49c71e6
run_makefile.lit for matrix_add
jgmelber Apr 25, 2024
7905e86
Rename matrix add
jgmelber Apr 25, 2024
c8d173e
remove deprecated run.lit
jgmelber Apr 25, 2024
610f287
Delete vector sum
jgmelber Apr 25, 2024
050ed92
Merge branch 'main' into makefileLitTested
jgmelber Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions programming_examples/basic/dma_transpose/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#
##===----------------------------------------------------------------------===##

include ../../makefile-common
srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

include ${srcdir}/../../makefile-common

SHELL := /bin/bash

Expand All @@ -16,27 +18,19 @@ targetname = dmaTranspose
M ?= 64
K ?= 32

build/aie.mlir: aie2.py
build/aie.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${M} ${K} > $@

.PHONY: inst/insts.txt
inst/insts.txt: aie2.py
rm -rf inst
mkdir -p inst
python3 $< ${LENGTH} > inst/aie.mlir
pushd inst && aiecc.py --aie-only-generate-npu --npu-insts-name=insts.txt aie.mlir && popd
${powershell} ./build/${targetname}.exe -x build/final.xclbin -i inst/insts.txt -k MLIR_AIE -l ${LENGTH}

build/final.xclbin: build/aie.mlir
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --no-compile-host --xclbin-name=${@F} \
--aie-generate-npu --npu-insts-name=insts.txt $(<:%=../%)

${targetname}.exe: test.cpp
${targetname}.exe: ${srcdir}/test.cpp
rm -rf _build
mkdir -p _build
cd _build && ${powershell} cmake .. -DTARGET_NAME=${targetname}
cd _build && ${powershell} cmake ${srcdir} -DTARGET_NAME=${targetname}
cd _build && ${powershell} cmake --build . --config Release
ifeq "${powershell}" "powershell.exe"
cp _build/${targetname}.exe $@
Expand Down
9 changes: 9 additions & 0 deletions programming_examples/basic/dma_transpose/run_makefile.lit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s
// CHECK: PASS!
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
# - M, K, N -- (optional) dimensions of matrices, may be used by design;
# N=1 for matrix-vector

srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
#include ${CURDIR}/../../makefile-common
current_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
#include ${current_dir}../../makefile-common
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include ${SELF_DIR}../../makefile-common
include ${current_dir}../../makefile-common

# defaults; overwrite if needed
M?=512
Expand All @@ -46,16 +47,16 @@ insts_target?=build/insts_${M}x${K}x${N}.txt

runargs?=-v 1 --warmup 10 --iters 10

kernels_dir=../../../../aie_kernels/aie2
kernels_dir=${srcdir}/../../../../aie_kernels/aie2

.PHONY: all
all: ${xclbin_target} ${insts_target} ${targetname}.exe

build/%.o: ${kernels_dir}/%.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -c $(<:%=../%) -o ${@F}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}

${mlir_target}: aie2.py
${mlir_target}: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< -M $M -K $K -N $N > $@

Expand All @@ -64,10 +65,10 @@ ${xclbin_target}: ${mlir_target} ${kernels:%=build/%.o}
cd ${@D} && aiecc.py --aie-generate-cdo --no-compile-host --xclbin-name=${@F} \
--aie-generate-npu --npu-insts-name=${insts_target:build/%=%} $(<:%=../%)

${targetname}.exe: test.cpp ../test.cpp ../common.h
${targetname}.exe: ${srcdir}/test.cpp ${srcdir}/../test.cpp ${srcdir}/../common.h
rm -rf _build
mkdir -p _build
cd _build && ${powershell} cmake -E env CXXFLAGS="-std=c++23 -ggdb" cmake ../.. -D CMAKE_C_COMPILER=gcc-13 -D CMAKE_CXX_COMPILER=g++-13 -DTARGET_NAME=${targetname} -Dsubdir=${subdir}
cd _build && ${powershell} cmake -E env CXXFLAGS="-std=c++23 -ggdb" cmake ${srcdir}/.. -D CMAKE_C_COMPILER=gcc-13 -D CMAKE_CXX_COMPILER=g++-13 -DTARGET_NAME=${targetname} -Dsubdir=${subdir}
cd _build && ${powershell} cmake --build . --config Release
ifeq "${powershell}" "powershell.exe"
cp _build/${targetname}.exe $@
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s
// CHECK: PASS!
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s
// CHECK: PASS!
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
##===----------------------------------------------------------------------===##
srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

subdir=whole_array
targetname=matrixMultiplication
Expand All @@ -14,4 +15,4 @@ M?=512
K?=512
N?=512

include ../makefile-common
include ${srcdir}/../makefile-common
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s
// CHECK: PASS!
22 changes: 11 additions & 11 deletions programming_examples/basic/passthrough_dmas/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
#
##===----------------------------------------------------------------------===##

include ../../makefile-common
srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

ACDC_AIE = $(dir $(shell which aie-opt))/..

SHELL := /bin/bash
include ${srcdir}/../../makefile-common

all: build/final.xclbin build/insts.txt

devicename ?= npu
targetname = passThroughDMAs
LENGTH ?= 4096

build/aie.mlir: aie2.py
build/aie.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${devicename} ${col} ${LENGTH} ${LENGTH} > $@
python3 $< ${LENGTH} ${devicename} ${col} > $@

.PHONY: inst/insts.txt
inst/insts.txt: aie2.py
inst/insts.txt: ${srcdir}/aie2.py
rm -rf inst
mkdir -p inst
python3 $< ${devicename} ${col} ${LENGTH} > inst/aie.mlir
python3 $< ${LENGTH} > inst/aie.mlir
pushd inst && aiecc.py --aie-only-generate-npu --npu-insts-name=insts.txt aie.mlir && popd
${powershell} ./build/${targetname}.exe -x build/final.xclbin -i inst/insts.txt -k MLIR_AIE -l ${LENGTH}

Expand All @@ -34,10 +33,10 @@ build/final.xclbin: build/aie.mlir
cd ${@D} && aiecc.py --aie-generate-cdo --no-compile-host --xclbin-name=${@F} \
--aie-generate-npu --npu-insts-name=insts.txt $(<:%=../%)

${targetname}.exe: test.cpp
${targetname}.exe: ${srcdir}/test.cpp
rm -rf _build
mkdir -p _build
cd _build && ${powershell} cmake .. -DTARGET_NAME=${targetname}
cd _build && ${powershell} cmake ${srcdir} -DTARGET_NAME=${targetname}
cd _build && ${powershell} cmake --build . --config Release
ifeq "${powershell}" "powershell.exe"
cp _build/${targetname}.exe $@
Expand Down Expand Up @@ -66,7 +65,8 @@ vck5000: build/aie.mlir
-Wl,-rpath,${ROCM_ROOT}/lib \
-Wl,--whole-archive -Wl,--no-whole-archive -lstdc++ -ldl -lelf -o test.elf


run_vck5000:
test.elf

clean:
rm -rf build _build inst ${targetname}.exe
25 changes: 12 additions & 13 deletions programming_examples/basic/passthrough_dmas/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@
from aie.extras.context import mlir_mod_ctx

N = 4096
dev = AIEDevice.npu
col = 0


# Deciphering the command line arguments
if len(sys.argv) < 3:
raise ValueError("[ERROR] Need 2 command line arguments (Device name, Col)")

if len(sys.argv) == 4:
if len(sys.argv) > 1:
N = int(sys.argv[1])

if sys.argv[1] == "npu":
dev = AIEDevice.npu
elif sys.argv[1] == "xcvc1902":
dev = AIEDevice.xcvc1902
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
if len(sys.argv) > 2:
if sys.argv[2] == "npu":
dev = AIEDevice.npu
elif sys.argv[2] == "xcvc1902":
dev = AIEDevice.xcvc1902
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[2]))

col = int(sys.argv[2])
if len(sys.argv) > 3:
col = int(sys.argv[3])


def my_passthrough():
Expand Down
2 changes: 1 addition & 1 deletion programming_examples/basic/passthrough_dmas/run.lit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// REQUIRES: ryzen_ai
//
// RUN: %python %S/aie2.py npu 0 > ./aie.mlir
// RUN: %python %S/aie2.py 4096 npu 0 > ./aie.mlir
// RUN: %python aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host --xclbin-name=aie.xclbin --npu-insts-name=insts.txt ./aie.mlir
// RUN: clang %S/test.cpp -o test.exe -std=c++11 -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 -l 4096 | FileCheck %s
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s
// CHECK: PASS!
60 changes: 38 additions & 22 deletions programming_examples/basic/passthrough_kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,72 @@
#
##===----------------------------------------------------------------------===##

include ../../makefile-common
srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

VPATH := ../../../aie_kernels/generic

PASSTHROUGH_SIZE = 4096
include ${srcdir}/../../makefile-common

targetname = passThroughKernel
VPATH := ${srcdir}/../../../aie_kernels/generic
data_size = 4096
trace_size = 8192
PASSTHROUGH_SIZE = ${data_size}

.PHONY: all template clean

all: build/final_${PASSTHROUGH_SIZE}.xclbin
all: build/final_${data_size}.xclbin

build/aie2_lineBased_8b_${data_size}.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${data_size} 0 > $@

build/aie2_lineBased_8b_${PASSTHROUGH_SIZE}.mlir: aie2.py
build/aie_trace__lineBased_8b_${data_size}.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${PASSTHROUGH_SIZE} > $@
python3 $< ${data_size} ${trace_size} > $@

build/passThrough.cc.o: passThrough.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -c $(<:%=../%) -o ${@F}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}

build/final_${PASSTHROUGH_SIZE}.xclbin: build/aie2_lineBased_8b_${PASSTHROUGH_SIZE}.mlir build/passThrough.cc.o
build/final_${data_size}.xclbin: build/aie2_lineBased_8b_${data_size}.mlir build/passThrough.cc.o
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host \
--xclbin-name=${@F} --npu-insts-name=insts.txt $(<:%=../%)
--xclbin-name=${@F} --npu-insts-name=insts_${data_size}.txt $(<:%=../%)

${targetname}.exe: test.cpp
build/final_trace_${data_size}.xclbin: build/aie2_lineBased_8b_${data_size}.mlir build/passThrough.cc.o
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host \
--xclbin-name=${@F} --npu-insts-name=insts_${data_size}.txt $(<:%=../%)

${targetname}_${data_size}.exe: ${srcdir}/test.cpp
rm -rf _build
mkdir -p _build
cd _build && ${powershell} cmake .. -DTARGET_NAME=${targetname} -DPASSTHROUGH_SIZE=${PASSTHROUGH_SIZE}
cd _build && ${powershell} cmake ${srcdir} -DTARGET_NAME=${targetname} -DPASSTHROUGH_SIZE=${data_size}
cd _build && ${powershell} cmake --build . --config Release
ifeq "${powershell}" "powershell.exe"
cp _build/${targetname}.exe $@
else
cp _build/${targetname} $@
endif

run: ${targetname}.exe build/final_${PASSTHROUGH_SIZE}.xclbin build/insts.txt
${powershell} ./$< -x build/final_${PASSTHROUGH_SIZE}.xclbin -i build/insts.txt -k MLIR_AIE
run: ${targetname}_${data_size}.exe build/final_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} ./$< -x build/final_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE

#run-g: ${targetname}.exe build/final_${data_size}.xclbin build/insts.txt
# ${powershell} ./$< -x build/final_${data_size}.xclbin -i build/insts.txt -k MLIR_AIE -t ${trace_size}

run-g: ${targetname}.exe build/final_${PASSTHROUGH_SIZE}.xclbin build/insts.txt
${powershell} ./$< -x build/final_${PASSTHROUGH_SIZE}.xclbin -i build/insts.txt -k MLIR_AIE -t 8192
run_py: build/final_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} python3 ${srcdir}/test.py -s ${data_size} -x build/final_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE

run_py: build/final_${PASSTHROUGH_SIZE}.xclbin build/insts.txt
${powershell} python3 test.py -s ${PASSTHROUGH_SIZE} -x build/final_${PASSTHROUGH_SIZE}.xclbin -i build/insts.txt -k MLIR_AIE
trace: ${targetname}_${data_size}.exe build/final_trace_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} ./$< -x build/final_trace_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE -t ${trace_size}
../../utils/parse_trace.py --filename trace.txt --mlir build/aie_trace_${data_size}.mlir --colshift 1 > trace_vs.json

trace:
../../utils/parse_eventIR.py --filename trace.txt --mlir build/aie.mlir --colshift 1 > parse_eventIR_vs.json
trace_py: build/final_trace_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} python3 ${srcdir}/test.py -x build/final_trace_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE -t ${trace_size} -s ${data_size}
../../utils/parse_trace.py --filename trace.txt --mlir build/aie_trace_${data_size}.mlir --colshift 1 > trace_vs.json

clean_trace:
rm -rf tmpTrace trace.txt
rm -rf tmpTrace trace.txt parse*json trace*json

clean:
rm -rf build _build ${targetname}.exe
rm -rf build _build ${targetname}*.exe
Loading
Loading