forked from Xilinx/mlir-aie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update section-1 and section-3 examples (Xilinx#1179)
- Loading branch information
1 parent
fc44199
commit a4cec00
Showing
9 changed files
with
563 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!---//===- README.md --------------------------*- Markdown -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// Copyright (C) 2022, Advanced Micro Devices, Inc. | ||
// | ||
//===----------------------------------------------------------------------===//--> | ||
|
||
# <ins>Quick Reference</ins> | ||
|
||
## Python Bindings | ||
|
||
| Syntax | Definition | Example | Notes | | ||
|--------|------------|---------|-------| | ||
| \<name\> = tile(column, row) | Declare AI Engine tile | ComputeTile = tile(1,3) | The actual tile coordinates run on the device may deviate from the ones declared here. In Ryzen AI, for example, these coordinates tend to be relative corodinates as the runtime scheduler may assign it to a different available column. | | ||
|
||
## Object FIFO Bindings | ||
|
||
|
||
## Python helper functions | ||
| Function | Description | | ||
|----------|-------------| | ||
| print(ctx.module) | Converts our ctx wrapped structural code to mlir and prints to stdout| | ||
| print(ctx.module.operation.verify()) | Runs additional structural verficiation on the python binded source code and prints to stdout | | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
##===- Makefile -----------------------------------------------------------===## | ||
# | ||
# This file licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
include ../../tutorials/makefile-common | ||
|
||
build/aie.mlir: aie2.py | ||
mkdir -p ${@D} | ||
python3 $< > $@ | ||
|
||
all: build/aie.mlir | ||
|
||
clean: | ||
rm -rf build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
# | ||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# (c) Copyright 2023 AMD Inc. | ||
|
||
from aie.dialects.aie import * # primary mlir-aie dialect definitions | ||
from aie.extras.context import mlir_mod_ctx # mlir ctx wrapper | ||
|
||
# AI Engine structural design function | ||
def mlir_aie_design(): | ||
# ctx wrapper - to convert python to mlir | ||
with mlir_mod_ctx() as ctx: | ||
|
||
# Dvice declaration - aie2 device xcvc1902 | ||
@device(AIEDevice.xcvc1902) | ||
def device_body(): | ||
|
||
# Tile(s) declarations | ||
ComputeTile1 = tile(1, 3) | ||
ComputeTile2 = tile(2, 3) | ||
ComputeTile3 = tile(2, 4) | ||
|
||
# Print the mlir conversion | ||
print(ctx.module) | ||
|
||
# Call design function to generate mlir code to stdout | ||
mlir_aie_design() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# (c) Copyright 2023 Advanced Micro Devices, Inc. | ||
|
||
# parameters | ||
# -DBOOST_ROOT: Path to Boost 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 | ||
|
||
# cmake needs this line | ||
cmake_minimum_required(VERSION 3.1) | ||
|
||
find_program(WSL NAMES powershell.exe) | ||
|
||
if (NOT WSL) | ||
set(BOOST_ROOT /usr/include/boost CACHE STRING "Path to Boost install") | ||
set(XRT_INC_DIR /opt/xilinx/xrt/include CACHE STRING "Path to XRT cloned repo") | ||
set(XRT_LIB_DIR /opt/xilinx/xrt/lib CACHE STRING "Path to xrt_coreutil.lib") | ||
else() | ||
set(BOOST_ROOT C:/Technical/thirdParty/boost_1_83_0 CACHE STRING "Path to Boost install") | ||
set(XRT_INC_DIR C:/Technical/XRT/src/runtime_src/core/include CACHE STRING "Path to XRT cloned repo") | ||
set(XRT_LIB_DIR C:/Technical/xrtIPUfromDLL CACHE STRING "Path to xrt_coreutil.lib") | ||
endif() | ||
|
||
set(TARGET_NAME test CACHE STRING "Target to be built") | ||
|
||
SET (ProjectName ${TARGET_NAME}) | ||
SET (currentTarget ${TARGET_NAME}) | ||
|
||
if ( WSL ) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}) | ||
endif () | ||
|
||
project(${ProjectName}) | ||
|
||
# Find packages | ||
find_package(Boost REQUIRED) | ||
|
||
add_executable(${currentTarget} | ||
test.cpp | ||
) | ||
|
||
target_compile_definitions(${currentTarget} PUBLIC DISABLE_ABI_CHECK=1) | ||
|
||
target_include_directories (${currentTarget} PUBLIC | ||
${XRT_INC_DIR} | ||
${Boost_INCLUDE_DIRS} | ||
../../reference_designs/utils | ||
) | ||
|
||
target_link_directories(${currentTarget} PUBLIC | ||
${XRT_LIB_DIR} | ||
${Boost_LIBRARY_DIRS} | ||
) | ||
|
||
if (NOT WSL) | ||
target_link_libraries(${currentTarget} PUBLIC | ||
xrt_coreutil | ||
boost_program_options | ||
boost_filesystem | ||
) | ||
else() | ||
target_link_libraries(${currentTarget} PUBLIC | ||
xrt_coreutil | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
##===- Makefile -----------------------------------------------------------===## | ||
# | ||
# This file licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
include ../../reference_designs/ipu-xrt/makefile-common | ||
|
||
all: build/final.xclbin | ||
|
||
targetname = myFirstProgram | ||
|
||
build/aie.mlir: aie2.py | ||
mkdir -p ${@D} | ||
python3 $< > $@ | ||
|
||
build/final.xclbin: build/aie.mlir | ||
mkdir -p ${@D} | ||
cd ${@D} && aiecc.py --aie-generate-cdo --aie-generate-ipu --no-compile-host \ | ||
--xclbin-name=${@F} --ipu-insts-name=insts.txt ${<F} | ||
|
||
${targetname}.exe: test.cpp | ||
rm -rf _build | ||
mkdir -p _build | ||
# cd _build && ${powershell} cmake .. -DTARGET_NAME=${targetname} | ||
cd _build && ${powershell} cmake -E env CXXFLAGS="-std=c++23 -ggdb" cmake .. -D CMAKE_C_COMPILER=gcc-13 -D CMAKE_CXX_COMPILER=g++-13 -DTARGET_NAME=${targetname} -Dsubdir=${subdir} | ||
cd _build && ${powershell} cmake --build . --config Release | ||
ifeq "${powershell}" "powershell.exe" | ||
cp _build/${targetname}.exe $@ | ||
else | ||
cp _build/${targetname} $@ | ||
endif | ||
|
||
run: ${targetname}.exe build/final.xclbin build/insts.txt | ||
${powershell} ./$< -x build/final.xclbin -i build/insts.txt -k MLIR_AIE | ||
|
||
clean: | ||
rm -rf build _build ${targetname}.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
# | ||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# (c) Copyright 2023 AMD Inc. | ||
|
||
from aie.dialects.aie import * # primary mlir-aie dialect definitions | ||
from aie.extras.context import mlir_mod_ctx # mlir ctx wrapper | ||
|
||
from aie.dialects.aiex import * # extended mlir-aie dialect definitions | ||
from aie.dialects.scf import * # scf (strcutred control flow) dialect | ||
from aie.extras.dialects.ext import memref, arith # memref and arithmatic dialects | ||
|
||
# AI Engine structural design function | ||
def my_first_aie_program(): | ||
# ctx wrapper - to convert python to mlir | ||
with mlir_mod_ctx() as ctx: | ||
|
||
# Dvice declaration - aie2 device IPU (aka Ryzen AI) | ||
@device(AIEDevice.ipu) | ||
def device_body(): | ||
# Memref types | ||
memRef_8_ty = T.memref(8, T.i32()) | ||
memRef_16_ty = T.memref(16, T.i32()) | ||
memRef_32_ty = T.memref(32, T.i32()) | ||
memRef_64_ty = T.memref(64, T.i32()) | ||
|
||
# Tile declarations | ||
ComputeTile = tile(0, 2) | ||
ShimTile = tile(0, 0) | ||
|
||
# AIE-array data movement with object fifos | ||
# Input | ||
of_in0 = object_fifo("in0", ShimTile, ComputeTile, 2, memRef_8_ty) | ||
|
||
# Output | ||
of_out0 = object_fifo("out0", ComputeTile, ShimTile, 2, memRef_8_ty) | ||
|
||
# Compute tile | ||
@core(ComputeTile) | ||
def core_body(): | ||
for _ in for_(8): | ||
elem_in = of_in0.acquire(ObjectFifoPort.Consume, 1) | ||
elem_out = of_out0.acquire(ObjectFifoPort.Produce, 1) | ||
for i in for_(8): | ||
v0 = memref.load(elem_in, [i]) | ||
v1 = arith.addi(v0, arith.constant(1, T.i32())) | ||
memref.store(v1, elem_out, [i]) | ||
yield_([]) | ||
of_in0.release(ObjectFifoPort.Consume, 1) | ||
of_out0.release(ObjectFifoPort.Produce, 1) | ||
yield_([]) | ||
|
||
# To/from AIE-array data movement | ||
@FuncOp.from_py_func(memRef_64_ty, memRef_32_ty, memRef_64_ty) | ||
def sequence(inTensor, notUsed, outTensor): | ||
ipu_dma_memcpy_nd( | ||
metadata="out0", bd_id=0, mem=outTensor, sizes=[1, 1, 1, 64] | ||
) | ||
ipu_dma_memcpy_nd( | ||
metadata="in0", bd_id=1, mem=inTensor, sizes=[1, 1, 1, 64] | ||
) | ||
ipu_sync(column=0, row=0, direction=0, channel=0) | ||
|
||
print(ctx.module) | ||
|
||
my_first_aie_program() |
Oops, something went wrong.