Skip to content

Commit

Permalink
clean up passthrough pykernel
Browse files Browse the repository at this point in the history
  • Loading branch information
hunhoffe committed Sep 30, 2024
1 parent 79c7a3e commit a540333
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 49 deletions.
34 changes: 3 additions & 31 deletions programming_examples/basic/passthrough_pykernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,17 @@ 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_${data_size}.xclbin

build/aie2_lineBased_8b_${data_size}.mlir: ${srcdir}/aie2.py
build/aie.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
python3 $< ${data_size} 0 > $@
python3 $< ${PASSTHROUGH_SIZE} > $@

build/aie_trace__lineBased_8b_${data_size}.mlir: ${srcdir}/aie2.py
mkdir -p ${@D}
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}

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_${data_size}.txt $(<:%=../%)

build/final_trace_${data_size}.xclbin: build/aie2_lineBased_8b_${data_size}.mlir build/passThrough.cc.o
build/final_${data_size}.xclbin: build/aie.mlir
mkdir -p ${@D}
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-npu --no-compile-host \
--xclbin-name=${@F} --npu-insts-name=insts_${data_size}.txt $(<:%=../%)
Expand All @@ -58,22 +44,8 @@ endif
run: ${targetname}_${data_size}.exe build/final_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} ./$< -x build/final_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE

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

trace: ${targetname}_${data_size}.exe build/final_trace_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} ./$< -x build/final_trace_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE -t ${trace_size}
../../utils/parse_trace.py --filename trace.txt --mlir build/aie_trace_${data_size}.mlir --colshift 1 > trace_vs.json

trace_py: build/final_trace_${data_size}.xclbin build/insts_${data_size}.txt
${powershell} python3 ${srcdir}/test.py -x build/final_trace_${data_size}.xclbin -i build/insts_${data_size}.txt -k MLIR_AIE -t ${trace_size} -s ${data_size}
../../utils/parse_trace.py --filename trace.txt --mlir build/aie_trace_${data_size}.mlir --colshift 1 > trace_vs.json

clean_trace:
rm -rf tmpTrace trace.txt parse*json trace*json

clean:
rm -rf build _build ${targetname}*.exe
20 changes: 2 additions & 18 deletions programming_examples/basic/passthrough_pykernel/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
from aie.extras.dialects.ext.func import func
from aie.extras.dialects.ext.scf import _for as range_

import aie.utils.trace as trace_utils


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

Expand All @@ -36,10 +34,6 @@ def passThroughLine(input: memRef_ty, output: memRef_ty, lineWidth: np.int32):
ShimTile = tile(0, 0)
ComputeTile2 = tile(0, 2)

# Set up a circuit-switched flow from core to shim for tracing information
if trace_size > 0:
flow(ComputeTile2, WireBundle.Trace, 0, ShimTile, WireBundle.DMA, 1)

# AIE-array data movement with object fifos
of_in = object_fifo("in", ShimTile, ComputeTile2, 2, memRef_ty)
of_out = object_fifo("out", ComputeTile2, ShimTile, 2, memRef_ty)
Expand All @@ -62,15 +56,6 @@ def core_body():

@runtime_sequence(tensor_ty, tensor_ty, tensor_ty)
def sequence(inTensor, outTensor, notUsed):
if trace_size > 0:
trace_utils.configure_simple_tracing_aie2(
ComputeTile2,
ShimTile,
ddr_id=1,
size=trace_size,
offset=N,
)

npu_dma_memcpy_nd(
metadata=of_in,
bd_id=0,
Expand All @@ -92,9 +77,8 @@ def sequence(inTensor, outTensor, notUsed):
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(vector_size, trace_size)
passthroughKernel(vector_size)
print(ctx.module)

0 comments on commit a540333

Please sign in to comment.