Skip to content

Commit

Permalink
migrate passthrough_kernel to use xrtrunner
Browse files Browse the repository at this point in the history
  • Loading branch information
hunhoffe committed Jul 19, 2024
1 parent 2c9dd11 commit 1621b9b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 66 deletions.
9 changes: 6 additions & 3 deletions programming_examples/passthrough/passthrough_kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ VPATH := ${MLIR_AIE_DIR}/aie_kernels/generic

all: run

print:
${powershell} python3 ${srcdir}/passthrough_kernel.py -p

build/passThrough.cc.o: ${VPATH}/passThrough.cc
mkdir -p ${@D}
cd ${@D} && xchesscc_wrapper ${CHESSCCWRAP2_FLAGS} -DBIT_WIDTH=8 -c $< -o ${@F}

run: build/passThrough.cc.o
mkdir -p build
cd build && ${powershell} python3 ${srcdir}/run.py
mkdir -p ${srcdir}/build
cd ${srcdir}/build && ${powershell} python3 ${srcdir}/passthrough_kernel.py

clean:
rm -rf ${srcdir}/build ${srcdir}/__pycache__
rm -rf ${srcdir}/build ${srcdir}/__pycache__
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
# Copyright (C) 2024, Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
import sys
from pathlib import Path # if you haven't already done so

# Python paths are a bit complex. Taking solution from : https://stackoverflow.com/questions/16981921/relative-imports-in-python-3
file = Path(__file__).resolve()
parent, root = file.parent, file.parents[1]
sys.path.append(str(root))

# Additionally remove the current file's directory from sys.path
try:
sys.path.remove(str(parent))
except ValueError: # Already removed
pass
import argparse
import numpy as np

from air.ir import *
from air.dialects.air import *
from air.dialects.memref import AllocOp, DeallocOp
from air.dialects.func import FuncOp
from air.dialects.scf import for_, yield_
from air.backend.xrt_runner import XRTRunner

range_ = for_

from common import *
INOUT_DATATYPE = np.uint8
INOUT_ELEM_SIZE = np.dtype(INOUT_DATATYPE).itemsize


@module_builder
def build_module(vector_size):
assert vector_size % NUM_VECTORS == 0
def build_module(vector_size, num_subvectors):
assert vector_size % num_subvectors == 0

# chop input in 4 sub-tensors
lineWidthInBytes = vector_size // NUM_VECTORS
lineWidthInBytes = vector_size // num_subvectors

# Type and method of input/output
memrefTyInOut = T.memref(vector_size, T.ui8())
Expand Down Expand Up @@ -70,7 +61,7 @@ def segment_body():
@herd(name="copyherd", sizes=[1, 1], link_with="passThrough.cc.o")
def herd_body(tx, ty, sx, sy):

for i in range_(NUM_VECTORS):
for i in range_(num_subvectors):
# We must allocate a buffer of image size for the input/output
tensor_in = AllocOp(tensor_type, [], [])
tensor_out = AllocOp(tensor_type, [], [])
Expand All @@ -92,5 +83,45 @@ def herd_body(tx, ty, sx, sy):


if __name__ == "__main__":
module = build_module()
print(module)
parser = argparse.ArgumentParser(
prog="run.py",
description="Builds, runs, and tests the passthrough_dma example",
)
parser.add_argument(
"-s",
"--vector_size",
type=int,
default=4096,
help="The size (in bytes) of the data vector to passthrough",
)
parser.add_argument(
"--subvector_size",
type=int,
default=4,
help="The number of sub-vectors to break the vector into",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
)
parser.add_argument(
"-p",
"--print-module-only",
action="store_true",
)
args = parser.parse_args()

mlir_module = build_module(args.vector_size, args.subvector_size)
if args.print_module_only:
print(mlir_module)
exit(0)

input_a = np.arange(1, args.vector_size + 1, dtype=INOUT_DATATYPE)
output_b = np.arange(1, args.vector_size + 1, dtype=INOUT_DATATYPE)
for i in range(args.vector_size):
input_a[i] = i % 0xFF
output_b[i] = i % 0xFF

runner = XRTRunner(verbose=args.verbose)
exit(runner.run_test(mlir_module, inputs=[input_a], expected_outputs=[output_b]))
43 changes: 0 additions & 43 deletions programming_examples/passthrough/passthrough_kernel/run.py

This file was deleted.

0 comments on commit 1621b9b

Please sign in to comment.