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 15 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
10 changes: 10 additions & 0 deletions programming_examples/basic/dma_transpose/run_makefile.lit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// (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
// RUN: %run_on_npu make -f %S/Makefile run_py | 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
@@ -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
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!
40 changes: 21 additions & 19 deletions programming_examples/basic/passthrough_kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,58 @@
#
##===----------------------------------------------------------------------===##

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_${PASSTHROUGH_SIZE}.mlir: aie2.py
build/aie2_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 $(<:%=../%)

${targetname}.exe: test.cpp
${targetname}.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}.exe build/final_${data_size}.xclbin build/insts.txt
${powershell} ./$< -x build/final_${data_size}.xclbin -i build/insts.txt -k MLIR_AIE

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-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_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
run_py: build/final_${data_size}.xclbin build/insts.txt
${powershell} python3 ${srcdir}/test.py -s ${data_size} -x build/final_${data_size}.xclbin -i build/insts.txt -k MLIR_AIE

trace:
../../utils/parse_eventIR.py --filename trace.txt --mlir build/aie.mlir --colshift 1 > parse_eventIR_vs.json
../../utils/parse_eventIR.py --filename trace.txt --mlir build/aie2_lineBased_8b_${data_size}.mlir --colshift 1 > parse_eventIR_vs.json

clean_trace:
rm -rf tmpTrace trace.txt
rm -rf tmpTrace trace.txt parse_eventIR_vs.json

clean:
rm -rf build _build ${targetname}.exe
39 changes: 17 additions & 22 deletions programming_examples/basic/passthrough_kernel/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@

import aie.utils.trace as trace_utils

N = 1024

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

lineWidthInBytes = N // 4 # chop input in 4 sub-tensors
lineWidthInInt32s = lineWidthInBytes // 4

enableTrace = False
traceSizeInBytes = 8192
traceSizeInInt32s = traceSizeInBytes // 4


def passthroughKernel():
def passthroughKernel(vector_size, trace_size):
N = vector_size
lineWidthInBytes = N // 4 # chop input in 4 sub-tensors
lineWidthInInt32s = lineWidthInBytes // 4

@device(AIEDevice.npu)
def device_body():
Expand All @@ -43,7 +34,8 @@ def device_body():
ShimTile = tile(0, 0)
ComputeTile2 = tile(0, 2)

if enableTrace:
# Set up a circuit-switched flow from core to shim for tracing information
jgmelber marked this conversation as resolved.
Show resolved Hide resolved
if trace_size > 0:
flow(ComputeTile2, WireBundle.Trace, 0, ShimTile, WireBundle.DMA, 1)

# AIE-array data movement with object fifos
Expand Down Expand Up @@ -71,18 +63,13 @@ def core_body():

@FuncOp.from_py_func(tensor_ty, tensor_ty, tensor_ty)
def sequence(inTensor, outTensor, notUsed):
if enableTrace:
if trace_size > 0:
trace_utils.configure_simple_tracing_aie2(
ComputeTile2,
ShimTile,
channel=1,
bd_id=13,
ddr_id=1,
size=traceSizeInBytes,
size=trace_size,
offset=tensorSize,
start=0x1,
stop=0x0,
events=[0x4B, 0x22, 0x21, 0x25, 0x2D, 0x2C, 0x1A, 0x4F],
)

npu_dma_memcpy_nd(
Expand All @@ -100,6 +87,14 @@ def sequence(inTensor, outTensor, notUsed):
npu_sync(column=0, row=0, direction=0, channel=0)


try:
vector_size = int(sys.argv[1])
if vector_size % 64 != 0 or vector_size < 512:
print("Vector size must be a multiple of 64 and greater than or equal to 512")
raise ValueError
trace_size = 0 if (len(sys.argv) != 3) else int(sys.argv[2])
except ValueError:
print("Argument has inappropriate value")
with mlir_mod_ctx() as ctx:
passthroughKernel()
passthroughKernel(vector_size, trace_size)
print(ctx.module)
12 changes: 0 additions & 12 deletions programming_examples/basic/passthrough_kernel/run.lit

This file was deleted.

Loading
Loading