Skip to content

Commit

Permalink
Use Peano for Programming Guide and Examples (#1844)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jgmelber and github-actions[bot] authored Oct 18, 2024
1 parent 5946b7d commit 4799ad3
Show file tree
Hide file tree
Showing 100 changed files with 375 additions and 129 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/buildAndTestRyzenAI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ concurrency:
env:
DEBIAN_FRONTEND: noninteractive
XILINXD_LICENSE_FILE: /opt/xilinx/Xilinx.lic
VITIS: /opt/Xilinx/Vitis/2023.2
VITIS: /opt/ryzen_ai-1.3.0/vitis_aie_essentials
CMAKE_ARGS: |
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
mkdir build
pushd build
export PATH=/opt/Xilinx/Vitis/2023.2/bin:/opt/Xilinx/Vitis/2023.2/aietools/bin:$PATH
export PATH=$VITIS/bin:$VITIS/aietools/bin:$PATH
cmake .. -G Ninja \
-DPython3_EXECUTABLE=$(which python) \
-DLLVM_EXTERNAL_LIT=$(which lit) \
Expand Down Expand Up @@ -134,11 +134,11 @@ jobs:
pip cache purge
source /opt/xilinx/xrt/setup.sh
export PATH=/opt/Xilinx/Vitis/2023.2/bin:/opt/Xilinx/Vitis/2023.2/aietools/bin:$PATH
export PATH=$VITIS/bin:$VITIS/aietools/bin:$PATH
source utils/quick_setup.sh
# quick_setup changes directory to programming_examples, so we need to return to mlir-aie
cd ..
./utils/build-mlir-aie-from-wheels.sh ./my_install/mlir
./utils/build-mlir-aie-from-wheels.sh ./my_install/mlir build install ./my_install/llvm-aie
# build is created by the build-mlir-aie-from-wheels.sh script
pushd build
Expand Down
7 changes: 0 additions & 7 deletions aie_kernels/generic/passThrough.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#define NOCPP

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <aie_api/aie.hpp>
Expand All @@ -37,39 +36,33 @@ extern "C" {
#if BIT_WIDTH == 8

void passThroughLine(uint8_t *in, uint8_t *out, int32_t lineWidth) {
printf("passThroughLine BIT_WIDTH\n");
passThrough_aie<uint8_t, 64>(in, out, 1, lineWidth);
}

void passThroughTile(uint8_t *in, uint8_t *out, int32_t tileHeight,
int32_t tileWidth) {
printf("passThroughTile BIT_WIDTH\n");
passThrough_aie<uint8_t, 64>(in, out, tileHeight, tileWidth);
}

#elif BIT_WIDTH == 16

void passThroughLine(int16_t *in, int16_t *out, int32_t lineWidth) {
printf("passThroughLine BIT_WIDTH\n");
passThrough_aie<int16_t, 32>(in, out, 1, lineWidth);
}

void passThroughTile(int16_t *in, int16_t *out, int32_t tileHeight,
int32_t tileWidth) {
printf("passThroughTile BIT_WIDTH\n");
passThrough_aie<int16_t, 32>(in, out, tileHeight, tileWidth);
}

#else // 32

void passThroughLine(int32_t *in, int32_t *out, int32_t lineWidth) {
printf("passThroughLine BIT_WIDTH\n");
passThrough_aie<int32_t, 16>(in, out, 1, lineWidth);
}

void passThroughTile(int32_t *in, int32_t *out, int32_t tileHeight,
int32_t tileWidth) {
printf("passThroughTile BIT_WIDTH\n");
passThrough_aie<int32_t, 16>(in, out, tileHeight, tileWidth);
}

Expand Down
1 change: 1 addition & 0 deletions programming_examples/basic/dma_transpose/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ build/aie.mlir: ${srcdir}/aie2.py
build/final.xclbin: build/aie.mlir
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --no-compile-host --xclbin-name=${@F} \
--no-xchesscc --no-xbridge --peano ${PEANO_INSTALL_DIR} \
--aie-generate-npu --npu-insts-name=insts.txt $(<:%=../%)

${targetname}.exe: ${srcdir}/test.cpp
Expand Down
2 changes: 1 addition & 1 deletion programming_examples/basic/dma_transpose/run_makefile.lit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ target_suffix=${M}x${K}x${N}_${m}x${k}x${n}_${n_aie_cols}c

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

CHESS=true

build/mm_${m}x${k}x${n}.o: ${kernels_dir}/cascade_mm.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ aie_py_src?=aie2.py
runargs?=-v 2 --warmup 1 --iters 1
aieargs+=-M $M -K $K -N $N --dtype_in ${dtype_in} --dtype_out ${dtype_out}

CHESS?=false

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

.PHONY: all
all: ${xclbin_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} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}

${mlir_target}: ${srcdir}/${aie_py_src}
mkdir -p ${@D}
Expand All @@ -97,6 +99,9 @@ ${mlir_target}: ${srcdir}/${aie_py_src}
${xclbin_target}: ${mlir_target} ${kernels:%=build/%.o}
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --no-compile-host --xclbin-name=${@F} \
$(if $(shell [ $(CHESS) != true ] && echo true), \
--no-xchesscc --no-xbridge --peano ${PEANO_INSTALL_DIR}, \
) \
--aie-generate-npu --npu-insts-name=${insts_target:build/%=%} $(<:%=../%)

${targetname}.exe: ${srcdir}/test.cpp ${srcdir}/../test.cpp ${srcdir}/../common.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ include ${SELF_DIR}../makefile-common

build/mv_${m}x${k}.o: ${kernels_dir}/mv.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -c $< -o ${@F}
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -c $< -o ${@F}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##===- Makefile -----------------------------------------------------------===##
#
# This file licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (C) 2024, Advanced Micro Devices, Inc.
#
##===----------------------------------------------------------------------===##

subdir=matrix_vector
targetname=matrixVectorMultiplication

# Currently does not accept reconfiguring size via these variables; must change
# in source at aie2.py as well as here
M=288
K=288
N=1
m=32
k=32

kernels=mv_${m}x${k}

SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include ${SELF_DIR}../makefile-common

CHESS=true

build/mv_${m}x${k}.o: ${kernels_dir}/mv.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -c $< -o ${@F}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile
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.chess clean
// RUN: make -f %S/Makefile.chess
// RUN: %run_on_npu make -f %S/Makefile.chess run | FileCheck %s
// CHECK: PASS!
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ include ${srcdir}/../makefile-common

build/mm_${m}x${k}x${n}.o: ${kernels_dir}/mm.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -D${dtype_in}_${dtype_out}_ONLY -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -D${dtype_in}_${dtype_out}_ONLY -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
##===- Makefile -----------------------------------------------------------===##
#
# This file licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (C) 2024, Advanced Micro Devices, Inc.
#
##===----------------------------------------------------------------------===##

srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
subdir=single_core
targetname=matrixMultiplication
kernels=mm

M?=256
K?=256
N?=256
m?=64
k?=64
n?=32

kernels=mm_${m}x${k}x${n}
aieargs+=-m $m -k $k -n $n
target_suffix=${M}x${K}x${N}_${m}x${k}x${n}
use_alt?=0

ifeq (${use_alt}, 1)
aie_py_src=aie2_alt.py
endif

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

CHESS=true

build/mm_${m}x${k}x${n}.o: ${kernels_dir}/mm.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -D${dtype_in}_${dtype_out}_ONLY -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_1
// RUN: cd %S/test_1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_2
// RUN: cd %S/test_2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_alt
// RUN: cd %S/test_alt
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.chess clean
// RUN: make -f %S/Makefile.chess
// RUN: %run_on_npu make -f %S/Makefile.chess run | FileCheck %s
// CHECK: PASS!
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_i8
// RUN: cd %S/test_i8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ include ${srcdir}/../makefile-common

build/mm_b_row_maj_${m}x${k}x${n}.o: ${kernels_dir}/mm.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -D${dtype_in}_${dtype_out}_ONLY -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -D${dtype_in}_${dtype_out}_ONLY -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}

