### Install EPEL on RHEL 9.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on RHEL 9.x systems. This process includes enabling the CodeReady Builder repository and installing the EPEL release package, a prerequisite for XRT. ```shell sudo subscription-manager repos --enable "codeready-builder-for-rhel-9-x86_64-rpms" sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm ``` -------------------------------- ### Install EPEL on RHEL 10.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on RHEL 10.x systems. It requires enabling the CodeReady Builder repository and then installing the EPEL release package. This is a prerequisite for XRT. ```shell sudo subscription-manager repos --enable "codeready-builder-for-rhel-10-x86_64-rpms" sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm ``` -------------------------------- ### Install EPEL on RHEL 8.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on RHEL 8.x systems. This involves enabling the CodeReady Builder repository and then installing the EPEL release package. This is necessary for XRT installation. ```shell sudo subscription-manager repos --enable "codeready-builder-for-rhel-8-x86_64-rpms" sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm ``` -------------------------------- ### Install Executables (CMake) Source: https://github.com/xilinx/xrt/blob/master/tests/xrt/mailbox/CMakeLists.txt Installs the compiled 'use_mailbox' and 'no_mailbox' executables to a runtime destination relative to the installation directory and test name. ```cmake install(TARGETS use_mailbox no_mailbox RUNTIME DESTINATION ${INSTALL_DIR}/${TESTNAME}) ``` -------------------------------- ### Install XRT Software Stack on Ubuntu Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the XRT software stack on Ubuntu systems using a downloaded DEB package. Replace `` with the actual XRT version number. ```shell sudo apt install xrt_.deb ``` -------------------------------- ### Install EPEL on CentOS 7.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on CentOS 7.x systems by directly installing the EPEL release package. This is a prerequisite for XRT installation. ```shell yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm ``` -------------------------------- ### Asynchronous Kernel Execution with Callbacks (C++) Source: https://context7.com/xilinx/xrt/llms.txt Illustrates non-blocking kernel execution using callbacks for completion notification. This allows the application to perform other tasks while the kernel runs in the background. The example includes setting up a callback, starting the kernel, and polling for completion. ```cpp auto kernel = xrt::kernel(device, uuid, "async_kernel"); auto run = xrt::run(kernel); // Set up callback for completion std::atomic completed{false}; run.add_callback(ERT_CMD_STATE_COMPLETED, [](const void* key, ert_cmd_state state, void* data) { auto flag = static_cast*>(data); flag->store(true); std::cout << "Kernel completed!" << std::endl; }, &completed); // Start kernel auto bo = xrt::bo(device, 4096, kernel.group_id(0)); run.set_arg(0, bo); run.start(); // Do other work while kernel executes std::cout << "Kernel running in background..." << std::endl; // Wait for completion (callback will fire) while (!completed.load()) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } ``` -------------------------------- ### Install EPEL on AlmaLinux 9.x/Rocky 9.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on AlmaLinux 9.x and Rocky Linux 9.x systems using DNF. This involves enabling the 'crb' repository and then installing the 'epel-release' package, which is necessary for XRT installation. ```shell sudo dnf config-manager --set-enabled crb sudo dnf install epel-release ``` -------------------------------- ### Install EPEL on AlmaLinux 8.x/Rocky 8.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on AlmaLinux 8.x and Rocky Linux 8.x systems using DNF. It enables the 'powertools' and 'appstream' repositories before installing the 'epel-release' package, a prerequisite for XRT. ```shell sudo dnf config-manager --set-enabled powertools sudo dnf config-manager --set-enabled appstream sudo dnf install epel-release ``` -------------------------------- ### Define XRT Setup and Loader Scripts (CMake) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/tools/scripts/CMakeLists.txt This snippet defines lists of setup and loader scripts based on the operating system. It differentiates between Unix-like systems (setup.sh, setup.fish, setup.csh, loader) and Windows (setup.bat, loader.bat). These lists are used later for installation. ```cmake if (NOT WIN32) set(XRT_SETUP_SCRIPTS setup.sh setup.fish setup.csh) set(XRT_LOADER_SCRIPTS loader) set (XRT_SCRIPTS service_bundle.sh plp_program.sh) else() set(XRT_SETUP_SCRIPTS setup.bat) set (XRT_LOADER_SCRIPTS loader.bat) endif(NOT WIN32) ``` -------------------------------- ### Project Setup and Variable Definitions (CMake) Source: https://github.com/xilinx/xrt/blob/master/build/xocl_petalinux_compile/CMakeLists.txt Initializes the CMake project, sets minimum version, project description, source directory, and installation paths. It also defines build-related flags like native build status. ```cmake PROJECT(XRT) CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0) SET(PROJECT_DESCRIPTION "https://github.com/Xilinx/XRT") set (XRT_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../src") set(XRT_VERSION_STRING "cross_compile") set (XRT_INSTALL_DIR "${CMAKE_BINARY_DIR}") set (XRT_INSTALL_INCLUDE_DIR "${XRT_INSTALL_DIR}/include") set(XRT_NATIVE_BUILD "no") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${XRT_SRC_DIR}/CMake/") set(XRT_DKMS_DRIVER_SRC_BASE_DIR "${XRT_SRC_DIR}/runtime_src/core") set(XRT_DKMS_INSTALL_DIR "${CMAKE_BINARY_DIR}/../driver_code") set(CMAKE_SOURCE_DIR "${XRT_SRC_DIR}") ``` -------------------------------- ### Install XRT and zocl on Target Embedded System (Bash) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/yocto.rst Installs the XRT package and the zocl driver module on an embedded system using the DNF package manager. Requires downloading repository configuration files and cleaning the DNF cache before installation. Assumes the target system has DNF enabled and access to the specified repository URLs. ```bash # Execute the following scripts on target embedded system # Install dnf repository description cd /etc/yum.repos.d wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic/rpm/repos/zynqmp-generic_ev.repo wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic-updates/rpm/repos/zynqmp-generic_ev-update.repo # Clean dnf local cache dnf clean all # Install XRT and zocl dnf install xrt dnf install zocl ``` -------------------------------- ### Install XRT Software Stack on RHEL/CentOS Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the XRT software stack on RHEL or CentOS systems using a downloaded RPM package. Replace `` with the actual XRT version number. ```shell sudo yum install xrt_.rpm ``` -------------------------------- ### Install XRT Hardware Emulation Libraries (CMake) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/pcie/emulation/hw_emu/CMakeLists.txt This CMake `install` command defines how the `xrt_hwemu` and `xrt_hwemu_static` libraries are installed on the system. It specifies destinations for runtime, library, and archive files, along with component assignments for different installation types (e.g., runtime vs. development). ```cmake install (TARGETS xrt_hwemu xrt_hwemu_static EXPORT xrt-targets RUNTIME DESTINATION ${XRT_INSTALL_BIN_DIR} COMPONENT ${XRT_COMPONENT} LIBRARY DESTINATION ${XRT_INSTALL_LIB_DIR} COMPONENT ${XRT_COMPONENT} NAMELINK_COMPONENT ${XRT_DEV_COMPONENT} ARCHIVE DESTINATION ${XRT_INSTALL_LIB_DIR} COMPONENT ${XRT_DEV_COMPONENT} ) ``` -------------------------------- ### Install Executables for Xilinx XRT Source: https://github.com/xilinx/xrt/blob/master/tests/xrt/22_verify/CMakeLists.txt Installs the compiled executables ('22_verify' and '22_verify_xcl') to a specified runtime destination directory. The installation is performed after all build targets have been defined. ```cmake install(TARGETS ${TESTNAME} ${TESTNAME}_xcl RUNTIME DESTINATION ${INSTALL_DIR}/${TESTNAME}) ``` -------------------------------- ### Run xrt nagios plugin with device and report Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/nagios_plugin.rst This example demonstrates how to run the xrt nagios plugin to get a 'platform' report for a specific device. The `--device` option takes a BDF (Bus:Device.Function) identifier, and the `--report` option specifies the type of report to retrieve. The output will be in JSON format. ```shell ./nagios_plugin.sh --device 0000:b3:00.1 --report platform ``` ```shell ./nagios_plugin.sh -d b3:00 -r platform ``` -------------------------------- ### Install GTest Dependencies with xrtdeps.sh Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/test.rst This command installs the Google Test (GTest) framework, which is used for unit testing XRT. The `xrtdeps.sh` script handles the installation of GTest libraries and necessary build tools. ```bash XRT/src/runtime_src/tools/scripts/xrtdeps.sh ``` -------------------------------- ### Install XRT Package on Ubuntu Host Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/cloud_vendor_support.rst Commands to install the XRT package and the container package on an Ubuntu host system. This is a prerequisite for enabling the MPD plugin functionality for containers. ```bash # install xrt pkg $ sudo apt install /opt/xrt_201920.2.3.0_18.04-xrt.deb # install xrt pkg $ sudo apt install /opt/xrt_201920.2.3.0_18.04-container.deb ``` -------------------------------- ### Get Device PCIe BDF using clGetDeviceInfo Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This example demonstrates how to obtain the Bus/Device/Function (BDF) information for a PCIe-based OpenCL device using the XRT-specific parameter CL_DEVICE_PCIE_BDF with the clGetDeviceInfo API. ```c++ char[20] bdf; clGetDeviceInfo(device, CL_DEVICE_PCIE_BDF, sizeof(bdf), &bdf, nullptr); ``` -------------------------------- ### Complete Application Example using XRT C++ API Source: https://context7.com/xilinx/xrt/llms.txt This C++ example demonstrates a complete application workflow for FPGA acceleration using the XRT library. It includes device initialization, loading an XCLBIN bitstream, allocating and mapping buffers, transferring data to the device, executing a kernel, and verifying the results. It requires the XRT library and a compatible FPGA bitstream (e.g., 'vector_add.xclbin'). ```cpp #include #include #include "xrt/xrt_device.h" #include "xrt/xrt_kernel.h" #include "xrt/xrt_bo.h" int main(int argc, char** argv) { try { // Configuration const std::string xclbin_path = "vector_add.xclbin"; const std::string kernel_name = "vadd"; const int vector_size = 4096; const size_t buffer_size = vector_size * sizeof(int); // Initialize device auto device = xrt::device(0); std::cout << "Device opened: " << device.get_info() << std::endl; // Load bitstream auto uuid = device.load_xclbin(xclbin_path); std::cout << "Xclbin loaded" << std::endl; // Open kernel auto vadd = xrt::kernel(device, uuid, kernel_name); // Allocate buffers auto bo_a = xrt::bo(device, buffer_size, vadd.group_id(0)); auto bo_b = xrt::bo(device, buffer_size, vadd.group_id(1)); auto bo_c = xrt::bo(device, buffer_size, vadd.group_id(2)); // Initialize input data auto a_map = bo_a.map(); auto b_map = bo_b.map(); auto c_map = bo_c.map(); for (int i = 0; i < vector_size; i++) { a_map[i] = i; b_map[i] = i * 2; } // Transfer to device bo_a.sync(XCL_BO_SYNC_BO_TO_DEVICE, buffer_size, 0); bo_b.sync(XCL_BO_SYNC_BO_TO_DEVICE, buffer_size, 0); // Execute kernel: c = a + b auto run = vadd(bo_a, bo_b, bo_c, vector_size); std::cout << "Kernel started" << std::endl; // Wait for completion run.wait(); std::cout << "Kernel completed" << std::endl; // Transfer result back bo_c.sync(XCL_BO_SYNC_BO_FROM_DEVICE, buffer_size, 0); // Verify results int errors = 0; for (int i = 0; i < vector_size; i++) { int expected = a_map[i] + b_map[i]; if (c_map[i] != expected) { errors++; if (errors < 10) { std::cout << "Error at " << i << ": got " << c_map[i] << ", expected " << expected << std::endl; } } } if (errors == 0) { std::cout << "TEST PASSED" << std::endl; return 0; } else { std::cout << "TEST FAILED with " << errors << " errors" << std::endl; return 1; } } catch (const std::exception& e) { std::cerr << "Exception: " << e.what() << std::endl; return 1; } } ``` -------------------------------- ### Get Kernel Argument Offset using clGetKernelArgInfo Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This example shows how to use the XRT-specific parameter CL_KERNAL_ARG_OFFSET with the clGetKernelArgInfo API. This allows fetching the byte offset of a specific argument for a given kernel. ```c++ size_t foo_offset = 0; clGetKernelArgInfo(kernel, 2, CL_KERNEL_ARG_OFFSET, sizeof(foo_offset), &foo_offset, nullptr); ``` -------------------------------- ### xbtop Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xbtools_map.rst Launches the `xbtop` command, which is a separate utility for monitoring Xilinx devices. ```APIDOC ## xbtop ### Description Launches the `xbtop` utility for real-time monitoring of Xilinx devices. ### Method `xbtop` ### Parameters None ### Request Example ```bash xbtop ``` ### Response #### Success Response (200) Launches the `xbtop` interface. #### Response Example (Launches an interactive monitoring tool.) ``` -------------------------------- ### Install XRT Loader and Setup Scripts (CMake) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/tools/scripts/CMakeLists.txt This CMake code installs the defined loader and setup scripts. The installation location depends on whether XRT is being installed into a system default directory or a specific unwrapped directory. It conditionally installs these scripts based on the XRT_BASE variable. ```cmake if (XRT_BASE) # Do not install loader or setup scripts if installing into system default if (NOT XRT_INSTALL_BIN_DIR STREQUAL XRT_INSTALL_UNWRAPPED_DIR) install (PROGRAMS ${XRT_LOADER_SCRIPTS} DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR} COMPONENT ${XRT_BASE_COMPONENT}) install (FILES ${XRT_SETUP_SCRIPTS} DESTINATION ${XRT_INSTALL_DIR} COMPONENT ${XRT_BASE_COMPONENT}) endif() endif() ``` -------------------------------- ### Program Boot Image with xbflash2 Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xbflash2.rst This snippet demonstrates how to program a boot.bin image to a QSPIPS flash device using the xbflash2 tool. It covers basic programming and more advanced options like specifying offsets and BAR configurations. ```shell #Program the boot.bin image. xbflash2 program --qspips --device 0000:3b:00.0 --image ``` ```shell #Program the boot.bin image. xbflash2 program --qspips --device 0000:3b:00.0 --image --offset 0x0 --bar-offset 0x10000 --bar 0 ``` -------------------------------- ### xbmgmt Command Usage Example Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xbmgmt.rst Illustrates the basic command structure for configuring a device using the 'xbmgmt configure' command. It shows how to specify the target device via its management BDF and an input INI file for configuration. ```shell xbmgmt configure [--device| -d] [--input] ``` -------------------------------- ### Example XRT Run Recipe JSON Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/common/runner/recipe.md A sample 'recipe.json' file illustrating the structure for defining kernel resources, buffers, and execution parameters for an NPU design. It includes input and output buffers and kernel configuration. ```json { "header": { "xclbin": "design.xclbin" }, "resources": { "buffers": [ { "name": "wts", "type": "input" }, { "name": "ifm", "type": "input" }, { "name": "ofm", "type": "output" } ], "kernels": [ { "name": "k1", "instance": "DPU", "ctrlcode": "no-ctrl-packet.elf" } ] }, "execution": { "runs": [ { "name": "k1", "arguments" : [ { "name": "wts", "argidx": 4 }, { "name": "ifm", "argidx": 3 }, { "name": "ofm", "argidx": 5 } ], "constants": [ { "value": "3", "type": "int", "argidx": 0 }, { "value": "0", "type": "int", "argidx": 1 }, { "value": "0", "type": "int", "argidx": 2 }, { "value": "0", "type": "int", "argidx": 6 }, { "value": "0", "type": "int", "argidx": 7 } ] } ] } } ``` -------------------------------- ### Build and Install 'instance_query' Shared Library (CMake) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/edge/ps_kernels/xrt/instance_query/CMakeLists.txt This snippet defines the build process for a shared library named 'instance_query' using CMake. It specifies the source files, sets target properties like versioning, links necessary libraries, and defines the installation destination for the library. Dependencies include CMake and potentially other XRT libraries specified in target_link_libraries. ```cmake # 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") add_library(instance_query SHARED "instance_query.cpp" ) set_target_properties(instance_query PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION} ) target_link_libraries(instance_query PRIVATE ) install (TARGETS instance_query EXPORT xrt-targets LIBRARY DESTINATION ${PS_KERNEL_INSTALL_DIR} ) ``` -------------------------------- ### Install EPEL on CentOS 8.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the EPEL repository on CentOS 8.x systems. It configures the PowerTools and AppStream repositories and then installs the EPEL release package. This is required for XRT. ```shell yum config-manager --set-enabled PowerTools yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm yum config-manager --set-enabled AppStream ``` -------------------------------- ### Execute Kernel with Arguments and Wait for Completion (C++) Source: https://context7.com/xilinx/xrt/llms.txt Demonstrates how to execute a kernel with input and output buffers, and a scalar argument. It includes buffer allocation, data preparation, kernel execution, and waiting for completion before retrieving results. Dependencies include the xrt library. ```cpp const int COUNT = 1024; const size_t data_size = COUNT * sizeof(int); // Create kernel auto simple = xrt::kernel(device, uuid, "simple"); // Allocate buffers auto bo_in = xrt::bo(device, data_size, simple.group_id(0)); auto bo_out = xrt::bo(device, data_size, simple.group_id(1)); // Prepare input data auto in_map = bo_in.map(); auto out_map = bo_out.map(); for (int i = 0; i < COUNT; i++) { in_map[i] = i; } bo_in.sync(XCL_BO_SYNC_BO_TO_DEVICE, data_size, 0); // Execute kernel (creates run and starts it) auto run = simple(bo_in, bo_out, 0x10); // bo_in, bo_out, scalar arg // Wait for completion run.wait(); // Retrieve results bo_out.sync(XCL_BO_SYNC_BO_FROM_DEVICE, data_size, 0); for (int i = 0; i < COUNT; i++) { std::cout << out_map[i] << " "; } ``` -------------------------------- ### Create and Map P2P Buffer with XRT Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/p2p.rst Demonstrates the creation of a P2P buffer using OpenCL's clCreateBuffer with extended pointer information for Xilinx devices. It then shows how to map this buffer into the host's address space using clEnqueueMapBuffer for read and write operations. This is crucial for direct data transfer between the host and peripheral devices. ```c // Create P2P buffer p2pBO = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_EXT_PTR_XILINX, chunk_size, &p2pBOExt, NULL); // Set kernel argument clSetKernelArg(kernel, 0, sizeof(cl_mem), p2pBO); // Map P2P Buffer into the host space p2pPtr = (char *) clEnqueueMapBuffer(command_queue, p2pBO, CL_TRUE, CL_MAP_WRITE | CL_MAP_READ, 0, chunk_size, 0, NULL, NULL, NULL); ``` -------------------------------- ### Basic xrt.ini Configuration Example Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xrt_ini.rst A sample xrt.ini file demonstrating how to configure runtime logging to the console and enable timeline trace for debugging. This example shows the basic structure with group names and key-value pairs. ```ini #Start of Runtime group [Runtime] runtime_log = console #Start of Debug group [Debug] timeline_trace = true ``` -------------------------------- ### Build XCLBIN with run.sh and make Source: https://github.com/xilinx/xrt/blob/master/tests/xrt/100_ert_ncu/readme.txt This snippet demonstrates how to build an xclbin file using the run.sh script and a makefile (xclbin.mk). It requires specifying the DSA and MODE parameters. The command is executed from the directory containing the xclbin.mk file. ```shell % pwd % [run.sh] make -f xclbin.mk DSA=... MODE=... xclbin ``` -------------------------------- ### Define Kernel and CPU Execution Runs Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/common/runner/recipe.md This snippet demonstrates defining execution runs for kernels and CPU functions, including arguments, constants, and sub-buffer specifications (size and offset). It shows how to pass full resources or specific portions as arguments. ```json { "execution": { "runs": [ { "name": "convert_ifm", "where": "cpu", "arguments" : [ { "name": "ifm", "argidx": 0 }, { "name": "ifm_int", "argidx": 1 } ], "constants" : [ { "value": "nchw2nchw4c", "type": "string", "argidx": 2 } ] ] }, { "name": "k1", "arguments" : [ { "name": "ifm_int", "size": 512, "offset": 0, "argidx": 3 }, { "name": "wts", "argidx": 4 }, { "name": "ofm_int", "size": 512, "offset": 512, "argidx": 5 } ] }, { "name": "k1", "arguments" : [ { "name": "ifm_int", "size": 512, "offset": 512, "argidx": 3 }, { "name": "wts", "argidx": 4 }, { "name": "ofm_int", "size": 512, "offset": 0, "argidx": 5 } ] }, { "name": "convert_ofm", "where": "cpu" "arguments" : [ { "name": "ofm_int", "argidx": 0 }, { "name": "ofm", "argidx": 1 } ], "constants" : [ { "value": "nchw4c2nchw", "argidx": 2 } ] ] }, ... ] } } ``` -------------------------------- ### Install EPEL on RHEL 7.x Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Installs the Extra Packages for Enterprise Linux (EPEL) repository on RHEL 7.x systems, which is a prerequisite for installing XRT dependencies. It enables the optional RPMs repository and then installs the EPEL release package. ```shell sudo yum-config-manager --enable rhel-7-server-optional-rpms sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm ``` -------------------------------- ### XRT Kernel Instantiation Source: https://context7.com/xilinx/xrt/llms.txt Demonstrates how to instantiate and manage FPGA kernel execution contexts using the XRT C++ API. It covers opening kernels with shared or exclusive access, opening specific compute units, and querying kernel properties such as name, memory group, and argument offset. Dependencies include xrt/xrt_kernel.h and xrt/xrt_device.h. ```cpp // Open kernel with shared access (default) auto kernel = xrt::kernel(device, uuid, "vadd"); // Open specific compute units auto kernel_cu = xrt::kernel(device, uuid, "vadd:{vadd_1,vadd_2}"); // Open with exclusive access auto kernel_exclusive = xrt::kernel(device, uuid, "vadd", xrt::kernel::cu_access_mode::exclusive); // Query kernel properties std::string kernel_name = kernel.get_name(); int arg0_mem_group = kernel.group_id(0); uint32_t arg0_offset = kernel.offset(0); std::cout << "Kernel: " << kernel_name << ", arg0 bank: " << arg0_mem_group << std::endl; ``` -------------------------------- ### CMake Build Configuration for Xilinx XRT Application Source: https://github.com/xilinx/xrt/blob/master/tests/unit_test/036_hello/CMakeLists.txt This snippet configures the CMake build system for a Xilinx XRT project. It sets the minimum CMake version, defines the project name, includes utility scripts, and creates an executable target 'hello' from 'hello.cpp'. It links the XRT OpenCL library and platform-specific libraries like uuid and pthread for non-Windows systems. ```cmake # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2022 Xilinx, Inc. All rights reserved. # CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) set(TESTNAME "036_hello") PROJECT(${TESTNAME}) include(../../CMake/utils.cmake) add_executable(${TESTNAME} hello.cpp) target_link_libraries(${TESTNAME} PRIVATE ${xrt_xilinxopencl_LIBRARY}) if (NOT WIN32) target_link_libraries(${TESTNAME} PRIVATE ${uuid_LIBRARY} pthread) endif(NOT WIN32) install(TARGETS ${TESTNAME} RUNTIME DESTINATION ${INSTALL_DIR}/${TESTNAME}) ``` -------------------------------- ### Clone and Build XRT using build.sh Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/test.rst This snippet demonstrates the process of cloning the XRT repository from GitHub and building it using the provided `build.sh` script. The `build.sh` script compiles XRT for both Debug and Release profiles, which are necessary for using the `run.sh` and `board.sh` scripts. ```bash git clone https://github.com/Xilinx/XRT.git cd XRT/build ./build.sh ``` -------------------------------- ### Install XRT Development Packages to Sysroot (Bash) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/yocto.rst Installs XRT and its development packages (dev, dbg, lic, src) into the host system's sysroot. This involves downloading RPM files and using the `sysroots_overlay.sh` script to apply them. Requires the `sysroots_overlay.sh` script and specified RPM packages. ```bash # Excute the following scripts on development machine # Download XRT RPM wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic-updates/rpm/aarch64/xrt-202010.2.7.0-r0.0.aarch64.rpm wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic-updates/rpm/aarch64/xrt-dev-202010.2.7.0-r0.0.aarch64.rpm wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic-updates/rpm/aarch64/xrt-dbg-202010.2.7.0-r0.0.aarch64.rpm wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic-updates/rpm/aarch64/xrt-lic-202010.2.7.0-r0.0.aarch64.rpm wget http://petalinux.xilinx.com/sswreleases/rel-v2020/generic-updates/rpm/aarch64/xrt-src-202010.2.7.0-r0.0.aarch64.rpm # Download sysroot overlay scripts wget https://raw.githubusercontent.com/Xilinx/XRT/master/src/runtime_src/tools/scripts/sysroots_overlay.sh # Generate RPM list file ls *.rpm > rpm.txt # Overlay RPM to sysroot ./sysroots_overlay.sh -s /aarch64-xilinx-linux/ -r ./rpm.txt ``` -------------------------------- ### Specify Host-Only Buffer with CL_MEM_EXT_PTR_XILINX Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This C++ code illustrates how to create a host-only buffer using `cl_mem_ext_ptr_t` and the `CL_MEM_EXT_PTR_XILINX` flag. It shows the structure setup for `XCL_MEM_EXT_HOST_ONLY` and its use with the `cl::Buffer` constructor. ```c++ cl_mem_ext_ptr_t host_buffer_ext = {0}; host_buffer_ext.flags = XCL_MEM_EXT_HOST_ONLY; cl::Buffer host_buffer (context,CL_MEM_READ_ONLY |CL_MEM_EXT_PTR_XILINX, size, &host_buffer_ext); ``` -------------------------------- ### Build Custom C/C++ Application with PetaLinux Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/yocto.rst This snippet illustrates the process of creating and building a custom C/C++ application within a PetaLinux project. It involves using `petalinux-create` to generate an application template, modifying the source files, and then rebuilding the system image to include the custom application. ```bash $ petalinux-create -t apps [--template TYPE] --name --enable # Change to the newly created application directory. $ cd /project-spec/meta-user/recipes-apps/myapp # Edit myapp.c/myapp.cpp with your source code. # Build the PetaLinux system image with the application. $ petalinux-build ``` -------------------------------- ### Start XRT AIE Performance Profiling in C Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xrt_native_apis.rst This code demonstrates starting performance counters in the AI Engine using the xrt::aie::profiling::start function. It configures counters based on provided options and port information, returning a handle for subsequent operations. ```c auto graph = xrt::graph(device, xclbin_uuid, "graph_name"); auto handle = event.start(xrt::aie::profiling::profiling_option option, std::string& port1, std::string& port2, int value); // run graph ... s2mm_run.wait(); ``` -------------------------------- ### Reinstall XRT on Ubuntu Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Reinstalls the XRT software stack on Ubuntu systems using a local DEB package. This command is useful for troubleshooting or applying updates. Replace `` with the actual XRT version. ```shell sudo apt install --reinstall ./xrt_.deb ``` -------------------------------- ### Reinstall XRT on RHEL/CentOS Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/install.rst Reinstalls the XRT software stack on RHEL or CentOS systems using a local RPM package. This command is useful for troubleshooting or applying updates. Replace `` with the actual XRT version. ```shell sudo yum reinstall ./xrt_.rpm ``` -------------------------------- ### Get Memory Object Bank Index using clGetMemObjectInfo Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This code illustrates the use of the XRT-specific parameter CL_MEM_BANK with the clGetMemObjectInfo API. It enables retrieval of the memory bank index associated with an OpenCL buffer object. ```c++ int mem_bank_index = 0; clGetMemObjectInfo(buf, CL_MEM_BANK, sizeof(int), &mem_bank_index, nullptr); ``` -------------------------------- ### Enable P2P with xrt-smi Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/p2p.rst Enables Peer-to-Peer (P2P) transfer for a specified device. This command requires root privileges. A warm reboot might be necessary if the system cannot allocate IO memory. Verify P2P status using 'xrt-smi examine'. ```bash # sudo xrt-smi configure --device 0000:b3:00.1 --p2p enable ``` -------------------------------- ### Get Kernel Compute Unit Count using clGetKernelInfo Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This snippet demonstrates how to extend the clGetKernelInfo API with XRT-specific parameters to retrieve the number of compute units (CUs) associated with a kernel object. The CL_KERNEL_COMPUTE_UNIT_COUNT parameter is used for this purpose. ```c++ cl_uint numcus = 0; clGetKernelInfo(kernel,CL_KERNEL_COMPUTE_UNIT_COUNT,sizeof(cl_uint),&numcus,nullptr); ``` -------------------------------- ### xbmgmt help/version Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xbtools_map.rst Provides help information or displays the version of the `xbmgmt` tool. ```APIDOC ## xbmgmt help/version ### Description Provides help information or displays the version of the `xbmgmt` tool. ### Method `xbmgmt` ### Parameters #### Path Parameters None #### Query Parameters - **help** (string) - Optional - Displays help information for `xbmgmt`. - **--help** (string) - Optional - Alias for `help`. - **version** (string) - Optional - Displays the version of `xbmgmt`. - **--version** (string) - Optional - Alias for `version`. #### Request Body None ### Request Example ```bash xbmgmt --help xbmgmt --version ``` ### Response #### Success Response (200) Displays help text or the version information. #### Response Example ``` # Example for --help Usage: xbmgmt [options] ... (help text) ... # Example for --version Xilinx xbmgmt tool version x.y.z ``` ``` -------------------------------- ### XRT Device Management Source: https://context7.com/xilinx/xrt/llms.txt Demonstrates how to open and manage Xilinx FPGA devices using the XRT C++ API. This includes opening devices by index or PCIe BDF, loading xclbin files, and querying device information. Dependencies include the xrt/xrt_device.h header. ```cpp #include "xrt/xrt_device.h" #include "xrt/xrt_kernel.h" #include "xrt/xrt_bo.h" // Open device by index auto device = xrt::device(0); // Or open by PCIe BDF (Bus:Device.Function) auto device2 = xrt::device("0000:03:00.1"); // Load xclbin (FPGA bitstream) auto uuid = device.load_xclbin("kernel.xclbin"); // Query device information auto device_name = device.get_info(); auto bdf = device.get_info(); bool has_m2m = device.get_info(); std::cout << "Device: " << device_name << " at " << bdf << std::endl; ``` -------------------------------- ### Specify Buffer Location by Kernel and Argument Index using CL_MEM_EXT_PTR_XILINX Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This C++ example illustrates specifying a buffer's location relative to a kernel argument. It involves setting the `argidx` and `kernel` fields of the `cl_mem_ext_ptr_t` structure and then calling `clCreateBuffer` with `CL_MEM_EXT_PTR_XILINX`. ```c++ ext.argidx = idx; ext.kernel = kernel; cl_int error; clCreateBuffer(context,CL_MEM_EXT_PTR_XILINX,size,&ext,&error); ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/xilinx/xrt/blob/master/tests/mcdm/CMakeLists.txt Configures the CMake build system for the Xilinx XRT project. It sets the minimum required CMake version, project name, C++ standard, and build verbosity. It also defines environment variables and sets up the installation directory. ```cmake # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2019-2022 Xilinx, Inc. All rights reserved. # CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) PROJECT(XRT_TESTCASES) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED OFF) set(CMAKE_VERBOSE_MAKEFILE ON) set(XILINX_XRT $ENV{XILINX_XRT}) set(XRT_CORE_LIBRARY xrt_core) if (NOT DEFINED ${INSTALL_DIR}) set(INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE}/${MODE}") endif() add_subdirectory(probe) ``` -------------------------------- ### Specify DDR Bank Location by Name using CL_MEM_EXT_PTR_XILINX Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst This C++ example shows how to explicitly set a buffer's location to a specific DDR bank (e.g., DDR_BANK0) using `cl_mem_ext_ptr_t` and `CL_MEM_EXT_PTR_XILINX`. It utilizes flags like `XCL_MEM_DDR_BANK0` and the `clCreateBuffer` function. ```c++ cl_mem_ext_ptr_t ext = {0}; ext.banks = XCL_MEM_DDR_BANK0; cl_int error; clCreateBuffer(context,CL_MEM_EXT_PTR_XILINX,size,&ext,&error); ``` -------------------------------- ### XRT Execution Configuration Example (JSON) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/common/runner/profile.md This JSON snippet demonstrates the structure and available parameters for configuring recipe execution within an XRT profile. It includes settings for iteration count, verbosity, validation, runlist thresholds, execution mode, and depth. ```json { "name": "myexecution", // custom id for this execution "iterations": 500, // default one iteration "verbose": false, // disable reporting of cpu time "validate": true, // validate after all iterations "runlist_threshold": 1 // when to use xrt::runlist "mode": mode, // latency, throughput, or validate "depth": depth // clone the recipe runlist "iteration" : { } } ``` -------------------------------- ### Get Compute Unit Information using xclGetComputeUnitInfo Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/opencl_extension.rst The xclGetComputeUnitInfo API retrieves specific details about a compute unit (CU) within a kernel. It requires flags like XCL_COMPUTE_UNIT_INDEX or XCL_COMPUTE_UNIT_BASE_ADDRESS to fetch the desired information, such as the CU's index or base memory address. ```c++ cl_uint cuidx; xclGetComputeUnitInfo(kernel,0,XCL_COMPUTE_UNIT_INDEX,sizeof(cuidx),&cuidx,nullptr); size_t cuaddr; xclGetComputeUnitInfo(kernel,0,XCL_COMPUTE_UNIT_BASE_ADDRESS,sizeof(cuaddr),&cuaddr,nullptr); ``` -------------------------------- ### Create and Configure PetaLinux Project with XRT Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/yocto.rst This snippet shows the commands to create a PetaLinux project, configure hardware description, and enable XRT components within the kernel and root filesystem. It ensures necessary packages like xrt, xrt-dev, zocl, and OpenCL headers are included for XRT functionality. ```bash $ petalinux-create -t project -n --template zynqMP # Get XSA file, which is exported by Vivado $ petalinux-config -p --get-hw-description= # Configure Linux kernel $ petalinux-config -c kernel # Configure rootfs, enable XRT components # menu -> "user packages" -> xrt # menu -> "user packages" -> xrt-dev # menu -> "user packages" -> zocl # menu -> "user packages" -> opencl-headers-dev # menu -> "user packages" -> opencl-clhpp-dev $ petalinux-config -c rootfs # Build package $ petalinux-build ``` -------------------------------- ### Install xclbinutil Executable and Scripts Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/tools/xclbinutil/CMakeLists.txt Defines installation rules for the xclbinutil executable and its associated loader scripts. The executable is installed to a runtime directory, and scripts are installed to the binary directory, with conditions to avoid redundant installation if directories are the same. ```cmake install (TARGETS ${XCLBINUTIL_NAME} RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR} COMPONENT ${XRT_BASE_COMPONENT}) # Do not install loader scripts if installing into system default if (NOT XRT_INSTALL_BIN_DIR STREQUAL XRT_INSTALL_UNWRAPPED_DIR) install (PROGRAMS ${XRT_LOADER_SCRIPTS} DESTINATION ${XRT_INSTALL_BIN_DIR} COMPONENT ${XRT_BASE_COMPONENT}) endif() ``` -------------------------------- ### Partition Programming API Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xbtools_map.rst Commands for programming partitions on Xilinx devices. ```APIDOC ## Partition Programming ### Description Used to program specific partitions on Xilinx devices. ### Method CLI Command ### Endpoint N/A (CLI tool) ### Parameters #### Command Options - **partition program** - Initiates the partition programming process. - **--card <bdf>** - Required. Specifies the Bus:Device.Function identifier of the target card. - **--device <bdf>** - Required. Specifies the Bus:Device.Function identifier of the target device (can be same as --card). - **--program** - Indicates that programming should occur. - **--name <shell name>** - Specifies the name of the shell partition to program. - **--shell <shell-file w/ path>** - Specifies the path to the shell file to program. - **--path <xclbin w/ path>** - Specifies the path to the XCLBIN file for programming. - **--user <xclbin w/ path>** - Specifies the path to the user XCLBIN file for programming. ### Request Example ```bash xrt partition --program --card 0000:01:00.0 --name my_shell --shell /path/to/shell.bin ``` ### Response #### Success Response Indicates successful completion of the partition programming operation. #### Response Example ``` Partition programming successful. ``` ``` -------------------------------- ### Build Executable and Link Libraries (CMake) Source: https://github.com/xilinx/xrt/blob/master/tests/unit_test/010_mmult2/CMakeLists.txt This snippet defines the main executable for the test case and links it against the necessary Xilinx XRT libraries. It conditionally links additional libraries for non-Windows platforms. ```cmake CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0) set(TESTNAME "010_mmult2") PROJECT(${TESTNAME}) include(../../CMake/utils.cmake) add_executable(${TESTNAME} test-cl.cpp) target_link_libraries(${TESTNAME} PRIVATE ${xrt_xilinxopencl_LIBRARY}) if (NOT WIN32) target_link_libraries(${TESTNAME} PRIVATE ${uuid_LIBRARY} pthread) endif(NOT WIN32) ``` -------------------------------- ### Install Nagios Plugin Script (CMake) Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/tools/nagios/CMakeLists.txt This CMake snippet installs the `nagios_plugin.sh` script to the specified Nagios plugins directory. The installation is conditional on the `XRT_EDGE` variable not being set. It defines the destination path and the component for installation. ```cmake set(XRT_NAGIOS_INSTALL "${XRT_INSTALL_DIR}/etc/nagios-plugins") # Determine the name of the executable set(NAGIOS_LOADER_SCRIPTS "nagios_plugin.sh") if (NOT XRT_EDGE) install (PROGRAMS ${NAGIOS_LOADER_SCRIPTS} DESTINATION ${XRT_NAGIOS_INSTALL} COMPONENT ${XRT_BASE_COMPONENT}) endif() ``` -------------------------------- ### XRT Native Library C API - Device and XCLBIN APIs Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/doc/toc/xrt_native.main.rst Documentation for Device and XCLBIN APIs in the XRT Native Library C interface, detailed in `xrt_device.rst` and `xrt_xclbin.rst`. ```APIDOC ## XRT Native Library C API - Device and XCLBIN APIs ### Description Provides C-style functions for interacting with devices and managing XCLBIN files. ### Files `../core/xrt_device.rst`, `../core/xrt_xclbin.rst` ### Functions (Refer to the content of `xrt_device.rst` and `xrt_xclbin.rst` for specific C functions and their usage.) ### Usage Example ```c // Placeholder for C device/XCLBIN API usage // Example: xrt_device_handle dev = xrt_device_open("device_name"); // Example: xrt_xclbin_handle xclbin = xrt_xclbin_read("path/to/your.xclbin"); ``` ``` -------------------------------- ### Installation Rules Source: https://github.com/xilinx/xrt/blob/master/src/runtime_src/core/tools/xbmgmt2/CMakeLists.txt This CMake code defines the installation rules for the `xbmgmt` executable and its loader scripts. It specifies the runtime destination directory and component for installation, with conditional logic to avoid installing loader scripts if installing into the system default directory. ```cmake if (NOT XRT_EDGE) install (TARGETS ${XBMGMT2_NAME} RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR} COMPONENT ${XRT_BASE_COMPONENT}) # Do not install loader scripts if installing into system default if (NOT XRT_INSTALL_BIN_DIR STREQUAL XRT_INSTALL_UNWRAPPED_DIR) install (PROGRAMS ${XRT_LOADER_SCRIPTS} DESTINATION ${XRT_INSTALL_BIN_DIR} COMPONENT ${XRT_BASE_COMPONENT}) endif() endif() ```