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

[asplos] update run_on_ipu #1271

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion programming_examples/basic/eltwise_exp/run.lit
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
// RUN: %python %S/aie2.py ipu 0 | aie-opt -cse -canonicalize -o ./aie.mlir
// RUN: %python aiecc.py --aie-generate-cdo --aie-generate-ipu --no-compile-host --xclbin-name=aie.xclbin --ipu-insts-name=insts.txt ./aie.mlir
// RUN: g++-13 %S/test.cpp -o test.exe -std=c++23 -Wall -I%S/../../../runtime_lib/test_lib %S/../../../runtime_lib/test_lib/test_utils.cpp %xrt_flags -lrt -lstdc++ -lboost_program_options -lboost_filesystem
// RUN: ./test.exe -x aie.xclbin -k MLIR_AIE -i insts.txt | FileCheck %s
// RUN: %run_on_ipu ./test.exe -x aie.xclbin -k MLIR_AIE -i insts.txt | FileCheck %s
// CHECK: PASS!
92 changes: 3 additions & 89 deletions utils/run_on_ipu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,14 @@
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Execute a command while pre-staging for AIE driver some .xclbin firmware and
# clean up the firmware stage after execution.
# This script assumes that the path of one xclbin
# appears in the argument list

# Old AIE driver
linux_driver_version=""
# Where the device driver finds the firmware to be loaded.
FIRMWARE_DIR=/lib/firmware/amdipu/1502
# The AIE device model
NPU_DEVICE=Phoenix
if [[ -d /lib/firmware/amdnpu/1502_00 ]]; then
# New AIE driver naming and firmware location starting with Linux 6.8
linux_driver_version="6.8"
FIRMWARE_DIR=/lib/firmware/amdnpu/1502_00
NPU_DEVICE=NPU1
fi
# Don't require root.
export XRT_HACK_UNSECURE_LOADING_XCLBIN=1

XRT_DIR=/opt/xilinx/xrt
source $XRT_DIR/setup.sh

# Get the UUID of the XCLBIN, used by the Linux kernel driver to access it
xclbin_uuid() {
local xclbin_file_name=$1
local uuid=$($XRT_DIR/bin/xclbinutil --info -i $xclbin_file_name \
| grep 'UUID (xclbin)' | awk '{print $3}')
echo "$uuid"
}

# Install the XCLBIN file so it can be consumed by the Linux kernel driver
stage_xclbin() {
local npu_device=$1
local xclbin_file_name=$2
if [[ $linux_driver_version ]]; then
# There is a bug in the device driver which prevent loading an XCLBIN if it
# is accessed through a symbolic link which is not owned by root. So just
# skip the symbolic link installed by the official XDNA XRT staging script
# and do some manual work instead
cp -a $xclbin_file_name \
$FIRMWARE_DIR/$(xclbin_uuid $xclbin_file_name).xclbin
else
# Use the official XDNA XRT staging script which requires running as root
$XRT_DIR/amdxdna/setup_xclbin_firmware.sh \
-dev $npu_device -xclbin $xclbin_file_name
fi
}

# Unstage the XCLBIN file
rm_xclbin() {
local XCLBIN_FN=$1
if [ -f "$XCLBIN_FN" ] && [ x"${XCLBIN_FN##*.}" == x"xclbin" ]; then
local UUID=$(xclbin_uuid $XCLBIN_FN)
if [[ $linux_driver_version ]]; then
# Remove the XCLBIN file
rm $FIRMWARE_DIR/$UUID.xclbin
else
# Remove the XCLBIN file pointed by the link
rm -rf "$(readlink -f $FIRMWARE_DIR/$UUID.xclbin)"
# Remove the link
unlink $FIRMWARE_DIR/$UUID.xclbin
fi
fi

# -xtype l tests for links that are broken (it is the opposite of -type)
find $FIRMWARE_DIR -xtype l -delete;
}

if [ x"$1" == x"--clean-xclbin" ]; then
rm_xclbin $2
exit 0
fi

XCLBIN_FN=""
# Analyze all the command arguments to find some .xclbin
for f in "$@"; do
if [ -f "$f" ]; then
filename=$(basename "$f")
extension="${f##*.}"
if [ x"$extension" = x"xclbin" ]; then
XCLBIN_FN="$filename"
# Stage the .xclbin to be loaded by the command execution later
stage_xclbin $NPU_DEVICE $XCLBIN_FN
break
fi
fi
done

# Execute the commands and its arguments
"$@"
err=$?

# TODO: use setup_xclbin_firmware.sh -clean instead
if [ x"$XCLBIN_FN" != x"" ]; then
rm_xclbin $XCLBIN_FN
fi

exit $err
exit $err
Loading