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

Enable Some Programming Examples for Strix #1952

Merged
merged 42 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c7fdd9e
Strix passthrough
jgmelber Oct 10, 2024
a287f46
Fixup test
jgmelber Oct 11, 2024
133ce6c
Dog
jgmelber Oct 24, 2024
fdbde78
Apply suggestions from code review
jgmelber Oct 24, 2024
a576bd2
Fixup aiecc.py for npu/npu2
jgmelber Oct 25, 2024
83d7051
Try enabling run_on_npu2
jgmelber Oct 25, 2024
096d0bc
Apply suggestions from code review
jgmelber Oct 25, 2024
cd69950
Merge branch 'main' into pt-strix
jgmelber Oct 25, 2024
6ea15fa
Add lit fixup
jgmelber Oct 25, 2024
d1f543f
Fixup lit cfg
jgmelber Oct 25, 2024
74c689c
Fix Makefile
jgmelber Oct 25, 2024
85e19ee
Don't pollute source tree
jgmelber Oct 25, 2024
332a00c
fix
jgmelber Oct 25, 2024
797fda9
Rely on test return value for PASS/fail
jgmelber Oct 25, 2024
997074e
Merge branch 'main' into pt-strix
jgmelber Oct 25, 2024
29b96bf
Merge branch 'main' into pt-strix
jgmelber Nov 22, 2024
23ca4b5
Generic mul kernel test on Strix
Dec 2, 2024
28c52f0
Update aie_kernels/aie2/mul.cc
jgmelber Dec 2, 2024
9b64d77
Merge branch 'main' into pt-strix
jgmelber Dec 2, 2024
7977393
Update alt files
jgmelber Dec 3, 2024
9caaef3
Try with words
jgmelber Dec 3, 2024
8a37de3
Try reordering
jgmelber Dec 3, 2024
c21a4b3
Merge branch 'main' into pt-strix
jgmelber Dec 3, 2024
9d32148
Remove FileCheck and use return
jgmelber Dec 3, 2024
0b344b7
Merge branch 'main' into pt-strix
jgmelber Dec 3, 2024
05fa898
[TEST] break the test
jgmelber Dec 3, 2024
3730e78
test.py return fix
jgmelber Dec 3, 2024
0f45307
test.py return fix again
jgmelber Dec 3, 2024
fb36343
test.py return 1
jgmelber Dec 3, 2024
8464fde
Force fail test.py
jgmelber Dec 4, 2024
007882c
Test for CI
jgmelber Dec 4, 2024
8459aef
Break alt
jgmelber Dec 4, 2024
08ac2d0
Cleanup
jgmelber Dec 4, 2024
7434ab9
vector_scalar_mul stx
jgmelber Dec 4, 2024
9da29ee
Use returns for lit checks
jgmelber Dec 4, 2024
ff3f484
Add some vision examples
jgmelber Dec 4, 2024
5b5ed07
Update alt to accept device
jgmelber Dec 4, 2024
75ef8d7
Vision tests use return not FileCheck
jgmelber Dec 4, 2024
70cc1e5
Merge branch 'main' into pt-strix
jgmelber Dec 4, 2024
cbf116e
Apply suggestions from code review
jgmelber Dec 4, 2024
d898263
Apply code review
jgmelber Dec 4, 2024
9278ee0
Apply suggestions from code review
jgmelber Dec 4, 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
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)
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
Loading