Skip to content

Commit

Permalink
rename and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
denolf committed Apr 10, 2024
1 parent cd2345a commit b17f178
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include ../makefile-common

SHELL := /bin/bash

targetname = passThroughHardware
targetname = passThroughDMAs
LENGTH ?= 4096

all: build/final.xclbin build/insts.txt
Expand Down Expand Up @@ -47,4 +47,4 @@ run: ${targetname}.exe build/final.xclbin build/insts.txt
${powershell} ./$< -x build/final.xclbin -i build/insts.txt -k MLIR_AIE -l ${LENGTH}

clean:
rm -rf build _build inst
rm -rf build _build inst ${targetname}.exe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from aie.extras.context import mlir_mod_ctx

N = 4096
N_in_bytes = N * 4

if len(sys.argv) == 2:
N = int(sys.argv[1])
Expand All @@ -41,9 +40,8 @@ def device_body():
# Compute tile 2
@core(ComputeTile2)
def core_body():
tmp = memref.alloc(1, T.i32())
v0 = arith.constant(0, T.i32())
memref.store(v0, tmp, [0])
for _ in for_(sys.maxsize):
yield_([])

# To/from AIE-array data movement
tensor_ty = T.memref(N, T.i32())
Expand Down
3 changes: 1 addition & 2 deletions programming_examples/basic/passthrough_kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# (c) Copyright 2023 Xilinx Inc.
# (c) Copyright 2024 Xilinx Inc.

# parameters
# -DBOOST_ROOT: Path to Boost install
# -DOpenCV_DIR: Path to OpenCV install
# -DXRT_INC_DIR: Full path to src/runtime_src/core/include in XRT cloned repo
# -DXRT_LIB_DIR: Path to xrt_coreutil.lib
# -DTARGET_NAME: Target name to be built
Expand Down
2 changes: 1 addition & 1 deletion programming_examples/basic/passthrough_kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VPATH := ../../../aie_kernels/aie_generic

PASSTHROUGH_SIZE = 4096

targetname = passthrough_kernel
targetname = passThroughKernel

.PHONY: all template clean

Expand Down
40 changes: 15 additions & 25 deletions programming_examples/basic/passthrough_kernel/aie2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# (c) Copyright 2023 AMD Inc.
# (c) Copyright 2024 AMD Inc.

import sys

Expand All @@ -12,30 +12,30 @@
from aie.dialects.scf import *
from aie.extras.context import mlir_mod_ctx

width = 1024
N = 1024

if len(sys.argv) == 2:
width = int(sys.argv[1])
N = int(sys.argv[1])

lineWidthInBytes = width
lineWidthInBytes = N
lineWidthInInt32s = lineWidthInBytes // 4

enableTrace = False
traceSizeInBytes = 8192
traceSizeInInt32s = traceSizeInBytes // 4


def passThroughAIE2():
def passthroughKernel():
with mlir_mod_ctx() as ctx:

@device(AIEDevice.ipu)
def device_body():
# define types
line_ty = T.memref(lineWidthInBytes, T.ui8())
memRef_ty = T.memref(lineWidthInBytes, T.ui8())

# AIE Core Function declarations
passThroughLine = external_func(
"passThroughLine", inputs=[line_ty, line_ty, T.i32()]
"passThroughLine", inputs=[memRef_ty, memRef_ty, T.i32()]
)

# Tile declarations
Expand All @@ -46,8 +46,8 @@ def device_body():
flow(ComputeTile2, "Trace", 0, ShimTile, "DMA", 1)

# AIE-array data movement with object fifos
of_in = object_fifo("in", ShimTile, ComputeTile2, 2, line_ty)
of_out = object_fifo("out", ComputeTile2, ShimTile, 2, line_ty)
of_in = object_fifo("in", ShimTile, ComputeTile2, 2, memRef_ty)
of_out = object_fifo("out", ComputeTile2, ShimTile, 2, memRef_ty)

# Set up compute tiles

