Skip to content

Commit

Permalink
Enable Some Programming Examples for Strix (#1952)
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>
Co-authored-by: [email protected] <Joe Melber>
  • Loading branch information
jgmelber and github-actions[bot] authored Dec 4, 2024
1 parent 0c0b330 commit 0f747e2
Show file tree
Hide file tree
Showing 31 changed files with 1,151 additions and 1,069 deletions.
4 changes: 0 additions & 4 deletions aie_kernels/aie2/mul.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
//
//===----------------------------------------------------------------------===//

#define __AIENGINE__ 2
#define NOCPP
#define __AIEARCH__ 20

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
22 changes: 20 additions & 2 deletions programming_examples/basic/passthrough_kernel/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ srcdir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

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

device = npu
targetname = passThroughKernel
VPATH := ${srcdir}/../../../aie_kernels/generic
data_size = 4096
Expand All @@ -31,27 +32,44 @@ all: build/final_${data_size}.xclbin

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

build/aie_trace__lineBased_8b_${data_size}.mlir: ${srcdir}/${aie_py_src}
mkdir -p ${@D}
python3 $< ${data_size} ${trace_size} > $@
python3 $< ${device} ${data_size} ${trace_size} > $@

build/passThrough.cc.o: passThrough.cc
mkdir -p ${@D}
ifeq ($(device),npu)
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}
else ifeq ($(device),npu2)
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2P_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}
else
echo "Device type not supported"
endif

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

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


${targetname}_${data_size}.exe: ${srcdir}/test.cpp
rm -rf _build
Expand Down
19 changes: 12 additions & 7 deletions programming_examples/basic/passthrough_kernel/aie2.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import aie.utils.trace as trace_utils


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

@device(AIEDevice.npu1_1col)
@device(dev)
def device_body():
# define types
vector_ty = np.ndarray[(N,), np.dtype[np.uint8]]
Expand Down Expand Up @@ -55,8 +55,6 @@ def core_body():
of_in.release(ObjectFifoPort.Consume, 1)
of_out.release(ObjectFifoPort.Produce, 1)

# print(ctx.module.operation.verify())

@runtime_sequence(vector_ty, vector_ty, vector_ty)
def sequence(inTensor, outTensor, notUsed):
if trace_size > 0:
Expand Down Expand Up @@ -85,13 +83,20 @@ def sequence(inTensor, outTensor, notUsed):


try:
vector_size = int(sys.argv[1])
device_name = str(sys.argv[1])
if device_name == "npu":
dev = AIEDevice.npu1_1col
elif device_name == "npu2":
dev = AIEDevice.npu2
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
vector_size = int(sys.argv[2])
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])
trace_size = 0 if (len(sys.argv) != 4) else int(sys.argv[3])
except ValueError:
print("Argument has inappropriate value")
with mlir_mod_ctx() as ctx:
passthroughKernel(vector_size, trace_size)
passthroughKernel(dev, vector_size, trace_size)
print(ctx.module)
17 changes: 12 additions & 5 deletions programming_examples/basic/passthrough_kernel/aie2_alt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import aie.utils.trace as trace_utils


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

@device(AIEDevice.npu1_1col)
@device(dev)
def device_body():
# define types
vector_ty = np.ndarray[(N,), np.dtype[np.uint8]]
Expand Down Expand Up @@ -79,13 +79,20 @@ def sequence(inTensor, outTensor, notUsed):


