* libhsakmt/virtio: Add alloc memory align api Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Rename CLGL BO to AMDGPU BO Rename VHSA_BO_CLGL to VHSA_BO_AMDGPU to support generic AMDGPU buffer objects, not just CL/GL interop. * libhsakmt/virtio: Add atomic helpers and node lookup Add vhsakmt_atomic_inc/dec macros and vhsakmt_get_node_by_id helper function. * libhsakmt/virtio: Add AMDGPU device initialization support Add vamdgpu_device_initialize and vamdgpu_device_deinitialize functions. * libhsakmt/virtio: Add AMDGPU device handle and DRM command support Add vamdgpu_device_get_fd, vdrmCommandWriteRead and update vhsaKmtGetAMDGPUDeviceHandle. * libhsakmt/virtio: Add AMDGPU BO free and CPU map support Add vamdgpu_bo_free and vamdgpu_bo_cpu_map functions. * libhsakmt/virtio: Add AMDGPU BO import and export support Add vamdgpu_bo_import, vamdgpu_bo_export and vhsakmt_bo_from_resid functions. * libhsakmt/virtio: Add AMDGPU BO VA operation support Add vamdgpu_bo_va_op function. * libhsakmt/virtio: Add dma buf export support Add vhsaKmtExportDMABufHandle API in virtio driver to support export feature. * libhsakmt/virtio: Fix potential deadlock in userptr deregistration Refactor vhsakmt_deregister_userptr_non_svm to avoid calling vhsakmt_destroy_userptr while holding the bo_handles_mutex lock. Previously, destroying userptrs directly while iterating the tree could cause deadlock issues due to nested locking. - Move interval tree removal from vhsakmt_destroy_userptr to caller - Collect BOs to free in a temporary array during tree traversal - Destroy BOs after releasing the mutex to avoid lock contention - Use dynamic array with realloc to handle arbitrary number of BOs Signed-off-by: Honglei Huang <honghuan@amd.com> * rocr: driver/virtio: Implement DMA-BUF import/export and memory mapping APIs Implement the missing DMA-BUF handling and memory mapping functions in the virtio KFD driver to enable cross-process memory sharing: - ExportDMABuf: Export HSA memory as DMA-BUF file descriptor - ImportDMABuf: Import DMA-BUF fd as shareable buffer object - Map: Map imported buffer into virtual address space with permissions - Unmap: Unmap buffer from virtual address space - ReleaseShareableHandle: Free imported buffer object Also add drm_perm() helper to convert HSA access permissions to AMDGPU VM page flags (READABLE/WRITEABLE). These APIs enable IPC memory sharing between HSA processes through DMA-BUF mechanism in virtualized environments. Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add register memory APIs Add two new memory registration functions to the virtio HSA KMT library: 1. vhsaKmtRegisterMemory: A simplified wrapper for vhsaKmtRegisterMemoryWithFlags that uses default CoarseGrain memory flags. 2. vhsaKmtRegisterMemoryToNodes: A stub implementation for registering memory to specific nodes. Returns HSAKMT_STATUS_NOT_IMPLEMENTED as it's currently not used in ROCR. Changes: - Added function declarations in hsakmt_virtio.h - Implemented functions in hsakmt_virtio_memory.c - Exported symbols in libhsakmt_virtio.ver Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add graphics handle registration and mapping APIs - Add vhsaKmtRegisterGraphicsHandleToNodesExt() with flags support - Add vhsaKmtMapGraphicHandle() and vhsaKmtUnmapGraphicHandle() stubs - Refactor existing registration API to use extended version Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add virtio support for queue APIs Implement vhsaKmtUpdateQueue, vhsaKmtSetQueueCUMask, vhsaKmtAllocQueueGWS and vhsaKmtGetQueueInfo functions with virtio protocol extensions and symbol exports. Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add new virtio API support for model, SMI, and XNACK mode Add three new API functions to the virtio backend: - vhsaKmtModelEnabled: Check if pre-silicon model is enabled (returns false for virtio) - vhsaKmtOpenSMI: Open SMI interface for a node (not yet supported in virtio) - vhsaKmtSetXNACKMode: Set XNACK mode via virtio control command Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add shared memory support for virtio backend Implement shared memory APIs for the virtio backend to enable memory sharing between processes: - Add vhsaKmtShareMemory() to share memory regions and create shared memory handles - Add vhsaKmtRegisterSharedHandle() to register shared memory handles in the current process - Add vhsaKmtRegisterSharedHandleToNodes() for node-specific shared memory registration Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add memory management APIs for virtio Add the following new memory management APIs to virtio implementation: - vhsaKmtSetMemoryUserData: Set user data for memory pointer - vhsaKmtSetMemoryPolicy: Configure memory policy for nodes - vhsaKmtSVMGetAttr: Get SVM (Shared Virtual Memory) attributes - vhsaKmtSVMSetAttr: Set SVM attributes - vhsaKmtReplaceAsanHeaderPage: ASAN header page replacement (stub) - vhsaKmtReturnAsanHeaderPage: ASAN header page return (stub) Changes include: - Added API declarations in hsakmt_virtio.h - Implemented functions in hsakmt_virtio_memory.c - Extended protocol definitions in hsakmt_virtio_proto.h - Added user_data field to vhsakmt_bo structure - Exported new symbols in libhsakmt_virtio.ver Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add SPM APIs Add three new SPM-related APIs to the virtio interface: - vhsaKmtSPMAcquire: Acquire SPM resources on a preferred node - vhsaKmtSPMRelease: Release SPM resources on a preferred node - vhsaKmtSPMSetDestBuffer: Set destination buffer for SPM data with optional userptr support and data loss detection These APIs extend the virtio command protocol with new query types: - VHSAKMT_CCMD_QUERY_SPM_ACQUIRE - VHSAKMT_CCMD_QUERY_SPM_RELEASE - VHSAKMT_CCMD_QUERY_SPM_SET_DST_BUFFER The implementation includes proper buffer management for both direct BO access and userptr fallback for smaller buffers. Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add virtio stub for hsaKmtAisReadWriteFile API Add vhsaKmtAisReadWriteFile stub implementation for the virtio backend to support AIS (Accelerated I/O Service) file read/write operations. This stub currently returns HSAKMT_STATUS_NOT_IMPLEMENTED. Changes include: - Add vhsaKmtAisReadWriteFile declaration in hsakmt_virtio.h - Add stub implementation in hsakmt_virtio_memory.c - Export the symbol in libhsakmt_virtio.ver Signed-off-by: energystoryhhl <energystoryhhl@users.noreply.github.com> * libhsakmt/virtio: Add vamdgpu_bo_query_info and vamdgpu_bo_set_metadata APIs Implement two new virtio wrapper functions for AMDGPU buffer object operations: 1. vamdgpu_bo_query_info: Query buffer object information including allocation parameters, memory usage, and metadata. 2. vamdgpu_bo_set_metadata: Set metadata for a buffer object, allowing applications to attach custom data to GPU memory allocations. Signed-off-by: Honglei Huang <honghuan@amd.com> * libhsakmt/virtio: Add ProcessVMRead/Write stub implementations for virtio Add vhsaKmtProcessVMRead and vhsaKmtProcessVMWrite stub functions to the virtio interface. These APIs return HSAKMT_STATUS_NOT_IMPLEMENTED since they are not supported in the baremetal implementation, matching the behavior of the deprecated hsaKmtProcessVMRead/Write APIs. Signed-off-by: energystoryhhl <energystoryhhl@users.noreply.github.com> --------- Signed-off-by: Honglei Huang <honghuan@amd.com> Signed-off-by: energystoryhhl <energystoryhhl@users.noreply.github.com> Co-authored-by: energystoryhhl <energystoryhhl@users.noreply.github.com>
ROCR Runtime
This ROCm Runtime (ROCr) repo combines 2 previously separate repos into a single repo:
- The HSA Runtime (
hsa-runtime) for AMD GPU application development and - The ROCt Thunk Library (
libhsakmt), a "thunk" interface to the ROCm kernel driver (ROCk), used by the runtime.
Infrastructure
The HSA runtime is a thin, user-mode API that exposes the necessary interfaces to access and interact with graphics hardware driven by the AMDGPU driver set and the ROCK kernel driver. Together they enable programmers to directly harness the power of AMD discrete graphics devices by allowing host applications to launch compute kernels directly to the graphics hardware.
The capabilities expressed by the HSA Runtime API are:
- Error handling
- Runtime initialization and shutdown
- System and agent information
- Signals and synchronization
- Architected dispatch
- Memory management
- HSA runtime fits into a typical software architecture stack.
The HSA runtime provides direct access to the graphics hardware to give the programmer more control of the execution. An example of low level hardware access is the support of one or more user mode queues provides programmers with a low-latency kernel dispatch interface, allowing them to develop customized dispatch algorithms specific to their application.
The HSA Architected Queuing Language is an open standard, defined by the HSA Foundation, specifying the packet syntax used to control supported AMD/ATI Radeon (c) graphics devices. The AQL language supports several packet types, including packets that can command the hardware to automatically resolve inter-packet dependencies (barrier AND & barrier OR packet), kernel dispatch packets and agent dispatch packets.
In addition to user mode queues and AQL, the HSA runtime exposes various virtual address ranges that can be accessed by one or more of the system's graphics devices, and possibly the host. The exposed virtual address ranges either support a fine grained or a coarse grained access. Updates to memory in a fine grained region are immediately visible to all devices that can access it, but only one device can have access to a coarse grained allocation at a time. Ownership of a coarse grained region can be changed using the HSA runtime memory APIs, but this transfer of ownership must be explicitly done by the host application.
Programmers should consult the HSA Runtime Programmer's Reference Manual for a full description of the HSA Runtime APIs, AQL and the HSA memory policy.
Known issues
- Each HSA process creates an internal DMA queue, but there is a system-wide limit of four DMA queues. When the limit is reached HSA processes will use internal kernels for copies.
Artifacts produced by the build
- libhsakmt (ROCt) - User-mode API interfaces for interacting with the ROCk driver
- Runtime (ROCr) - Core runtime supporting HSA standards
- rocrtst - Runtime test suites for HSA implementation validation and performance testing
- kfdtest - Validation tests for ROCt
Building the ROCR Runtime
Target platform requirements
Please see the ROCm System requirements (Linux).
Ensure you have the following installed:
- CMake 3.7 or higher
libelf-devg++libdrm-amdgpu-devorlibdrm-devpkg-configrocm-corerocm-llvm-dev
ROCr & ROCt Build Instructions
- Clone this repository and cd into its root
- Prepare the build directory
mkdir build && cd build - Configure the build (example)
e.g:
cmake -DCMAKE_INSTALL_PREFIX=<rocm install dir> ..cmake -DCMAKE_INSTALL_PREFIX=/opt/rocm .. - Compile the project
make - Install the runtime
make install - (Optional) Build packages
make package
Non-default CMake Build Options
-
Produce a release build instead of debug
-DCMAKE_BUILD_TYPE=Release -
Control whether libhsakmt and libhsa-runtime are shared or static libhsakmt is always built as a static library that gets linked into libhsa-runtime, so there is a single library generated called libhsa-runtime64{.so/.a}. If
BUILD_SHARED_LIBSis not set, this is a shared library by default. SettingBUILD_SHARED_LIBStoOFFwill make it static.-DBUILD_SHARED_LIBS=ON # or OFF for static lib
Building the tests
rocrtst
- Go to rocrtst root
cd <rocr-runtime>/rocrtst/suites/test_common - Prepare the build directory
mkdir build && cd build - Configure the build
Example configuration:
cmake \ -DCMAKE_PREFIX_PATH="<rocm install root>;<llvm install root>" \ -DROCM_DIR="$ROCM_INSTALL_PATH" \ -DOPENCL_DIR="<rocm install root>" \ .. - Compile the project
make make rocrtst_kernels - ** Run the tests
Make sure libhsa-runtime.so is in the library path; e.g.,
$ LD_LIBRARY_PATH=<rocm install root> ./rocrtst -h # See help options
kfdtest
- Go to kfdtest root
cd <rocr-runtime>/libhsakmt/tests/kfdtest - Prepare the build directory
mkdir build && cd build - Configure the build
Example configuration:
cmake \ -DCMAKE_PREFIX_PATH="<rocm install root>" \ -DROCM_DIR="$ROCM_INSTALL_PATH" \ .. - Compile the project
make
Using the ROCR Runtime
After installation, you can link against the runtime by using the provided CMake package configurations. For example, to use the ROCR runtime in your project:
find_package(hsa-runtime64 1.0 REQUIRED)
add_executable(MyApp main.cpp)
target_link_libraries(MyApp PRIVATE hsa-runtime64::hsa-runtime64)
Disclaimer
The information contained herein is for informational purposes only, and is subject to change without notice. While every precaution has been taken in the preparation of this document, it may contain technical inaccuracies, omissions and typographical errors, and AMD is under no obligation to update or otherwise correct this information. Advanced Micro Devices, Inc. makes no representations or warranties with respect to the accuracy or completeness of the contents of this document, and assumes no liability of any kind, including the implied warranties of noninfringement, merchantability or fitness for particular purposes, with respect to the operation or use of AMD hardware, software or other products described herein. No license, including implied or arising by estoppel, to any intellectual property rights is granted by this document. Terms and limitations applicable to the purchase or use of AMD's products are as set forth in a signed agreement between the parties or in AMD's Standard Terms and Conditions of Sale.
AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies.
Copyright © 2014-2024 Advanced Micro Devices, Inc. All rights reserved.