Skip to content

Commit

Permalink
[program examples] lit test on Makefile (#1397)
Browse files Browse the repository at this point in the history
Co-authored-by: Joseph Melber <jmelber@xilinx.com>
Co-authored-by: Jack Lo <36210336+jackl-xilinx@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Joseph Melber <jgmelber@gmail.com>
  • Loading branch information
5 people authored Apr 25, 2024
1 parent 7b6e3c4 commit 0644a0a
Show file tree
Hide file tree
Showing 72 changed files with 393 additions and 860 deletions.
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: 0 additions & 10 deletions programming_examples/basic/dma_transpose/run.lit

This file was deleted.

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!
11 changes: 0 additions & 11 deletions programming_examples/basic/matrix_add_one/run.lit

This file was deleted.

13 changes: 7 additions & 6 deletions programming_examples/basic/matrix_multiplication/makefile-common
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

This file was deleted.

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!

This file was deleted.

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

This file was deleted.

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 @@ -49,8 +49,6 @@ add_executable(${currentTarget}
test.cpp
)

set_property(TARGET ${currentTarget} PROPERTY CXX_STANDARD 23)

target_compile_definitions(${currentTarget} PUBLIC DISABLE_ABI_CHECK=1)

target_include_directories (${currentTarget} PUBLIC
Expand Down
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

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

Expand All @@ -23,18 +25,18 @@ build/final.xclbin: build/aie.mlir
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host \
--xclbin-name=${@F} --npu-insts-name=insts.txt ${<F}

${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 $@
else
cp _build/${targetname} $@
endif

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
//===----------------------------------------------------------------------===//-->

# <ins>Matrix Addition</ins>
# <ins>Matrix Scalar Addition</ins>

Single tile performs a very simple `+` operation where the kernel loads data from local memory, increments the value by `1` and stores it back. The DMA in the Shim tile is programmed to bring the bottom left `8x16` portion of a larger `16x128` matrix into the tile to perform the operation. This reference design can be run on either a RyzenAI NPU or a VCK5000.

Expand Down
9 changes: 9 additions & 0 deletions programming_examples/basic/matrix_scalar_add/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!
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
10 changes: 0 additions & 10 deletions programming_examples/basic/passthrough_dmas/run.lit

This file was deleted.

9 changes: 9 additions & 0 deletions programming_examples/basic/passthrough_dmas/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!
Loading

0 comments on commit 0644a0a

Please sign in to comment.