try:
vector_size = int(sys.argv[1])
device_name = str(sys.argv[1])
if device_name == "npu":
dev = AIEDevice.npu1_1col
elif device_name == "npu2":
dev = AIEDevice.npu2
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
vector_size = int(sys.argv[2])
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])
trace_size = 0 if (len(sys.argv) != 4) else int(sys.argv[3])
except ValueError:
print("Argument has inappropriate value")
with mlir_mod_ctx() as ctx:
passthroughKernel(vector_size, trace_size)
passthroughKernel(dev, vector_size, trace_size)
print(ctx.module)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//
// REQUIRES: ryzen_ai, peano
//
// RUN: mkdir -p test
// RUN: cd test
// 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: Running...
// CHECK: PASS!
// RUN: %run_on_npu make -f %S/Makefile run
// RUN: %run_on_npu make -f %S/Makefile run_py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
// RUN: cd test_alt
// RUN: make -f %S/Makefile clean
// RUN: env use_alt=1 make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run_py | FileCheck %s
// CHECK: PASS!
// RUN: %run_on_npu make -f %S/Makefile run_py

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: mkdir -p test_stx
// RUN: cd test_stx
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile device=npu2
// RUN: %run_on_2npu make -f %S/Makefile run device=npu2
4 changes: 2 additions & 2 deletions programming_examples/basic/passthrough_kernel/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def main(opts):

if not errors:
print("\nPASS!\n")
exit(0)
sys.exit(0)
else:
print("\nError count: ", errors)
print("\nFailed.\n")
exit(-1)
sys.exit(1)


if __name__ == "__main__":
Expand Down
11 changes: 9 additions & 2 deletions programming_examples/basic/vector_scalar_mul/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include ${srcdir}/../../makefile-common

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

device = npu
targetname = vectorScalar
data_size = 4096
trace_size = 8192
Expand All @@ -32,19 +33,25 @@ kristof: build/insts_${data_size}.txt

build/%.o: %.cc
mkdir -p ${@D}
ifeq ($(device),npu)
ifeq ($(CHESS), true)
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -c $< -o ${@F};
else
cd ${@D} && ${PEANO_INSTALL_DIR}/bin/clang++ ${PEANOWRAP2_FLAGS} -c $< -o ${@F};
endif
else ifeq ($(device),npu2)
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2P_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}
else
echo "Device type not supported"
endif

build/aie_${data_size}.mlir: ${srcdir}/${aie_py_src}
mkdir -p ${@D}
python3 $< ${data_size} 0 > $@
python3 $< ${device} ${data_size} 0 > $@

build/aie_trace_${data_size}.mlir: ${srcdir}/${aie_py_src}
mkdir -p ${@D}
python3 $< ${data_size} ${trace_size} > $@
python3 $< ${device} ${data_size} ${trace_size} > $@

#build/insts_${data_size}.txt: build/final_${data_size}.xclbin
build/final_${data_size}.xclbin: build/aie_${data_size}.mlir build/scale.o
Expand Down
19 changes: 13 additions & 6 deletions programming_examples/basic/vector_scalar_mul/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import aie.utils.trace as trace_utils


def my_vector_scalar(vector_size, trace_size):
def my_vector_scalar(dev, vector_size, trace_size):
N = vector_size
N_in_bytes = N * 2
N_div_n = 4 # chop input vector into 4 sub-vectors
Expand All @@ -26,7 +26,7 @@ def my_vector_scalar(vector_size, trace_size):

vectorized = True

@device(AIEDevice.npu1_1col)
@device(dev)
def device_body():
tensor_ty = np.ndarray[(N,), np.dtype[np.int16]]
tile_ty = np.ndarray[(n,), np.dtype[np.int16]]
Expand Down Expand Up @@ -93,13 +93,20 @@ def sequence(A, F, C):


try:
vector_size = int(sys.argv[1])
device_name = str(sys.argv[1])
if device_name == "npu":
dev = AIEDevice.npu1_1col
elif device_name == "npu2":
dev = AIEDevice.npu2
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
vector_size = int(sys.argv[2])
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])
trace_size = 0 if (len(sys.argv) != 4) else int(sys.argv[3])
except ValueError:
print("Argument has inappropriate value")
with mlir_mod_ctx() as ctx:
my_vector_scalar(vector_size, trace_size)
print(ctx.module)
my_vector_scalar(dev, vector_size, trace_size)
print(ctx.module)
19 changes: 13 additions & 6 deletions programming_examples/basic/vector_scalar_mul/aie2_alt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import aie.utils.trace as trace_utils