Expand All @@ -57,16 +57,16 @@ def core_body():
for _ in for_(sys.maxsize):
elemOut = of_out.acquire(ObjectFifoPort.Produce, 1)
elemIn = of_in.acquire(ObjectFifoPort.Consume, 1)
call(passThroughLine, [elemIn, elemOut, width])
call(passThroughLine, [elemIn, elemOut, lineWidthInBytes])
of_in.release(ObjectFifoPort.Consume, 1)
of_out.release(ObjectFifoPort.Produce, 1)
yield_([])

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

tensorSize = width
tensorSize = N
tensorSizeInInt32s = tensorSize // 4
tensor_ty = T.memref(tensorSizeInInt32s, T.i32())
tensor_ty = T.memref(lineWidthInInt32s, T.i32())

@FuncOp.from_py_func(tensor_ty, tensor_ty, tensor_ty)
def sequence(inTensor, outTensor, notUsed):
Expand Down Expand Up @@ -150,20 +150,10 @@ def sequence(inTensor, outTensor, notUsed):
)
IpuWrite32(0, 0, 0x1D20C, 0x3)

ipu_dma_memcpy_nd(
metadata="in",
bd_id=0,
mem=inTensor,
sizes=[1, 1, 1, tensorSizeInInt32s],
)
ipu_dma_memcpy_nd(
metadata="out",
bd_id=1,
mem=outTensor,
sizes=[1, 1, 1, tensorSizeInInt32s],
)
ipu_dma_memcpy_nd(metadata="in", bd_id=0, mem=inTensor, sizes=[1, 1, 1, tensorSizeInInt32s])
ipu_dma_memcpy_nd(metadata="out", bd_id=1, mem=outTensor, sizes=[1, 1, 1, tensorSizeInInt32s])
ipu_sync(column=0, row=0, direction=0, channel=0)

print(ctx.module)

passThroughAIE2()
passthroughKernel()
12 changes: 12 additions & 0 deletions programming_examples/basic/passthrough_kernel/run.lit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// (c) Copyright 2023 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// REQUIRES: ryzen_ai, chess
//
// RUN: xchesscc_wrapper aie2 -I %aietools/include -DBIT_WIDTH=8 -c %S/../../../aie_kernels/aie_generic/passThrough.cc -o passThrough.cc.o
// RUN: %python %S/aie2.py 4096 | aie-opt -cse -canonicalize -o ./aie.mlir
// RUN: %python aiecc.py --xbridge --aie-generate-cdo --aie-generate-ipu --no-compile-host --xclbin-name=aie.xclbin --ipu-insts-name=insts.txt ./aie.mlir
// RUN: clang %S/test.cpp -o test.exe -std=c++11 -Wall -DPASSTHROUGH_SIZE=4096 -I%S/../../utils %S/../../utils/xrtUtils.cpp %xrt_flags -lrt -lstdc++ -lboost_program_options -lboost_filesystem
// RUN: %run_on_ipu ./test.exe -x aie.xclbin -k MLIR_AIE -i insts.txt | FileCheck %s
// CHECK: PASS!

21 changes: 10 additions & 11 deletions programming_examples/basic/passthrough_kernel/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,21 @@ int main(int argc, const char *argv[]) {
bo_out.sync(XCL_BO_SYNC_BO_FROM_DEVICE);

// Compare out to in
int numberOfDifferences = 0;
int errors = 0;
for(int i = 0; i < PASSTHROUGH_SIZE; i++) {
if(bufOut[i] != bufInA[i])
numberOfDifferences++;
errors++;
}

// Print Pass/Fail result of our test
int res = 0;
if (numberOfDifferences == 0) {
printf("PASS!\n");
res = 0;
if (!errors) {
std::cout << std::endl << "PASS!" << std::endl << std::endl;
return 0;
} else {
printf("Fail!\n");
res = -1;
std::cout << std::endl
<< errors << " mismatches." << std::endl
<< std::endl;
std::cout << std::endl << "fail." << std::endl << std::endl;
return 1;
}

printf("Testing passThrough done!\n");
return res;
}

0 comments on commit b17f178

Please sign in to comment.