From 001c6e3c48a616c37530bb33cd37a7f6b822670c Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Wed, 24 May 2023 11:39:22 -0700 Subject: [PATCH 01/16] VITIS-6327 CMake broken when invoking xclbinutil Signed-off-by: Daniel Benusovich --- build/build_edge.sh | 4 +- .../core/edge/ps_kernels/xrt/CMakeLists.txt | 3 +- .../xrt/instance_query/CMakeLists.txt | 9 +- .../edge/ps_kernels/xrt/tests/CMakeLists.txt | 4 + .../xrt/tests/validate/CMakeLists.txt | 4 + .../validate/ps_validate_test/CMakeLists.txt | 38 +++++ .../validate/ps_validate_test/ps_validate.cpp | 34 ++++ src/runtime_src/tools/scripts/pkgapu.sh | 30 +++- tests/validate/ps_validate_test/src/Makefile | 150 ++++++++++++++++++ tests/validate/ps_validate_test/src/utils.mk | 104 ++++++++++++ 10 files changed, 371 insertions(+), 9 deletions(-) create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/CMakeLists.txt create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp create mode 100644 tests/validate/ps_validate_test/src/Makefile create mode 100644 tests/validate/ps_validate_test/src/utils.mk diff --git a/build/build_edge.sh b/build/build_edge.sh index 8c1ea547464..068cbbf7187 100755 --- a/build/build_edge.sh +++ b/build/build_edge.sh @@ -374,8 +374,8 @@ echo "CONFIG_YOCTO_MACHINE_NAME=\"${YOCTO_MACHINE}\"" echo "CONFIG_YOCTO_MACHINE_NAME=\"${YOCTO_MACHINE}\"" >> project-spec/configs/config #Uncomment the following 2 lines to change TMP_DIR location -#echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" -#echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" >> project-spec/configs/config +echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" +echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" >> project-spec/configs/config # Build package echo " * Performing PetaLinux Build (from: ${PWD})" diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt index f312610c536..350eecca7e4 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. # add_subdirectory(instance_query) +add_subdirectory(tests) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/instance_query/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/instance_query/CMakeLists.txt index 739d59e812f..9db668001c2 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/instance_query/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/instance_query/CMakeLists.txt @@ -3,8 +3,8 @@ # set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") -add_library(instance_query OBJECT - instance_query.cpp +add_library(instance_query SHARED + "instance_query.cpp" ) set_target_properties(instance_query PROPERTIES @@ -12,6 +12,11 @@ set_target_properties(instance_query PROPERTIES SOVERSION ${XRT_SOVERSION} ) +target_link_libraries(instance_query + PRIVATE + ${Boost_FILESYSTEM_LIBRARY} + ) + install (TARGETS instance_query EXPORT xrt-targets LIBRARY DESTINATION ${PS_KERNEL_INSTALL_DIR} diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/CMakeLists.txt new file mode 100644 index 00000000000..0256f523d15 --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/CMakeLists.txt @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# +add_subdirectory(validate) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt new file mode 100644 index 00000000000..e7e47b6ba35 --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# +add_subdirectory(ps_validate_test) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt new file mode 100644 index 00000000000..a2aaf1271e2 --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. +# +set(XCLBIN_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/xclbin_lib") +set(XCLBIN_KERNELS_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/xclbin_lib/ps_kernels") + +set(PS_KERNEL_NAME "ps_validate") +set(XCLBIN_NAME "ps_validate.xclbin") + +add_library(${PS_KERNEL_NAME} SHARED + "ps_validate.cpp" + ) + +set_target_properties(${PS_KERNEL_NAME} PROPERTIES + VERSION ${XRT_VERSION_STRING} + SOVERSION ${XRT_SOVERSION} + ) + +install (TARGETS ${PS_KERNEL_NAME} + EXPORT xrt-targets + LIBRARY DESTINATION ${XCLBIN_KERNELS_INSTALL_DIR} + ) + +set(PS_KERNEL_LOCATION "${XCLBIN_KERNELS_INSTALL_DIR}/${PS_KERNEL_NAME}.so") + +add_custom_command( + OUTPUT ${XCLBIN_NAME} + COMMAND xclbinutil --output ${XCLBIN_NAME} --add-pskernel ${PS_KERNEL_LOCATION} + DEPENDS ${PS_KERNEL_NAME} + ) + +add_custom_target(xclbin ALL + DEPENDS ${XCLBIN_NAME} + ) + +install (FILES ${XCLBIN_NAME} + DESTINATION ${XCLBIN_KERNELS_INSTALL_DIR} + ) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp new file mode 100644 index 00000000000..0dd011a76e9 --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "xrt/xrt_kernel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "core/edge/include/sk_types.h" + +// User private data structure container (context object) definition +class xrtHandles : public pscontext +{ +public: +}; + + +__attribute__((visibility("default"))) +int hello_world(int *input, int *output, int count, struct xrtHandles *xrtHandle) +{ + memcpy(output, input, count*sizeof(int)); + + return 0; +} + +#ifdef __cplusplus +} +#endif diff --git a/src/runtime_src/tools/scripts/pkgapu.sh b/src/runtime_src/tools/scripts/pkgapu.sh index d9fa4df226c..e3d6606a7d0 100755 --- a/src/runtime_src/tools/scripts/pkgapu.sh +++ b/src/runtime_src/tools/scripts/pkgapu.sh @@ -298,13 +298,15 @@ if [ -e $IMAGES_DIR/sdk.sh ]; then echo "sdk.sh exists copy it to apu package" cp $IMAGES_DIR/sdk.sh $SDK fi -# Generate PS Kernel xclbin -# Hardcoding the ps kernel xclbin name to ps_kernels.xclbin -# We can create one xclbin per PS Kernel also based on future requirements -PS_KERNELS_XCLBIN="$BUILD_DIR/lib/firmware/xilinx/ps_kernels/ps_kernels.xclbin" + #Extract ps_kernels_lib from rootfs tar tar -C $BUILD_DIR -xf $IMAGES_DIR/rootfs.tar.gz ./usr/lib/ps_kernels_lib if [ $? -eq 0 ]; then + # Generate PS Kernel xclbin + # This xclbin contains all the built-in kernels + # Hardcoding the ps kernel xclbin name to ps_kernels.xclbin + # We can create one xclbin per PS Kernel also based on future requirements + PS_KERNELS_XCLBIN="$BUILD_DIR/lib/firmware/xilinx/ps_kernels/ps_kernels.xclbin" PS_KERNEL_DIR=$BUILD_DIR/usr/lib/ps_kernels_lib ps_kernel_command="xclbinutil --output $PS_KERNELS_XCLBIN " pk_exists=0 @@ -319,8 +321,28 @@ if [ $? -eq 0 ]; then echo "Running $ps_kernel_command" $ps_kernel_command fi + + # Extract generated PS Kernel xclbins here + # This handles the xclbins required for device validation + PS_KERNEL_XCLBINS_DIR="$BUILD_DIR/lib/firmware/xilinx/xclbins" + PS_KERNEL_DIR=$BUILD_DIR/usr/lib/xclbin_lib + ps_kernel_command="xclbinutil --output $PS_KERNELS_XCLBIN " + pk_exists=0 + for entry in "$PS_KERNEL_DIR"/*.so + do + pk_exists=1 + ps_kernel_command+=" --add-pskernel $entry" + done + # Generate xclbin if atleast one PS Kernel exists + if [ $pk_exists -eq 1 ]; then + # Run final xclbinutil command to generate the PS Kernels xclbin + echo "Running $ps_kernel_command" + $ps_kernel_command + fi + fi + dodeb $INSTALL_ROOT dorpm $INSTALL_ROOT diff --git a/tests/validate/ps_validate_test/src/Makefile b/tests/validate/ps_validate_test/src/Makefile new file mode 100644 index 00000000000..8834f85cefa --- /dev/null +++ b/tests/validate/ps_validate_test/src/Makefile @@ -0,0 +1,150 @@ +# +# Copyright 2022 Xilinx, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# makefile-generator v1.0.3 +# + +############################## Help Section ############################## +.PHONY: help + +help:: + $(ECHO) "Makefile Usage:" + $(ECHO) " make all TARGET= PLATFORM= EDGE_COMMON_SW=." + $(ECHO) " Command to generate the design for specified Target and Shell." + $(ECHO) "" + $(ECHO) " make clean " + $(ECHO) " Command to remove the generated non-hardware files." + $(ECHO) "" + $(ECHO) " make cleanall" + $(ECHO) " Command to remove all the generated files." + $(ECHO) "" + $(ECHO) " make test PLATFORM=" + $(ECHO) " Command to run the application. This is same as 'run' target but does not have any makefile dependency." + $(ECHO) "" + $(ECHO) " make run TARGET= PLATFORM= EDGE_COMMON_SW=" + $(ECHO) " Command to run application in emulation." + $(ECHO) "" + $(ECHO) " make build TARGET= PLATFORM= EDGE_COMMON_SW=" + $(ECHO) " Command to build xclbin application." + $(ECHO) "" + $(ECHO) " make host" + $(ECHO) " Command to build host application." + $(ECHO) " EDGE_COMMON_SW is required for SoC shells. Please download and use the pre-built image from - " + $(ECHO) " https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-platforms.html" + $(ECHO) "" + $(ECHO) " make clean " + $(ECHO) " Command to remove the generated non-hardware files." + $(ECHO) "" + $(ECHO) " make cleanall" + $(ECHO) " Command to remove all the generated files." + $(ECHO) "" + + +############################## Setting up Project Variables ############################## +# Points to top directory of Git repository +PWD = $(shell readlink -f .) + +TARGET := hw +HOST_ARCH := x86 +SYSROOT := $(EDGE_COMMON_SW)/sysroots/cortexa72-cortexa53-xilinx-linux + +include ./utils.mk + +XSA := +ifneq ($(PLATFORM), ) +XSA := $(call device2xsa, $(PLATFORM)) +endif +TEMP_DIR := ./_x.$(TARGET).$(XSA) +BUILD_DIR := ./build_dir.$(TARGET).$(XSA) + +CMD_ARGS = -p $(GEN_DIR) + +CXXFLAGS += $(opencl_CXXFLAGS) -Wall -O0 -g -std=c++1y +LDFLAGS += $(opencl_LDFLAGS) + +########################## Checking if PLATFORM in allowlist ####################### +PLATFORM_BLOCKLIST += zc vck190 2019 2018 + +############################## Setting up Host Variables ############################## +#Include Required Host Source Files +HOST_SRCS += ./host.cpp +# Host compiler global settings +CXXFLAGS += -fmessage-length=0 -I$(XILINX_XRT)/include +LDFLAGS += -lrt -lstdc++ -lxrt_core -lxrt_coreutil -lpthread -luuid -L$(XILINX_XRT)/lib +LDFLAGS += -lboost_filesystem -lboost_system + +############################## Setting up Kernel Variables ############################## +# Kernel compiler global settings +EXECUTABLE = ./ps_validate_test.exe + +############################## Setting up PS Kernel Variables ############################## +CROSSCXX := $(XILINX_VITIS)/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ +CROSSCFLAGS = -I$(XILINX_XRT)/include -I$(SYSROOT)/usr/include/xrt -I$(SYSROOT)/ -fPIC -fvisibility=hidden -lrt --sysroot=$(SYSROOT) -Ilibs +CROSSCFLAGS += -Wall -O2 -g +CROSSLDFLAGS = -shared -lxrt_coreutil -L$(SYSROOT)/usr/lib -lpthread -lrt -ldl -lcrypt -lstdc++ --sysroot=$(SYSROOT) + +ps_target = ps_validate.so +ps_OBJS = ps_validate.o + +############################## Declaring Binary Containers ############################## +BINARY_NAME = ps_validate +BINARY_CONTAINERS += $(BINARY_NAME).xclbin + +############################## Setting Targets ############################## +CP = cp -rf + +.PHONY: all clean cleanall docs +all: check-platform check-device check-vitis check_edge_sw $(EXECUTABLE) $(ps_target) $(BINARY_CONTAINERS) + +.PHONY: host +host: $(EXECUTABLE) + +.PHONY: build +build: check-vitis check-device check_edge_sw $(ps_target) $(BINARY_CONTAINERS) + +############################## Setting Rules for PS Kernel objects (Building PS Kernels) ############################## +$(ps_OBJS) : ./ps_validate.c + $(CROSSCXX) -c $(CROSSCFLAGS) -o $@ $< + +$(ps_target): $(ps_OBJS) + $(CROSSCXX) $< $(CROSSLDFLAGS) -o $@ + +############################## Setting Rules for Binary Containers (Building Kernels) ############################## +$(BINARY_CONTAINERS): + xclbinutil --add-pskernel $(ps_target) --output $(BINARY_CONTAINERS) --force + +############################## Setting Rules for Host (Building Host Executable) ############################## +$(EXECUTABLE): $(HOST_SRCS) | check-xrt + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) + +############################## Setting Essential Checks and Running Rules ############################## +run: all + $(EXECUTABLE) $(CMD_ARGS) + + +.PHONY: test +test: $(EXECUTABLE) + $(EXECUTABLE) $(CMD_ARGS) + +############################## Cleaning Rules ############################## +# Cleaning stuff +clean: + -$(RMDIR) $(EXECUTABLE) $(XCLBIN)/{*sw_emu*,*hw_emu*} + -$(RMDIR) profile_* TempConfig system_estimate.xtxt *.rpt *.csv + -$(RMDIR) src/*.ll *v++* .Xil emconfig.json dltmp* xmltmp* *.log *.jou *.wcfg *.wdb + +cleanall: clean + -$(RMDIR) build_dir* + -$(RMDIR) package.* + -$(RMDIR) _x* *xclbin.run_summary qemu-memory-_* emulation _vimage pl* start_simulation.sh *.xclbin \ No newline at end of file diff --git a/tests/validate/ps_validate_test/src/utils.mk b/tests/validate/ps_validate_test/src/utils.mk new file mode 100644 index 00000000000..09fba14b914 --- /dev/null +++ b/tests/validate/ps_validate_test/src/utils.mk @@ -0,0 +1,104 @@ +#+------------------------------------------------------------------------------- +# The following parameters are assigned with default values. These parameters can +# be overridden through the make command line +#+------------------------------------------------------------------------------- + +DEBUG := no + +#Generates debug summary report +ifeq ($(DEBUG), yes) +VPP_LDFLAGS += --dk list_ports +endif + +ifneq ($(TARGET), hw) +VPP_FLAGS += -g +endif + +#Setting PLATFORM +ifeq ($(PLATFORM),) +ifneq ($(DEVICE),) +$(warning WARNING: DEVICE is deprecated in make command. Please use PLATFORM instead) +PLATFORM := $(DEVICE) +endif +endif + +#Platform Architecture +ifneq ($(PLATFORM),) +DEV_ARCH := $(shell platforminfo -p $(PLATFORM) | grep 'FPGA Family' | sed 's/.*://' | sed '/ai_engine/d' | sed 's/^[[:space:]]*//') +endif + +check_edge_sw: +ifndef EDGE_COMMON_SW + $(error EDGE_COMMON_SW variable is not set, please download and use the pre-built image from https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-platforms.html) +endif + +#Checks for XILINX_VITIS +check-vitis: +ifndef XILINX_VITIS + $(error XILINX_VITIS variable is not set, please set correctly using "source /Vitis//settings64.sh" and rerun) +endif + +#Checks for XILINX_XRT +check-xrt: +ifndef XILINX_XRT + $(error XILINX_XRT variable is not set, please set correctly using "source /opt/xilinx/xrt/setup.sh" and rerun) +endif + +check-device: + @set -eu; \ + inallowlist=False; \ + inblocklist=False; \ + if [ "$(PLATFORM_ALLOWLIST)" = "" ]; \ + then inallowlist=True; \ + fi; \ + for dev in $(PLATFORM_ALLOWLIST); \ + do if [[ $$(echo $(PLATFORM) | grep $$dev) != "" ]]; \ + then inallowlist=True; fi; \ + done ;\ + for dev in $(PLATFORM_BLOCKLIST); \ + do if [[ $$(echo $(PLATFORM) | grep $$dev) != "" ]]; \ + then inblocklist=True; fi; \ + done ;\ + if [[ $$inblocklist == True ]]; \ + then echo "[ERROR]: This example is not supported for $(PLATFORM)."; exit 1;\ + fi; \ + if [[ $$inallowlist == False ]]; \ + then echo "[Warning]: The platform $(PLATFORM) not in allowlist."; \ + fi; + +#Checks for Correct architecture +ifneq ($(HOST_ARCH), $(filter $(HOST_ARCH),x86)) +$(error HOST_ARCH variable not set correctly, supported HOST_ARCH is x86 only) +endif + +#Setting CXX +CXX := g++ + +check-platform: +ifndef PLATFORM + $(error PLATFORM not set. Please set the PLATFORM properly and rerun. Run "make help" for more details.) +endif + +# device2xsa - create a filesystem friendly name from device name +# $(1) - full name of device +device2xsa = $(strip $(patsubst %.xpfm, % , $(shell basename $(PLATFORM)))) + +############################## Deprecated Checks and Running Rules ############################## +check: + $(ECHO) "WARNING: \"make check\" is a deprecated command. Please use \"make run\" instead" + make run + +exe: + $(ECHO) "WARNING: \"make exe\" is a deprecated command. Please use \"make host\" instead" + make host + +# Cleaning stuff +RM = rm -f +RMDIR = rm -rf + +ECHO:= @echo + +docs: README.rst + +README.rst: description.json + $(XF_PROJ_ROOT)/common/utility/readme_gen/readme_gen.py description.json \ No newline at end of file From 977ca8acde5e43f18e3fd8c20cdaa693a6a5969c Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Thu, 25 May 2023 15:01:33 -0700 Subject: [PATCH 02/16] VITIS-6327 build creates correct ps kernel images. No xclbin generation yet Signed-off-by: Daniel Benusovich --- .../validate/ps_validate_test/CMakeLists.txt | 15 ++++++++------- .../validate/ps_validate_test/ps_validate.cpp | 17 +++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index a2aaf1271e2..6078f9f2372 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -16,17 +16,18 @@ set_target_properties(${PS_KERNEL_NAME} PROPERTIES SOVERSION ${XRT_SOVERSION} ) -install (TARGETS ${PS_KERNEL_NAME} - EXPORT xrt-targets - LIBRARY DESTINATION ${XCLBIN_KERNELS_INSTALL_DIR} - ) +target_link_libraries(${PS_KERNEL_NAME} + PRIVATE + xrt_coreutil + xrt_core +) -set(PS_KERNEL_LOCATION "${XCLBIN_KERNELS_INSTALL_DIR}/${PS_KERNEL_NAME}.so") +set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") add_custom_command( OUTPUT ${XCLBIN_NAME} - COMMAND xclbinutil --output ${XCLBIN_NAME} --add-pskernel ${PS_KERNEL_LOCATION} - DEPENDS ${PS_KERNEL_NAME} + COMMAND "xclbinutil" --output ${XCLBIN_NAME} --add-pskernel ${PS_KERNEL_LOCATION} + DEPENDS ${PS_KERNEL_NAME} "xclbinutil" ) add_custom_target(xclbin ALL diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp index 0dd011a76e9..420b5bb8129 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp @@ -1,16 +1,6 @@ -#include -#include -#include -#include -#include -#include -#include -#include #include "xrt/xrt_kernel.h" -#ifdef __cplusplus -extern "C" { -#endif +#include #include "core/edge/include/sk_types.h" @@ -20,6 +10,9 @@ class xrtHandles : public pscontext public: }; +#ifdef __cplusplus +extern "C" { +#endif __attribute__((visibility("default"))) int hello_world(int *input, int *output, int count, struct xrtHandles *xrtHandle) @@ -31,4 +24,4 @@ int hello_world(int *input, int *output, int count, struct xrtHandles *xrtHandle #ifdef __cplusplus } -#endif +#endif \ No newline at end of file From 2185671ee1992307aba87b381cd32c175976ed1b Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Fri, 2 Jun 2023 11:29:22 -0700 Subject: [PATCH 03/16] VITIS-6327 Remove unused Makefiles for building xclbins Signed-off-by: Daniel Benusovich --- tests/validate/ps_validate_test/src/Makefile | 150 ------------------- tests/validate/ps_validate_test/src/utils.mk | 104 ------------- 2 files changed, 254 deletions(-) delete mode 100644 tests/validate/ps_validate_test/src/Makefile delete mode 100644 tests/validate/ps_validate_test/src/utils.mk diff --git a/tests/validate/ps_validate_test/src/Makefile b/tests/validate/ps_validate_test/src/Makefile deleted file mode 100644 index 8834f85cefa..00000000000 --- a/tests/validate/ps_validate_test/src/Makefile +++ /dev/null @@ -1,150 +0,0 @@ -# -# Copyright 2022 Xilinx, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# makefile-generator v1.0.3 -# - -############################## Help Section ############################## -.PHONY: help - -help:: - $(ECHO) "Makefile Usage:" - $(ECHO) " make all TARGET= PLATFORM= EDGE_COMMON_SW=." - $(ECHO) " Command to generate the design for specified Target and Shell." - $(ECHO) "" - $(ECHO) " make clean " - $(ECHO) " Command to remove the generated non-hardware files." - $(ECHO) "" - $(ECHO) " make cleanall" - $(ECHO) " Command to remove all the generated files." - $(ECHO) "" - $(ECHO) " make test PLATFORM=" - $(ECHO) " Command to run the application. This is same as 'run' target but does not have any makefile dependency." - $(ECHO) "" - $(ECHO) " make run TARGET= PLATFORM= EDGE_COMMON_SW=" - $(ECHO) " Command to run application in emulation." - $(ECHO) "" - $(ECHO) " make build TARGET= PLATFORM= EDGE_COMMON_SW=" - $(ECHO) " Command to build xclbin application." - $(ECHO) "" - $(ECHO) " make host" - $(ECHO) " Command to build host application." - $(ECHO) " EDGE_COMMON_SW is required for SoC shells. Please download and use the pre-built image from - " - $(ECHO) " https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-platforms.html" - $(ECHO) "" - $(ECHO) " make clean " - $(ECHO) " Command to remove the generated non-hardware files." - $(ECHO) "" - $(ECHO) " make cleanall" - $(ECHO) " Command to remove all the generated files." - $(ECHO) "" - - -############################## Setting up Project Variables ############################## -# Points to top directory of Git repository -PWD = $(shell readlink -f .) - -TARGET := hw -HOST_ARCH := x86 -SYSROOT := $(EDGE_COMMON_SW)/sysroots/cortexa72-cortexa53-xilinx-linux - -include ./utils.mk - -XSA := -ifneq ($(PLATFORM), ) -XSA := $(call device2xsa, $(PLATFORM)) -endif -TEMP_DIR := ./_x.$(TARGET).$(XSA) -BUILD_DIR := ./build_dir.$(TARGET).$(XSA) - -CMD_ARGS = -p $(GEN_DIR) - -CXXFLAGS += $(opencl_CXXFLAGS) -Wall -O0 -g -std=c++1y -LDFLAGS += $(opencl_LDFLAGS) - -########################## Checking if PLATFORM in allowlist ####################### -PLATFORM_BLOCKLIST += zc vck190 2019 2018 - -############################## Setting up Host Variables ############################## -#Include Required Host Source Files -HOST_SRCS += ./host.cpp -# Host compiler global settings -CXXFLAGS += -fmessage-length=0 -I$(XILINX_XRT)/include -LDFLAGS += -lrt -lstdc++ -lxrt_core -lxrt_coreutil -lpthread -luuid -L$(XILINX_XRT)/lib -LDFLAGS += -lboost_filesystem -lboost_system - -############################## Setting up Kernel Variables ############################## -# Kernel compiler global settings -EXECUTABLE = ./ps_validate_test.exe - -############################## Setting up PS Kernel Variables ############################## -CROSSCXX := $(XILINX_VITIS)/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++ -CROSSCFLAGS = -I$(XILINX_XRT)/include -I$(SYSROOT)/usr/include/xrt -I$(SYSROOT)/ -fPIC -fvisibility=hidden -lrt --sysroot=$(SYSROOT) -Ilibs -CROSSCFLAGS += -Wall -O2 -g -CROSSLDFLAGS = -shared -lxrt_coreutil -L$(SYSROOT)/usr/lib -lpthread -lrt -ldl -lcrypt -lstdc++ --sysroot=$(SYSROOT) - -ps_target = ps_validate.so -ps_OBJS = ps_validate.o - -############################## Declaring Binary Containers ############################## -BINARY_NAME = ps_validate -BINARY_CONTAINERS += $(BINARY_NAME).xclbin - -############################## Setting Targets ############################## -CP = cp -rf - -.PHONY: all clean cleanall docs -all: check-platform check-device check-vitis check_edge_sw $(EXECUTABLE) $(ps_target) $(BINARY_CONTAINERS) - -.PHONY: host -host: $(EXECUTABLE) - -.PHONY: build -build: check-vitis check-device check_edge_sw $(ps_target) $(BINARY_CONTAINERS) - -############################## Setting Rules for PS Kernel objects (Building PS Kernels) ############################## -$(ps_OBJS) : ./ps_validate.c - $(CROSSCXX) -c $(CROSSCFLAGS) -o $@ $< - -$(ps_target): $(ps_OBJS) - $(CROSSCXX) $< $(CROSSLDFLAGS) -o $@ - -############################## Setting Rules for Binary Containers (Building Kernels) ############################## -$(BINARY_CONTAINERS): - xclbinutil --add-pskernel $(ps_target) --output $(BINARY_CONTAINERS) --force - -############################## Setting Rules for Host (Building Host Executable) ############################## -$(EXECUTABLE): $(HOST_SRCS) | check-xrt - $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) - -############################## Setting Essential Checks and Running Rules ############################## -run: all - $(EXECUTABLE) $(CMD_ARGS) - - -.PHONY: test -test: $(EXECUTABLE) - $(EXECUTABLE) $(CMD_ARGS) - -############################## Cleaning Rules ############################## -# Cleaning stuff -clean: - -$(RMDIR) $(EXECUTABLE) $(XCLBIN)/{*sw_emu*,*hw_emu*} - -$(RMDIR) profile_* TempConfig system_estimate.xtxt *.rpt *.csv - -$(RMDIR) src/*.ll *v++* .Xil emconfig.json dltmp* xmltmp* *.log *.jou *.wcfg *.wdb - -cleanall: clean - -$(RMDIR) build_dir* - -$(RMDIR) package.* - -$(RMDIR) _x* *xclbin.run_summary qemu-memory-_* emulation _vimage pl* start_simulation.sh *.xclbin \ No newline at end of file diff --git a/tests/validate/ps_validate_test/src/utils.mk b/tests/validate/ps_validate_test/src/utils.mk deleted file mode 100644 index 09fba14b914..00000000000 --- a/tests/validate/ps_validate_test/src/utils.mk +++ /dev/null @@ -1,104 +0,0 @@ -#+------------------------------------------------------------------------------- -# The following parameters are assigned with default values. These parameters can -# be overridden through the make command line -#+------------------------------------------------------------------------------- - -DEBUG := no - -#Generates debug summary report -ifeq ($(DEBUG), yes) -VPP_LDFLAGS += --dk list_ports -endif - -ifneq ($(TARGET), hw) -VPP_FLAGS += -g -endif - -#Setting PLATFORM -ifeq ($(PLATFORM),) -ifneq ($(DEVICE),) -$(warning WARNING: DEVICE is deprecated in make command. Please use PLATFORM instead) -PLATFORM := $(DEVICE) -endif -endif - -#Platform Architecture -ifneq ($(PLATFORM),) -DEV_ARCH := $(shell platforminfo -p $(PLATFORM) | grep 'FPGA Family' | sed 's/.*://' | sed '/ai_engine/d' | sed 's/^[[:space:]]*//') -endif - -check_edge_sw: -ifndef EDGE_COMMON_SW - $(error EDGE_COMMON_SW variable is not set, please download and use the pre-built image from https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-platforms.html) -endif - -#Checks for XILINX_VITIS -check-vitis: -ifndef XILINX_VITIS - $(error XILINX_VITIS variable is not set, please set correctly using "source /Vitis//settings64.sh" and rerun) -endif - -#Checks for XILINX_XRT -check-xrt: -ifndef XILINX_XRT - $(error XILINX_XRT variable is not set, please set correctly using "source /opt/xilinx/xrt/setup.sh" and rerun) -endif - -check-device: - @set -eu; \ - inallowlist=False; \ - inblocklist=False; \ - if [ "$(PLATFORM_ALLOWLIST)" = "" ]; \ - then inallowlist=True; \ - fi; \ - for dev in $(PLATFORM_ALLOWLIST); \ - do if [[ $$(echo $(PLATFORM) | grep $$dev) != "" ]]; \ - then inallowlist=True; fi; \ - done ;\ - for dev in $(PLATFORM_BLOCKLIST); \ - do if [[ $$(echo $(PLATFORM) | grep $$dev) != "" ]]; \ - then inblocklist=True; fi; \ - done ;\ - if [[ $$inblocklist == True ]]; \ - then echo "[ERROR]: This example is not supported for $(PLATFORM)."; exit 1;\ - fi; \ - if [[ $$inallowlist == False ]]; \ - then echo "[Warning]: The platform $(PLATFORM) not in allowlist."; \ - fi; - -#Checks for Correct architecture -ifneq ($(HOST_ARCH), $(filter $(HOST_ARCH),x86)) -$(error HOST_ARCH variable not set correctly, supported HOST_ARCH is x86 only) -endif - -#Setting CXX -CXX := g++ - -check-platform: -ifndef PLATFORM - $(error PLATFORM not set. Please set the PLATFORM properly and rerun. Run "make help" for more details.) -endif - -# device2xsa - create a filesystem friendly name from device name -# $(1) - full name of device -device2xsa = $(strip $(patsubst %.xpfm, % , $(shell basename $(PLATFORM)))) - -############################## Deprecated Checks and Running Rules ############################## -check: - $(ECHO) "WARNING: \"make check\" is a deprecated command. Please use \"make run\" instead" - make run - -exe: - $(ECHO) "WARNING: \"make exe\" is a deprecated command. Please use \"make host\" instead" - make host - -# Cleaning stuff -RM = rm -f -RMDIR = rm -rf - -ECHO:= @echo - -docs: README.rst - -README.rst: description.json - $(XF_PROJ_ROOT)/common/utility/readme_gen/readme_gen.py description.json \ No newline at end of file From 15cb44846c410c3635802feaba2b5c2e1eb444fe Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Fri, 2 Jun 2023 14:21:59 -0700 Subject: [PATCH 04/16] VITIS-6327 Export of ps_validate xclbin complete Signed-off-by: Daniel Benusovich --- .../core/edge/ps_kernels/xrt/CMakeLists.txt | 8 ++++++- .../validate/ps_validate_test/CMakeLists.txt | 16 ++++++------- src/runtime_src/tools/scripts/pkgapu.sh | 23 ++++++------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt index 350eecca7e4..534b9792301 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt @@ -2,4 +2,10 @@ # Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. # add_subdirectory(instance_query) -add_subdirectory(tests) + +if (EXISTS "/opt/xilinx/xrt") + message(WARNING "XILINX_XRT is set! Generating ps kernel xclbins") + add_subdirectory(tests) +else() + message(WARNING "XILINX_XRT not set, skip generating ps kernel xclbins") +endif() diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index 6078f9f2372..66b777ff37c 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -1,8 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. # -set(XCLBIN_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/xclbin_lib") -set(XCLBIN_KERNELS_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/xclbin_lib/ps_kernels") +set(XCLBIN_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") set(PS_KERNEL_NAME "ps_validate") set(XCLBIN_NAME "ps_validate.xclbin") @@ -23,17 +22,18 @@ target_link_libraries(${PS_KERNEL_NAME} ) set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") +set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") add_custom_command( - OUTPUT ${XCLBIN_NAME} - COMMAND "xclbinutil" --output ${XCLBIN_NAME} --add-pskernel ${PS_KERNEL_LOCATION} - DEPENDS ${PS_KERNEL_NAME} "xclbinutil" + OUTPUT ${XCLBIN_LOCATION} + COMMAND "/opt/xilinx/xrt/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force + DEPENDS ${PS_KERNEL_NAME} ) add_custom_target(xclbin ALL - DEPENDS ${XCLBIN_NAME} + DEPENDS ${XCLBIN_LOCATION} ) -install (FILES ${XCLBIN_NAME} - DESTINATION ${XCLBIN_KERNELS_INSTALL_DIR} +install (FILES ${XCLBIN_LOCATION} + DESTINATION ${XCLBIN_INSTALL_DIR} ) diff --git a/src/runtime_src/tools/scripts/pkgapu.sh b/src/runtime_src/tools/scripts/pkgapu.sh index e3d6606a7d0..55f5f343ac2 100755 --- a/src/runtime_src/tools/scripts/pkgapu.sh +++ b/src/runtime_src/tools/scripts/pkgapu.sh @@ -299,6 +299,9 @@ if [ -e $IMAGES_DIR/sdk.sh ]; then cp $IMAGES_DIR/sdk.sh $SDK fi +# Output the required xclbins for validating and operating the APU +PS_KERNELS_XCLBIN_PATH="$BUILD_DIR/lib/firmware/xilinx/ps_kernels" +mkdir -p $PS_KERNELS_XCLBIN_PATH #Extract ps_kernels_lib from rootfs tar tar -C $BUILD_DIR -xf $IMAGES_DIR/rootfs.tar.gz ./usr/lib/ps_kernels_lib if [ $? -eq 0 ]; then @@ -306,7 +309,7 @@ if [ $? -eq 0 ]; then # This xclbin contains all the built-in kernels # Hardcoding the ps kernel xclbin name to ps_kernels.xclbin # We can create one xclbin per PS Kernel also based on future requirements - PS_KERNELS_XCLBIN="$BUILD_DIR/lib/firmware/xilinx/ps_kernels/ps_kernels.xclbin" + PS_KERNELS_XCLBIN="$PS_KERNELS_XCLBIN_PATH/ps_kernels.xclbin" PS_KERNEL_DIR=$BUILD_DIR/usr/lib/ps_kernels_lib ps_kernel_command="xclbinutil --output $PS_KERNELS_XCLBIN " pk_exists=0 @@ -322,27 +325,15 @@ if [ $? -eq 0 ]; then $ps_kernel_command fi - # Extract generated PS Kernel xclbins here + # Extract generated xclbins here # This handles the xclbins required for device validation - PS_KERNEL_XCLBINS_DIR="$BUILD_DIR/lib/firmware/xilinx/xclbins" - PS_KERNEL_DIR=$BUILD_DIR/usr/lib/xclbin_lib - ps_kernel_command="xclbinutil --output $PS_KERNELS_XCLBIN " - pk_exists=0 - for entry in "$PS_KERNEL_DIR"/*.so + for entry in "$PS_KERNEL_DIR"/*.xclbin do - pk_exists=1 - ps_kernel_command+=" --add-pskernel $entry" + cp $entry $PS_KERNELS_XCLBIN_PATH done - # Generate xclbin if atleast one PS Kernel exists - if [ $pk_exists -eq 1 ]; then - # Run final xclbinutil command to generate the PS Kernels xclbin - echo "Running $ps_kernel_command" - $ps_kernel_command - fi fi - dodeb $INSTALL_ROOT dorpm $INSTALL_ROOT From 3ca793b63a498675fe56d359c46642e667dc65e6 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Tue, 6 Jun 2023 17:06:16 -0700 Subject: [PATCH 05/16] VITIS-6327 Non functional. Convert CMake xclbinutil usage into pkgapu. pkgapu not able to create xclbins due to missing symbols in ps kernel libraries Signed-off-by: Daniel Benusovich --- build/build_edge.sh | 4 +-- .../validate/ps_validate_test/CMakeLists.txt | 23 +++---------- src/runtime_src/tools/scripts/pkgapu.sh | 33 +++++-------------- 3 files changed, 16 insertions(+), 44 deletions(-) diff --git a/build/build_edge.sh b/build/build_edge.sh index 068cbbf7187..8c1ea547464 100755 --- a/build/build_edge.sh +++ b/build/build_edge.sh @@ -374,8 +374,8 @@ echo "CONFIG_YOCTO_MACHINE_NAME=\"${YOCTO_MACHINE}\"" echo "CONFIG_YOCTO_MACHINE_NAME=\"${YOCTO_MACHINE}\"" >> project-spec/configs/config #Uncomment the following 2 lines to change TMP_DIR location -echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" -echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" >> project-spec/configs/config +#echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" +#echo "CONFIG_TMP_DIR_LOCATION=\"/scratch/${USER}/petalinux-top/$PETALINUX_VER\"" >> project-spec/configs/config # Build package echo " * Performing PetaLinux Build (from: ${PWD})" diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index 66b777ff37c..45417bf3ffb 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -1,10 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. # -set(XCLBIN_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") +set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") set(PS_KERNEL_NAME "ps_validate") -set(XCLBIN_NAME "ps_validate.xclbin") add_library(${PS_KERNEL_NAME} SHARED "ps_validate.cpp" @@ -21,19 +20,7 @@ target_link_libraries(${PS_KERNEL_NAME} xrt_core ) -set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") -set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") - -add_custom_command( - OUTPUT ${XCLBIN_LOCATION} - COMMAND "/opt/xilinx/xrt/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force - DEPENDS ${PS_KERNEL_NAME} - ) - -add_custom_target(xclbin ALL - DEPENDS ${XCLBIN_LOCATION} - ) - -install (FILES ${XCLBIN_LOCATION} - DESTINATION ${XCLBIN_INSTALL_DIR} - ) +install (TARGETS ${PS_KERNEL_NAME} + EXPORT xrt-targets + LIBRARY DESTINATION ${PS_KERNEL_INSTALL_DIR} +) diff --git a/src/runtime_src/tools/scripts/pkgapu.sh b/src/runtime_src/tools/scripts/pkgapu.sh index 55f5f343ac2..7c6fd9f4a18 100755 --- a/src/runtime_src/tools/scripts/pkgapu.sh +++ b/src/runtime_src/tools/scripts/pkgapu.sh @@ -300,38 +300,23 @@ if [ -e $IMAGES_DIR/sdk.sh ]; then fi # Output the required xclbins for validating and operating the APU -PS_KERNELS_XCLBIN_PATH="$BUILD_DIR/lib/firmware/xilinx/ps_kernels" -mkdir -p $PS_KERNELS_XCLBIN_PATH #Extract ps_kernels_lib from rootfs tar tar -C $BUILD_DIR -xf $IMAGES_DIR/rootfs.tar.gz ./usr/lib/ps_kernels_lib if [ $? -eq 0 ]; then - # Generate PS Kernel xclbin - # This xclbin contains all the built-in kernels - # Hardcoding the ps kernel xclbin name to ps_kernels.xclbin - # We can create one xclbin per PS Kernel also based on future requirements - PS_KERNELS_XCLBIN="$PS_KERNELS_XCLBIN_PATH/ps_kernels.xclbin" + # Generate the output directory + PS_KERNELS_XCLBIN_PATH="$BUILD_DIR/lib/firmware/xilinx/ps_kernels" + mkdir -p $PS_KERNELS_XCLBIN_PATH + # Generate PS Kernel xclbins + # We create one xclbin per PS Kernel PS_KERNEL_DIR=$BUILD_DIR/usr/lib/ps_kernels_lib - ps_kernel_command="xclbinutil --output $PS_KERNELS_XCLBIN " pk_exists=0 for entry in "$PS_KERNEL_DIR"/*.so do - pk_exists=1 - ps_kernel_command+=" --add-pskernel $entry" + # Remove .so suffix from filename + f=$(basename -- "$entry") + f=${f%.so} + xclbinutil --output $PS_KERNELS_XCLBIN_PATH/$f.xclbin --add-pskernel $entry --force done - # Generate xclbin if atleast one PS Kernel exists - if [ $pk_exists -eq 1 ]; then - # Run final xclbinutil command to generate the PS Kernels xclbin - echo "Running $ps_kernel_command" - $ps_kernel_command - fi - - # Extract generated xclbins here - # This handles the xclbins required for device validation - for entry in "$PS_KERNEL_DIR"/*.xclbin - do - cp $entry $PS_KERNELS_XCLBIN_PATH - done - fi dodeb $INSTALL_ROOT From fd659ec7777d05247750caeed78a3f347fb005bb Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Thu, 8 Jun 2023 16:43:52 -0700 Subject: [PATCH 06/16] VITIS-6327 Add in automatic sourcing for VITIS for build edge Signed-off-by: Daniel Benusovich --- build/build_edge.sh | 4 +++- .../core/edge/ps_kernels/CMakeLists.txt | 15 +++++++++------ .../core/edge/ps_kernels/xrt/CMakeLists.txt | 8 +------- src/runtime_src/tools/scripts/pkgapu.sh | 14 -------------- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/build/build_edge.sh b/build/build_edge.sh index 068cbbf7187..5b76e126a16 100755 --- a/build/build_edge.sh +++ b/build/build_edge.sh @@ -45,6 +45,7 @@ install_recipes() if [ $? != 0 ]; then echo "inherit externalsrc" > $XRT_BB echo "EXTERNALSRC = \"$XRT_REPO_DIR/src\"" >> $XRT_BB + echo "EXTRA_OECMAKE += \"-DMY_VITIS=$XILINX_VITIS\"" >> $XRT_BB echo 'EXTERNALSRC_BUILD = "${WORKDIR}/build"' >> $XRT_BB echo 'PACKAGE_CLASSES = "package_rpm"' >> $XRT_BB echo 'LICENSE = "GPLv2 & Apache-2.0"' >> $XRT_BB @@ -307,7 +308,8 @@ fi if [ -f $SETTINGS_FILE ]; then source $SETTINGS_FILE fi -source $PETALINUX/settings.sh +source $PETALINUX/settings.sh +source /proj/xbuilds/2023.2_daily_latest/installs/lin64/Vitis/2023.2/settings64.sh if [[ $AARCH = $aarch64_dir ]]; then if [[ -f $PETALINUX/../../bsp/release/zynqmp-common-v$PETALINUX_VER-final.bsp ]]; then diff --git a/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt index 84d74da5fdf..8a15d0fca22 100644 --- a/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt @@ -1,9 +1,12 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2019-2022 Xilinx, Inc. All rights reserved. -# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. -if (DEFINED XRT_AIE_BUILD) - add_subdirectory(sample) - add_subdirectory(profiling) -endif() +# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. +message( "VITIS is ${MY_VITIS}") +if (DEFINED MY_VITIS) + if (DEFINED XRT_AIE_BUILD) + add_subdirectory(sample) + add_subdirectory(profiling) + endif() -add_subdirectory(xrt) + add_subdirectory(xrt) +endif() diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt index 534b9792301..350eecca7e4 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/CMakeLists.txt @@ -2,10 +2,4 @@ # Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. # add_subdirectory(instance_query) - -if (EXISTS "/opt/xilinx/xrt") - message(WARNING "XILINX_XRT is set! Generating ps kernel xclbins") - add_subdirectory(tests) -else() - message(WARNING "XILINX_XRT not set, skip generating ps kernel xclbins") -endif() +add_subdirectory(tests) diff --git a/src/runtime_src/tools/scripts/pkgapu.sh b/src/runtime_src/tools/scripts/pkgapu.sh index 55f5f343ac2..68d76dfe4ec 100755 --- a/src/runtime_src/tools/scripts/pkgapu.sh +++ b/src/runtime_src/tools/scripts/pkgapu.sh @@ -177,7 +177,6 @@ if [[ ! -d $IMAGES_DIR ]]; then error "Please specify the valid path of APU images by -images" fi IMAGES_DIR=`realpath $IMAGES_DIR` -source /proj/xbuilds/2022.2_released/installs/lin64/Vitis/2022.2/settings64.sh if [[ ! (`which mkimage` && `which bootgen` && `which xclbinutil`) ]]; then @@ -311,19 +310,6 @@ if [ $? -eq 0 ]; then # We can create one xclbin per PS Kernel also based on future requirements PS_KERNELS_XCLBIN="$PS_KERNELS_XCLBIN_PATH/ps_kernels.xclbin" PS_KERNEL_DIR=$BUILD_DIR/usr/lib/ps_kernels_lib - ps_kernel_command="xclbinutil --output $PS_KERNELS_XCLBIN " - pk_exists=0 - for entry in "$PS_KERNEL_DIR"/*.so - do - pk_exists=1 - ps_kernel_command+=" --add-pskernel $entry" - done - # Generate xclbin if atleast one PS Kernel exists - if [ $pk_exists -eq 1 ]; then - # Run final xclbinutil command to generate the PS Kernels xclbin - echo "Running $ps_kernel_command" - $ps_kernel_command - fi # Extract generated xclbins here # This handles the xclbins required for device validation From e525ca4365c15b4f90c45b6131c1a038a415bfa3 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Thu, 8 Jun 2023 17:42:17 -0700 Subject: [PATCH 07/16] VITIS-6327 Update CMake to generate xclbin for the apu package Signed-off-by: Daniel Benusovich --- .../validate/ps_validate_test/CMakeLists.txt | 22 +++++++++++++++---- .../validate/ps_validate_test/ps_validate.cpp | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index 45417bf3ffb..2bcb81e6182 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -20,7 +20,21 @@ target_link_libraries(${PS_KERNEL_NAME} xrt_core ) -install (TARGETS ${PS_KERNEL_NAME} - EXPORT xrt-targets - LIBRARY DESTINATION ${PS_KERNEL_INSTALL_DIR} -) +set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") +set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") +set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") +set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") + +add_custom_command( + OUTPUT ${XCLBIN_LOCATION} + COMMAND "/opt/xilinx/xrt/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force + DEPENDS ${PS_KERNEL_NAME} + ) + +add_custom_target(${XCLBIN_TARGET} ALL + DEPENDS ${XCLBIN_LOCATION} + ) + +install (FILES ${XCLBIN_LOCATION} + DESTINATION ${PS_KERNEL_INSTALL_DIR} + ) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp index 420b5bb8129..1c26c2621dc 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/ps_validate.cpp @@ -24,4 +24,4 @@ int hello_world(int *input, int *output, int count, struct xrtHandles *xrtHandle #ifdef __cplusplus } -#endif \ No newline at end of file +#endif From 4f9ad748b1abe5c4e215cbb39694aeaedbfff856 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Mon, 12 Jun 2023 14:46:55 -0700 Subject: [PATCH 08/16] VITIS-6327 Change xclbinutil invocation to use specified vitis version Signed-off-by: Daniel Benusovich --- .../xrt/tests/validate/ps_validate_test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index 2bcb81e6182..cfae00761bb 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -27,7 +27,7 @@ set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") add_custom_command( OUTPUT ${XCLBIN_LOCATION} - COMMAND "/opt/xilinx/xrt/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force + COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force DEPENDS ${PS_KERNEL_NAME} ) From a65bb9a03c9f09a264c4d87b575c038291aaf9ac Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Mon, 12 Jun 2023 15:28:38 -0700 Subject: [PATCH 09/16] VITIS-6327 Add ps_bandwidth ps kernel xclbin Signed-off-by: Daniel Benusovich --- .../xrt/tests/validate/CMakeLists.txt | 1 + .../validate/ps_bandwidth_test/CMakeLists.txt | 40 +++++++ .../ps_bandwidth_test/ps_bandwidth.cpp | 101 ++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt index e7e47b6ba35..ba49754fa1a 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt @@ -2,3 +2,4 @@ # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. # add_subdirectory(ps_validate_test) +add_subdirectory(ps_bandwidth_test) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt new file mode 100644 index 00000000000..b559a1a6b0b --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. +# +set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") + +set(PS_KERNEL_NAME "ps_bandwidth") + +add_library(${PS_KERNEL_NAME} SHARED + "ps_bandwidth.cpp" + ) + +set_target_properties(${PS_KERNEL_NAME} PROPERTIES + VERSION ${XRT_VERSION_STRING} + SOVERSION ${XRT_SOVERSION} + ) + +target_link_libraries(${PS_KERNEL_NAME} + PRIVATE + xrt_coreutil + xrt_core +) + +set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") +set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") +set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") +set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") + +add_custom_command( + OUTPUT ${XCLBIN_LOCATION} + COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force + DEPENDS ${PS_KERNEL_NAME} + ) + +add_custom_target(${XCLBIN_TARGET} ALL + DEPENDS ${XCLBIN_LOCATION} + ) + +install (FILES ${XCLBIN_LOCATION} + DESTINATION ${PS_KERNEL_INSTALL_DIR} + ) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp new file mode 100644 index 00000000000..b140bbf18c0 --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "xrt/xrt_kernel.h" + +#ifdef __cplusplus +extern "C" { +#endif +#include "core/edge/include/sk_types.h" + +// User private data structure container (context object) definition +class xrtHandles : public pscontext +{ +public: + xrt::device dhdl; + xrt::kernel bandwidth_kernel; + xrtHandles(xclDeviceHandle dhdl_in, const xuid_t xclbin_uuid) + : dhdl(dhdl_in) + , bandwidth_kernel(dhdl,xclbin_uuid,"bandwidth") + { + } +}; + + __attribute__((visibility("default"))) + pscontext *bandwidth_kernel_init(xclDeviceHandle dhdl, const xuid_t xclbin_uuid) { + xrtHandles *handles = new xrtHandles(dhdl, xclbin_uuid); + + return(handles); + } + +__attribute__((visibility("default"))) +int bandwidth_kernel(int reps, double *max_throughput, xrtHandles *xrtHandle) +{ + double max_throughput_int = 0; + + // Starting at 4K and going up to 16M with increments of power of 2 + for (uint32_t i = 4 * 1024; i <= 16 * 1024 * 1024; i *= 2) { + unsigned int data_size = i; + + // These commands will allocate memory on the FPGA. The xrt::bo objects + // can be used to reference the memory locations on the device. + // Creating Buffers + auto input_buffer = xrt::bo(xrtHandle->dhdl, data_size, xrtHandle->bandwidth_kernel.group_id(0)); + auto output_buffer = xrt::bo(xrtHandle->dhdl, data_size, xrtHandle->bandwidth_kernel.group_id(1)); + auto input_host = input_buffer.map(); + auto output_host = output_buffer.map(); + + // Filling up memory with an incremental byte pattern + for (uint32_t j = 0; j < data_size; j++) { + input_host[j] = j % 256; + // Initializing output vectors to zero + output_host[j] = 0; + } + + auto time_start = std::chrono::high_resolution_clock::now(); + auto run = xrtHandle->bandwidth_kernel(input_buffer, output_buffer, data_size, reps); + run.wait(); + auto time_end = std::chrono::high_resolution_clock::now(); + + // check + for (uint32_t j = 0; j < data_size; j++) { + if (output_host[j] != input_host[j]) { + syslog(LOG_ERR,"%s: ERROR : kernel failed to copy entry %d, input %d output %d\n",__func__, j, input_host[j], output_host[j]); + return EXIT_FAILURE; + } + } + + double usduration = + (double)(std::chrono::duration_cast(time_end - time_start).count() / reps); + + double dnsduration = (double)usduration; + double dsduration = dnsduration / ((double)1000000000); // Convert the duration from nanoseconds to seconds + double bpersec = (data_size * 1) / dsduration; + double mbpersec = (2 * bpersec) / ((double)1024 * 1024); // Convert b/sec to mb/sec + + if (mbpersec > max_throughput_int) max_throughput_int = mbpersec; + syslog(LOG_INFO, "%s: Throughput : %f MB/s\n",__func__,mbpersec); + } + + syslog(LOG_INFO, "%s: Throughput (Type: DDR) = %f MB/s\n",__func__,max_throughput_int); + max_throughput[0] = max_throughput_int; + + return 0; +} + + +__attribute__((visibility("default"))) +int bandwidth_kernel_fini(xrtHandles *handles) { + delete handles; + return 0; +} + +#ifdef __cplusplus +} +#endif From c4da863e6f1ee641239fd5352c21d7b9a7c074cd Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Mon, 12 Jun 2023 17:02:49 -0700 Subject: [PATCH 10/16] VITIS-6327 Add ps aie validation xclbin Signed-off-by: Daniel Benusovich --- .../xrt/tests/validate/CMakeLists.txt | 4 +- .../tests/validate/ps_aie_test/CMakeLists.txt | 40 ++++++++++ .../xrt/tests/validate/ps_aie_test/ps_aie.cpp | 80 +++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/ps_aie.cpp diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt index ba49754fa1a..13da25dd539 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt @@ -1,5 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. # -add_subdirectory(ps_validate_test) +add_subdirectory(ps_aie_test) add_subdirectory(ps_bandwidth_test) +add_subdirectory(ps_validate_test) + diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt new file mode 100644 index 00000000000..03bfb470ac6 --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. +# +set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") + +set(PS_KERNEL_NAME "ps_aie") + +add_library(${PS_KERNEL_NAME} SHARED + "ps_aie.cpp" + ) + +set_target_properties(${PS_KERNEL_NAME} PROPERTIES + VERSION ${XRT_VERSION_STRING} + SOVERSION ${XRT_SOVERSION} + ) + +target_link_libraries(${PS_KERNEL_NAME} + PRIVATE + xrt_coreutil + xrt_core +) + +set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") +set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") +set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") +set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") + +add_custom_command( + OUTPUT ${XCLBIN_LOCATION} + COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force + DEPENDS ${PS_KERNEL_NAME} + ) + +add_custom_target(${XCLBIN_TARGET} ALL + DEPENDS ${XCLBIN_LOCATION} + ) + +install (FILES ${XCLBIN_LOCATION} + DESTINATION ${PS_KERNEL_INSTALL_DIR} + ) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/ps_aie.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/ps_aie.cpp new file mode 100644 index 00000000000..1ba6b6e3abf --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/ps_aie.cpp @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2022 Xilinx, Inc +// Copyright (C) 2023 Advanced Micro Devices, Inc. - All rights reserved + +#include "core/edge/include/sk_types.h" +#include +#include +#include +#include +#include +#include +#include + +#include "xrt/xrt_aie.h" +#include "xrt/xrt_bo.h" +#include "xrt/xrt_graph.h" +#include "xrt/xrt_kernel.h" + +#define SAMPLES 256 + +#ifdef __cplusplus +extern "C" { +#endif + +class xrtHandles : public pscontext { + public: + xrt::device dhdl; + xrt::graph graphhdl; + xrtHandles(xclDeviceHandle dhdl_in, const xuid_t xclbin_uuid) : dhdl(dhdl_in), graphhdl(dhdl, xclbin_uuid, "mm") { + graphhdl.run(); + } +}; + +__attribute__((visibility("default"))) xrtHandles* +aie_kernel_init(xclDeviceHandle dhdl, const xuid_t xclbin_uuid) { + xrtHandles* handles = new xrtHandles(dhdl, xclbin_uuid); + + return handles; +} + +__attribute__((visibility("default"))) int +aie_kernel( + float* in_boA, float* in_boB, float* out_bo, int input_size, int output_size, xrtHandles* handles) { + auto out_bohdl = xrt::aie::bo(handles->dhdl, output_size, 0, 0); + auto in_bohdlA = xrt::aie::bo(handles->dhdl, input_size, 0, 0); + auto in_bohdlB = xrt::aie::bo(handles->dhdl, input_size, 0, 0); + + auto inA_bo_map = in_bohdlA.map(); + auto inB_bo_map = in_bohdlB.map(); + auto out_bo_map = out_bohdl.map(); + + memcpy(inA_bo_map, in_boA, input_size); + memcpy(inB_bo_map, in_boB, input_size); + + std::string gmioportA, gmioportB, gmioportC; + int gmio_id = 0; + gmioportA = std::to_string(gmio_id++); + gmioportB = std::to_string(gmio_id++); + in_bohdlB.sync("in_source2", XCL_BO_SYNC_BO_GMIO_TO_AIE, input_size, 0); + in_bohdlA.sync("in_source1", XCL_BO_SYNC_BO_GMIO_TO_AIE, input_size, 0); + + gmioportC = std::to_string(gmio_id++); + out_bohdl.sync("out_sink", XCL_BO_SYNC_BO_AIE_TO_GMIO, output_size, 0); + + memcpy(out_bo, out_bo_map, output_size); + + return 0; +} + +__attribute__((visibility("default"))) int +aie_kernel_fini(xrtHandles* handles) { + std::cout << "Releasing remaining XRT objects...\n"; + handles->graphhdl.end(); + delete handles; + return 0; +} + +#ifdef __cplusplus +} +#endif From dac4143344e24fee1611ba126ad50026d3047a33 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Mon, 12 Jun 2023 17:43:23 -0700 Subject: [PATCH 11/16] VITIS-6327 Add dependency json. Update comment headers Signed-off-by: Daniel Benusovich --- .../ps_kernels/xrt/tests/validate/CMakeLists.txt | 5 +++++ .../tests/validate/ps_aie_test/CMakeLists.txt | 5 +---- .../validate/ps_bandwidth_test/CMakeLists.txt | 5 +---- .../validate/ps_validate_test/CMakeLists.txt | 5 +---- .../xrt/tests/validate/test_dependencies.json | 16 ++++++++++++++++ src/runtime_src/tools/scripts/pkgapu.sh | 10 ++++++++-- 6 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt index 13da25dd539..f105353c5f0 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/CMakeLists.txt @@ -1,7 +1,12 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. # +set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") + add_subdirectory(ps_aie_test) add_subdirectory(ps_bandwidth_test) add_subdirectory(ps_validate_test) +install (FILES test_dependencies.json + DESTINATION ${PS_KERNEL_INSTALL_DIR} + ) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt index 03bfb470ac6..d7db436c9b2 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt @@ -1,8 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. -# -set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") - +# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. set(PS_KERNEL_NAME "ps_aie") add_library(${PS_KERNEL_NAME} SHARED diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt index b559a1a6b0b..1ed1d37bbe5 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt @@ -1,8 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. -# -set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") - +# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. set(PS_KERNEL_NAME "ps_bandwidth") add_library(${PS_KERNEL_NAME} SHARED diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index cfae00761bb..81a7ee775fb 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -1,8 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved. -# -set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") - +# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. set(PS_KERNEL_NAME "ps_validate") add_library(${PS_KERNEL_NAME} SHARED diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json new file mode 100644 index 00000000000..f07398eb39f --- /dev/null +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json @@ -0,0 +1,16 @@ +{ + "ps_kernel_mappings": [ + { + "name": "ps_aie.xclbin", + "dependencies": ["ps_aie.xclbin"] + }, + { + "name": "ps_bandwidth.xclbin", + "dependencies": ["ps_bandwidth.xclbin"] + }, + { + "name": "ps_validate.xclbin", + "dependencies": ["ps_validate.xclbin"] + } + ] +} diff --git a/src/runtime_src/tools/scripts/pkgapu.sh b/src/runtime_src/tools/scripts/pkgapu.sh index c24776517b1..f50484fd8a9 100755 --- a/src/runtime_src/tools/scripts/pkgapu.sh +++ b/src/runtime_src/tools/scripts/pkgapu.sh @@ -1,6 +1,7 @@ #!/bin/bash # # Copyright (C) 2021-2022 Xilinx, Inc. All rights reserved. +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. # # This script creates rpm and deb packages for Versal APU firmware and Built-in PS Kernels. @@ -305,8 +306,7 @@ if [ $? -eq 0 ]; then # Generate the output directory PS_KERNELS_XCLBIN_PATH="$BUILD_DIR/lib/firmware/xilinx/ps_kernels" mkdir -p $PS_KERNELS_XCLBIN_PATH - # Generate PS Kernel xclbins - # We create one xclbin per PS Kernel + # Copy over PS kernel xclbins built by XRT PS_KERNEL_DIR=$BUILD_DIR/usr/lib/ps_kernels_lib # Extract generated xclbins here @@ -315,6 +315,12 @@ if [ $? -eq 0 ]; then do cp $entry $PS_KERNELS_XCLBIN_PATH done + + # Copy the configuration json files for PS kernels + for entry in "$PS_KERNEL_DIR"/*.json + do + cp $entry $PS_KERNELS_XCLBIN_PATH + done fi dodeb $INSTALL_ROOT From 925a870ade6cfe8958277f452e08991f07bff70f Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Thu, 15 Jun 2023 16:26:32 -0700 Subject: [PATCH 12/16] VITIS-6327 remove dependencies for ps_validate ps kernel Signed-off-by: Daniel Benusovich --- .../edge/ps_kernels/xrt/tests/validate/test_dependencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json index f07398eb39f..65706b454b9 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/test_dependencies.json @@ -10,7 +10,7 @@ }, { "name": "ps_validate.xclbin", - "dependencies": ["ps_validate.xclbin"] + "dependencies": [] } ] } From cc0e1012666c2952f43114c38532a2ffb8d49d14 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Mon, 19 Jun 2023 13:15:30 -0700 Subject: [PATCH 13/16] VITIS-6327 Remove sourcing of VITIS build into separate file. Update build script to use new file. Update apu package script to use new file Signed-off-by: Daniel Benusovich --- build/build_edge.sh | 4 +++- build/vitis.build | 1 + src/runtime_src/tools/scripts/pkgapu.sh | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 build/vitis.build diff --git a/build/build_edge.sh b/build/build_edge.sh index 9581df7705c..5ec3109609b 100755 --- a/build/build_edge.sh +++ b/build/build_edge.sh @@ -309,7 +309,9 @@ if [ -f $SETTINGS_FILE ]; then source $SETTINGS_FILE fi source $PETALINUX/settings.sh -source /proj/xbuilds/2023.2_daily_latest/installs/lin64/Vitis/2023.2/settings64.sh + +VITIS_FILE="${THIS_SCRIPT_DIR}/vitis.build" +source $VITIS_FILE if [[ $AARCH = $aarch64_dir ]]; then if [[ -f $PETALINUX/../../bsp/release/zynqmp-common-v$PETALINUX_VER-final.bsp ]]; then diff --git a/build/vitis.build b/build/vitis.build new file mode 100644 index 00000000000..66e90af624e --- /dev/null +++ b/build/vitis.build @@ -0,0 +1 @@ +source /proj/xbuilds/2023.2_daily_latest/installs/lin64/Vitis/2023.2/settings64.sh diff --git a/src/runtime_src/tools/scripts/pkgapu.sh b/src/runtime_src/tools/scripts/pkgapu.sh index f50484fd8a9..e412a5401e8 100755 --- a/src/runtime_src/tools/scripts/pkgapu.sh +++ b/src/runtime_src/tools/scripts/pkgapu.sh @@ -167,6 +167,10 @@ FW_FILE="$BUILD_DIR/lib/firmware/xilinx/xrt-versal-apu.xsabin" INSTALL_ROOT="$BUILD_DIR/lib" SDK="$BUILD_DIR/lib/firmware/xilinx/sysroot/sdk.sh" +THIS_SCRIPT_DIR="$( cd "$( dirname "${THIS_SCRIPT}" )" >/dev/null 2>&1 && pwd )" +VITIS_FILE="${THIS_SCRIPT_DIR}/vitis.build" +source $VITIS_FILE + if [[ $clean == 1 ]]; then echo $PWD echo "/bin/rm -rf $BUILD_DIR" From a2175a48b1a81598b2a4ec78d73e5f2b3b3df125 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Fri, 23 Jun 2023 13:03:39 -0700 Subject: [PATCH 14/16] VITIS-6327 Refactor ps kernel xclbin generation into function Signed-off-by: Daniel Benusovich --- .../core/edge/ps_kernels/CMakeLists.txt | 24 ++++++++++++++++++- .../tests/validate/ps_aie_test/CMakeLists.txt | 19 +-------------- .../validate/ps_bandwidth_test/CMakeLists.txt | 19 +-------------- .../validate/ps_validate_test/CMakeLists.txt | 19 +-------------- 4 files changed, 26 insertions(+), 55 deletions(-) diff --git a/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt index 8a15d0fca22..1d4357d078a 100644 --- a/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/CMakeLists.txt @@ -1,7 +1,29 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2019-2022 Xilinx, Inc. All rights reserved. # Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. -message( "VITIS is ${MY_VITIS}") +set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib") + +function(generate_ps_kernel_xclbin PS_KERNEL_NAME) + set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") + set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") + set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") + set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") + + add_custom_command( + OUTPUT ${XCLBIN_LOCATION} + COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force + DEPENDS ${PS_KERNEL_NAME} + ) + + add_custom_target(${XCLBIN_TARGET} ALL + DEPENDS ${XCLBIN_LOCATION} + ) + + install (FILES ${XCLBIN_LOCATION} + DESTINATION ${PS_KERNEL_INSTALL_DIR} + ) +endfunction() + if (DEFINED MY_VITIS) if (DEFINED XRT_AIE_BUILD) add_subdirectory(sample) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt index d7db436c9b2..b45e07b652c 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_aie_test/CMakeLists.txt @@ -17,21 +17,4 @@ target_link_libraries(${PS_KERNEL_NAME} xrt_core ) -set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") -set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") -set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") -set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") - -add_custom_command( - OUTPUT ${XCLBIN_LOCATION} - COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force - DEPENDS ${PS_KERNEL_NAME} - ) - -add_custom_target(${XCLBIN_TARGET} ALL - DEPENDS ${XCLBIN_LOCATION} - ) - -install (FILES ${XCLBIN_LOCATION} - DESTINATION ${PS_KERNEL_INSTALL_DIR} - ) +generate_ps_kernel_xclbin(${PS_KERNEL_NAME}) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt index 1ed1d37bbe5..8666943da80 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/CMakeLists.txt @@ -17,21 +17,4 @@ target_link_libraries(${PS_KERNEL_NAME} xrt_core ) -set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") -set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") -set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") -set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") - -add_custom_command( - OUTPUT ${XCLBIN_LOCATION} - COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force - DEPENDS ${PS_KERNEL_NAME} - ) - -add_custom_target(${XCLBIN_TARGET} ALL - DEPENDS ${XCLBIN_LOCATION} - ) - -install (FILES ${XCLBIN_LOCATION} - DESTINATION ${PS_KERNEL_INSTALL_DIR} - ) +generate_ps_kernel_xclbin(${PS_KERNEL_NAME}) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt index 81a7ee775fb..9db1ea7d051 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_validate_test/CMakeLists.txt @@ -17,21 +17,4 @@ target_link_libraries(${PS_KERNEL_NAME} xrt_core ) -set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin") -set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin") -set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so") -set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}") - -add_custom_command( - OUTPUT ${XCLBIN_LOCATION} - COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force - DEPENDS ${PS_KERNEL_NAME} - ) - -add_custom_target(${XCLBIN_TARGET} ALL - DEPENDS ${XCLBIN_LOCATION} - ) - -install (FILES ${XCLBIN_LOCATION} - DESTINATION ${PS_KERNEL_INSTALL_DIR} - ) +generate_ps_kernel_xclbin(${PS_KERNEL_NAME}) From 01ed0152817704bc675f7719ad3af541fbd99948 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Tue, 27 Jun 2023 13:45:44 -0700 Subject: [PATCH 15/16] VITIS-6327 Simplify for loop variables Signed-off-by: Daniel Benusovich --- .../tests/validate/ps_bandwidth_test/ps_bandwidth.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp index b140bbf18c0..7288130078d 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp @@ -9,6 +9,14 @@ #include "xrt/xrt_kernel.h" +constexpr unsigned long long int operator "" _Kb(unsigned long long int n) { + return n * 1024; +} + +constexpr unsigned long long int operator "" _Mb(unsigned long long int n) { + return n * 1024 * 1024; +} + #ifdef __cplusplus extern "C" { #endif @@ -40,7 +48,7 @@ int bandwidth_kernel(int reps, double *max_throughput, xrtHandles *xrtHandle) double max_throughput_int = 0; // Starting at 4K and going up to 16M with increments of power of 2 - for (uint32_t i = 4 * 1024; i <= 16 * 1024 * 1024; i *= 2) { + for (uint32_t i = 4_Kb; i <= 16_Mb; i *= 2) { unsigned int data_size = i; // These commands will allocate memory on the FPGA. The xrt::bo objects From d33882fbfe43e286318f597f0178484e8d29ac8a Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Tue, 27 Jun 2023 14:35:55 -0700 Subject: [PATCH 16/16] VITIS-6327 Change units of defined literal to standard form Signed-off-by: Daniel Benusovich --- .../xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp index 7288130078d..9b5f2efa3f8 100644 --- a/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp +++ b/src/runtime_src/core/edge/ps_kernels/xrt/tests/validate/ps_bandwidth_test/ps_bandwidth.cpp @@ -9,11 +9,11 @@ #include "xrt/xrt_kernel.h" -constexpr unsigned long long int operator "" _Kb(unsigned long long int n) { +constexpr unsigned long long int operator "" _Ki(unsigned long long int n) { return n * 1024; } -constexpr unsigned long long int operator "" _Mb(unsigned long long int n) { +constexpr unsigned long long int operator "" _Mi(unsigned long long int n) { return n * 1024 * 1024; } @@ -48,7 +48,7 @@ int bandwidth_kernel(int reps, double *max_throughput, xrtHandles *xrtHandle) double max_throughput_int = 0; // Starting at 4K and going up to 16M with increments of power of 2 - for (uint32_t i = 4_Kb; i <= 16_Mb; i *= 2) { + for (uint32_t i = 4_Ki; i <= 16_Mi; i *= 2) { unsigned int data_size = i; // These commands will allocate memory on the FPGA. The xrt::bo objects