Skip to content

Commit

Permalink
VITIS-11750 Create a wrapper (e.g. npu-smi) on top of xbutil
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Chane <[email protected]>
  • Loading branch information
rchane committed May 21, 2024
1 parent 8d07049 commit 5425686
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/xbutil2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ set(XBUTIL_V2_SRCS ${XBUTIL_V2_BASE_FILES} ${XBUTIL_V2_SUBCMD_FILES})
# Determine the name of the executable
if(WIN32)
set(XBUTIL2_NAME "xbutil") # Yes, on windows the file name will be xbutil
set(XRT_HELPER_SCRIPTS "xbutil" "xbutil.bat")
set(XRT_HELPER_SCRIPTS "npu-smi" "npu-smi.bat" "xbutil" "xbutil.bat")
else()
set(XBUTIL2_NAME "xbutil2")
set(XRT_HELPER_SCRIPTS "xbutil")
set(XRT_HELPER_SCRIPTS "npu-smi" "xbutil")
endif()

add_executable(${XBUTIL2_NAME} ${XBUTIL_V2_SRCS})
Expand Down
65 changes: 65 additions & 0 deletions src/runtime_src/core/tools/xbutil2/npu-smi
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2020-2022 Xilinx, Inc.
#

# -- Detect a Windows environment and automatically switch to the .bat file
if [[ "`uname`" == windows32* ]] || [[ "`uname`" == CYGWIN* ]] ; then
trap "" INT
"$0.bat" "$@"
exit $?
fi

# Working variables
XRT_PROG=xbutil2

# -- Examine the options
XRTWARP_PROG_ARGS_size=0
XRTWRAP_PROG_ARGS=()
while [ $# -gt 0 ]; do
case "$1" in
# Indicates that the legacy was specified
-legacy|--legacy)
echo "----------------------------------------------------------------------"
echo "Error: Obsoleted option
The --legacy option is no longer supported.
For legacy migration, please refer to the XRT github.io utility
migration guide.
Commands, options, arguments and their descriptions can also be
reported via the --help option."
echo "----------------------------------------------------------------------"
exit 1
;;
# Copy the options the remaining options
*)
XRTWRAP_PROG_ARGS[$XRTWARP_PROG_ARGS_size]="$1"
XRTWARP_PROG_ARGS_size=$(($XRTWARP_PROG_ARGS_size + 1))
shift
;;
esac
done

# -- Find loader directory
XRT_LOADER_DIR="`dirname \"$0\"`"

# For edge platforms loader is not required as tools are in standard location(/usr).
# So calling unwrapped tool from this script itself.
if [[ $XRT_LOADER_DIR =~ "/usr" ]]; then
"${XRT_LOADER_DIR}/unwrapped/${XRT_PROG}" "${XRTWRAP_PROG_ARGS[@]}"
exit 0
fi

# Call loader for dc platforms
XRT_LOADER="${XRT_LOADER_DIR}/unwrapped/loader"
if [ ! -f "$XRT_LOADER" ]; then
echo "ERROR: Could not find 64-bit loader executable."
echo "ERROR: ${XRT_LOADER} does not exist."
exit 1
fi

"${XRT_LOADER}" -exec ${XRT_PROG} "${XRTWRAP_PROG_ARGS[@]}"
52 changes: 52 additions & 0 deletions src/runtime_src/core/tools/xbutil2/npu-smi.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@echo off
setlocal

REM Working variables
set XRT_PROG=xbutil

REM -- Examine the options
set XRTWRAP_PROG_ARGS=
:parseArgs
if [%1] == [] (
goto argsParsed
) else (
REM New option
if [%1] == [-new] (
echo INFO: The 'new' option is only valid for the linux version of xbmgmt
shift
) else (
if [%1] == [--new] (
echo INFO: The 'new' option is only valid for the linux version of xbmgmt
shift
) else (
REM Unknown option, must be associated with the program
set XRTWRAP_PROG_ARGS=%XRTWRAP_PROG_ARGS% %1
shift
)
))
goto parseArgs
:argsParsed


REM -- Find the loader from the current directory. If it exists.
set XRT_LOADER=%~dp0unwrapped\loader.bat

REM -- Find loader from the PATH. If it exists.
FOR /F "tokens=* USEBACKQ" %%F IN (`where xbutil`) DO (
set XBUTIL_PATH=%%~dpF
)

REM -- If the loader is not found in the current directory use the PATH.
if not exist %XRT_LOADER% (
set XRT_LOADER=%XBUTIL_PATH%unwrapped\loader.bat
)

REM -- Loader is not within the current directory or PATH. All hope is lost.
if not exist %XRT_LOADER% (
echo ERROR: Could not find 64-bit loader executable.
echo ERROR: %XRT_LOADER% does not exist.
GOTO:EOF
)

%XRT_LOADER% -exec %XRT_PROG% %XRTWRAP_PROG_ARGS%

0 comments on commit 5425686

Please sign in to comment.