build/mm_b_col_maj_${m}x${k}x${n}.o: ${kernels_dir}/mm_b_col_maj.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}

ifneq (${b_col_maj}, 1)
build/mm_${m}x${k}x${n}.o: build/mm_b_row_maj_${m}x${k}x${n}.o
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
##===- Makefile -----------------------------------------------------------===##
#
# This file licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (C) 2024, Advanced Micro Devices, Inc.
#
##===----------------------------------------------------------------------===##
srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
subdir=whole_array
targetname=matrixMultiplication

M?=640
K?=896
N?=768
m?=16
k?=32
n?=48
n_aie_cols?=2
b_col_maj?=0

kernels=mm_${m}x${k}x${n}
aieargs+=-m $m -k $k -n $n --n-aie-cols ${n_aie_cols} --b-col-maj ${b_col_maj}
runargs+=--b_col_maj ${b_col_maj}
target_suffix=${M}x${K}x${N}_${m}x${k}x${n}_${n_aie_cols}c

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

CHESS=true

build/mm_b_row_maj_${m}x${k}x${n}.o: ${kernels_dir}/mm.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -D${dtype_in}_${dtype_out}_ONLY -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}

build/mm_b_col_maj_${m}x${k}x${n}.o: ${kernels_dir}/mm_b_col_maj.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -DDIM_M=${m} -DDIM_K=${k} -DDIM_N=${n} -c $< -o ${@F}

ifneq (${b_col_maj}, 1)
build/mm_${m}x${k}x${n}.o: build/mm_b_row_maj_${m}x${k}x${n}.o
mkdir -p ${@D}
ar rvs $@ $^
else
build/mm_${m}x${k}x${n}.o: build/mm_b_col_maj_${m}x${k}x${n}.o
mkdir -p ${@D}
ar rvs $@ $^
endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_1_col
// RUN: cd %S/test_1_col
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_2_col
// RUN: cd %S/test_2_col
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_4_col
// RUN: cd %S/test_4_col
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) Copyright 2024 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p %S/test_4_col_i8
// RUN: cd %S/test_4_col_i8
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.chess clean
// RUN: make -f %S/Makefile.chess
// RUN: %run_on_npu make -f %S/Makefile.chess run | FileCheck %s
// CHECK: PASS!
Loading

0 comments on commit 4799ad3

Please sign in to comment.