Skip to content

Commit d880395

Browse files
authored
Vitis 6327 Add PS kernel xclbins into APU Package (#7594)
* VITIS-6327 CMake broken when invoking xclbinutil Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 build creates correct ps kernel images. No xclbin generation yet Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Remove unused Makefiles for building xclbins Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Export of ps_validate xclbin complete Signed-off-by: Daniel Benusovich <[email protected]> * 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 <[email protected]> * VITIS-6327 Add in automatic sourcing for VITIS for build edge Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Update CMake to generate xclbin for the apu package Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Change xclbinutil invocation to use specified vitis version Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Add ps_bandwidth ps kernel xclbin Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Add ps aie validation xclbin Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Add dependency json. Update comment headers Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 remove dependencies for ps_validate ps kernel Signed-off-by: Daniel Benusovich <[email protected]> * 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 <[email protected]> * VITIS-6327 Refactor ps kernel xclbin generation into function Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Simplify for loop variables Signed-off-by: Daniel Benusovich <[email protected]> * VITIS-6327 Change units of defined literal to standard form Signed-off-by: Daniel Benusovich <[email protected]> --------- Signed-off-by: Daniel Benusovich <[email protected]>
1 parent 5b966dc commit d880395

File tree

15 files changed

+376
-26
lines changed

15 files changed

+376
-26
lines changed

build/build_edge.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ install_recipes()
4545
if [ $? != 0 ]; then
4646
echo "inherit externalsrc" > $XRT_BB
4747
echo "EXTERNALSRC = \"$XRT_REPO_DIR/src\"" >> $XRT_BB
48+
echo "EXTRA_OECMAKE += \"-DMY_VITIS=$XILINX_VITIS\"" >> $XRT_BB
4849
echo 'EXTERNALSRC_BUILD = "${WORKDIR}/build"' >> $XRT_BB
4950
echo 'PACKAGE_CLASSES = "package_rpm"' >> $XRT_BB
5051
echo 'LICENSE = "GPLv2 & Apache-2.0"' >> $XRT_BB
@@ -280,7 +281,10 @@ fi
280281
if [ -f $SETTINGS_FILE ]; then
281282
source $SETTINGS_FILE
282283
fi
283-
source $PETALINUX/settings.sh
284+
source $PETALINUX/settings.sh
285+
286+
VITIS_FILE="${THIS_SCRIPT_DIR}/vitis.build"
287+
source $VITIS_FILE
284288

285289
if [[ $AARCH = $aarch64_dir ]]; then
286290
if [[ -f $PETALINUX/../../bsp/release/zynqmp-common-v$PETALINUX_VER-final.bsp ]]; then

build/vitis.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source /proj/xbuilds/2023.2_daily_latest/installs/lin64/Vitis/2023.2/settings64.sh
Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright (C) 2019-2022 Xilinx, Inc. All rights reserved.
3-
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
4-
if (DEFINED XRT_AIE_BUILD)
5-
add_subdirectory(sample)
6-
add_subdirectory(profiling)
7-
endif()
3+
# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
4+
set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib")
5+
6+
function(generate_ps_kernel_xclbin PS_KERNEL_NAME)
7+
set(XCLBIN_NAME "${PS_KERNEL_NAME}.xclbin")
8+
set(XCLBIN_TARGET "${PS_KERNEL_NAME}_xclbin")
9+
set(PS_KERNEL_LOCATION "lib${PS_KERNEL_NAME}.so")
10+
set(XCLBIN_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${XCLBIN_NAME}")
11+
12+
add_custom_command(
13+
OUTPUT ${XCLBIN_LOCATION}
14+
COMMAND "${MY_VITIS}/bin/xclbinutil" --output ${XCLBIN_LOCATION} --add-pskernel ${PS_KERNEL_LOCATION} --force
15+
DEPENDS ${PS_KERNEL_NAME}
16+
)
17+
18+
add_custom_target(${XCLBIN_TARGET} ALL
19+
DEPENDS ${XCLBIN_LOCATION}
20+
)
821

9-
add_subdirectory(xrt)
22+
install (FILES ${XCLBIN_LOCATION}
23+
DESTINATION ${PS_KERNEL_INSTALL_DIR}
24+
)
25+
endfunction()
26+
27+
if (DEFINED MY_VITIS)
28+
if (DEFINED XRT_AIE_BUILD)
29+
add_subdirectory(sample)
30+
add_subdirectory(profiling)
31+
endif()
32+
33+
add_subdirectory(xrt)
34+
endif()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
2+
# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
33
#
44
add_subdirectory(instance_query)
5+
add_subdirectory(tests)

src/runtime_src/core/edge/ps_kernels/xrt/instance_query/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
#
44
set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib")
55

6-
add_library(instance_query OBJECT
7-
instance_query.cpp
6+
add_library(instance_query SHARED
7+
"instance_query.cpp"
88
)
99

1010
set_target_properties(instance_query PROPERTIES
1111
VERSION ${XRT_VERSION_STRING}
1212
SOVERSION ${XRT_SOVERSION}
1313
)
1414

15+
target_link_libraries(instance_query
16+
PRIVATE
17+
${Boost_FILESYSTEM_LIBRARY}
18+
)
19+
1520
install (TARGETS instance_query
1621
EXPORT xrt-targets
1722
LIBRARY DESTINATION ${PS_KERNEL_INSTALL_DIR}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
3+
#
4+
add_subdirectory(validate)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
3+
#
4+
set(PS_KERNEL_INSTALL_DIR "${XRT_INSTALL_LIB_DIR}/ps_kernels_lib")
5+
6+
add_subdirectory(ps_aie_test)
7+
add_subdirectory(ps_bandwidth_test)
8+
add_subdirectory(ps_validate_test)
9+
10+
install (FILES test_dependencies.json
11+
DESTINATION ${PS_KERNEL_INSTALL_DIR}
12+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
3+
set(PS_KERNEL_NAME "ps_aie")
4+
5+
add_library(${PS_KERNEL_NAME} SHARED
6+
"ps_aie.cpp"
7+
)
8+
9+
set_target_properties(${PS_KERNEL_NAME} PROPERTIES
10+
VERSION ${XRT_VERSION_STRING}
11+
SOVERSION ${XRT_SOVERSION}
12+
)
13+
14+
target_link_libraries(${PS_KERNEL_NAME}
15+
PRIVATE
16+
xrt_coreutil
17+
xrt_core
18+
)
19+
20+
generate_ps_kernel_xclbin(${PS_KERNEL_NAME})
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2022 Xilinx, Inc
3+
// Copyright (C) 2023 Advanced Micro Devices, Inc. - All rights reserved
4+
5+
#include "core/edge/include/sk_types.h"
6+
#include <cstring>
7+
#include <fstream>
8+
#include <iostream>
9+
#include <stdint.h>
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <vector>
13+
14+
#include "xrt/xrt_aie.h"
15+
#include "xrt/xrt_bo.h"
16+
#include "xrt/xrt_graph.h"
17+
#include "xrt/xrt_kernel.h"
18+
19+
#define SAMPLES 256
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
class xrtHandles : public pscontext {
26+
public:
27+
xrt::device dhdl;
28+
xrt::graph graphhdl;
29+
xrtHandles(xclDeviceHandle dhdl_in, const xuid_t xclbin_uuid) : dhdl(dhdl_in), graphhdl(dhdl, xclbin_uuid, "mm") {
30+
graphhdl.run();
31+
}
32+
};
33+
34+
__attribute__((visibility("default"))) xrtHandles*
35+
aie_kernel_init(xclDeviceHandle dhdl, const xuid_t xclbin_uuid) {
36+
xrtHandles* handles = new xrtHandles(dhdl, xclbin_uuid);
37+
38+
return handles;
39+
}
40+
41+
__attribute__((visibility("default"))) int
42+
aie_kernel(
43+
float* in_boA, float* in_boB, float* out_bo, int input_size, int output_size, xrtHandles* handles) {
44+
auto out_bohdl = xrt::aie::bo(handles->dhdl, output_size, 0, 0);
45+
auto in_bohdlA = xrt::aie::bo(handles->dhdl, input_size, 0, 0);
46+
auto in_bohdlB = xrt::aie::bo(handles->dhdl, input_size, 0, 0);
47+
48+
auto inA_bo_map = in_bohdlA.map<float*>();
49+
auto inB_bo_map = in_bohdlB.map<float*>();
50+
auto out_bo_map = out_bohdl.map<float*>();
51+
52+
memcpy(inA_bo_map, in_boA, input_size);
53+
memcpy(inB_bo_map, in_boB, input_size);
54+
55+
std::string gmioportA, gmioportB, gmioportC;
56+
int gmio_id = 0;
57+
gmioportA = std::to_string(gmio_id++);
58+
gmioportB = std::to_string(gmio_id++);
59+
in_bohdlB.sync("in_source2", XCL_BO_SYNC_BO_GMIO_TO_AIE, input_size, 0);
60+
in_bohdlA.sync("in_source1", XCL_BO_SYNC_BO_GMIO_TO_AIE, input_size, 0);
61+
62+
gmioportC = std::to_string(gmio_id++);
63+
out_bohdl.sync("out_sink", XCL_BO_SYNC_BO_AIE_TO_GMIO, output_size, 0);
64+
65+
memcpy(out_bo, out_bo_map, output_size);
66+
67+
return 0;
68+
}
69+
70+
__attribute__((visibility("default"))) int
71+
aie_kernel_fini(xrtHandles* handles) {
72+
std::cout << "Releasing remaining XRT objects...\n";
73+
handles->graphhdl.end();
74+
delete handles;
75+
return 0;
76+
}
77+
78+
#ifdef __cplusplus
79+
}
80+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
3+
set(PS_KERNEL_NAME "ps_bandwidth")
4+
5+
add_library(${PS_KERNEL_NAME} SHARED
6+
"ps_bandwidth.cpp"
7+
)
8+
9+
set_target_properties(${PS_KERNEL_NAME} PROPERTIES
10+
VERSION ${XRT_VERSION_STRING}
11+
SOVERSION ${XRT_SOVERSION}
12+
)
13+
14+
target_link_libraries(${PS_KERNEL_NAME}
15+
PRIVATE
16+
xrt_coreutil
17+
xrt_core
18+
)
19+
20+
generate_ps_kernel_xclbin(${PS_KERNEL_NAME})

0 commit comments

Comments
 (0)