def my_vector_scalar(vector_size, trace_size):
def my_vector_scalar(dev, vector_size, trace_size):
N = vector_size
N_in_bytes = N * 2
N_div_n = 4 # chop input vector into 4 sub-vectors
Expand All @@ -26,7 +26,7 @@ def my_vector_scalar(vector_size, trace_size):

vectorized = True

@device(AIEDevice.npu1_1col)
@device(dev)
def device_body():
tensor_ty = np.ndarray[(N,), np.dtype[np.int16]]
tile_ty = np.ndarray[(n,), np.dtype[np.int16]]
Expand Down Expand Up @@ -97,13 +97,20 @@ def sequence(A, F, C):


try:
vector_size = int(sys.argv[1])
device_name = str(sys.argv[1])
if device_name == "npu":
dev = AIEDevice.npu1_1col
elif device_name == "npu2":
dev = AIEDevice.npu2
else:
raise ValueError("[ERROR] Device name {} is unknown".format(sys.argv[1]))
vector_size = int(sys.argv[2])
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])
trace_size = 0 if (len(sys.argv) != 4) else int(sys.argv[3])
except ValueError:
print("Argument has inappropriate value")
with mlir_mod_ctx() as ctx:
my_vector_scalar(vector_size, trace_size)
print(ctx.module)
my_vector_scalar(dev, vector_size, trace_size)
print(ctx.module)
9 changes: 4 additions & 5 deletions programming_examples/basic/vector_scalar_mul/run_makefile.lit
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
// RUN: cd test_peano
// RUN: make -f %S/Makefile clean
// RUN: env CHESS=false 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
// RUN: %run_on_npu make -f %S/Makefile run
// RUN: %run_on_npu make -f %S/Makefile run_py
// RUN: make -f %S/Makefile clean
// RUN: env CHESS=false %run_on_npu make -f %S/Makefile trace | FileCheck %s
// RUN: env CHESS=false %run_on_npu make -f %S/Makefile trace_py | FileCheck %s
// CHECK: PASS!
// RUN: env CHESS=false %run_on_npu make -f %S/Makefile trace
// RUN: env CHESS=false %run_on_npu make -f %S/Makefile trace_py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
// RUN: cd test_alt
// RUN: make -f %S/Makefile clean
// RUN: env CHESS=true use_alt=1 make -f %S/Makefile
// RUN: %run_on_npu make -f %S/Makefile run | FileCheck %s
// CHECK: PASS!

// RUN: %run_on_npu make -f %S/Makefile run

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
// RUN: cd test_chess
// RUN: make -f %S/Makefile clean
// RUN: env CHESS=true 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
// RUN: %run_on_npu make -f %S/Makefile run
// RUN: %run_on_npu make -f %S/Makefile run_py
// RUN: make -f %S/Makefile clean
// RUN: env CHESS=true %run_on_npu make -f %S/Makefile trace | FileCheck %s
// RUN: env CHESS=true %run_on_npu make -f %S/Makefile trace_py | FileCheck %s
// CHECK: PASS!
// RUN: env CHESS=true %run_on_npu make -f %S/Makefile trace
// RUN: env CHESS=true %run_on_npu make -f %S/Makefile trace_py
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: mkdir -p test_stx
// RUN: cd test_stx
// RUN: make -f %S/Makefile clean
// RUN: make -f %S/Makefile device=npu2
// RUN: %run_on_2npu make -f %S/Makefile run device=npu2
4 changes: 2 additions & 2 deletions programming_examples/basic/vector_scalar_mul/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def main(opts):

if not errors:
print("\nPASS!\n")
exit(0)
sys.exit(0)
else:
print("\nError count: ", errors)
print("\nFailed.\n")
exit(-1)
sys.exit(1)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 0f747e2

Please sign in to comment.