In the ROCm compute stack, every piece of device memory allocated by an application corresponds to a buffer object (BO) in the kernel. A BO carries three responsibilities at once: it describes a range of physical storage (VRAM or system memory), it records the mappings of that storage in the various address spaces, and it takes part in runtime management such as eviction, migration and cross-device sharing. Multi-GPU systems amplify the complexity of all three: the same storage must be mapped into the page tables of several GPUs, and the mapping method depends on the type of interconnect between the GPUs. This article follows the execution of a dual-GPU compute program to establish the overall structure of the KFD driver, introduces the four address spaces involved with a BO, and presents the basic composition of the four-layer BO structure as the foundation for the rest of the book.
1 Multi-GPU Compute Scenario
1.1 Example Program
The following HIP program allocates one buffer on each of two GPUs, enables GPU 0 to access the VRAM of GPU 1, launches a compute kernel on GPU 0, and copies the result back to host memory.
float *a0, *a1;
hipSetDevice(0); hipMalloc(&a0, size); /* VRAM of GPU 0 */
hipSetDevice(1); hipMalloc(&a1, size); /* VRAM of GPU 1 */
hipSetDevice(0); hipDeviceEnablePeerAccess(1, 0); /* GPU 0 accesses GPU 1 VRAM */
hipLaunchKernelGGL(kern, grid, block, 0, 0, a0, a1);
hipMemcpy(host, a0, size, hipMemcpyDeviceToHost);
hipFree(a1);
hipFree(a0);
The program involves only five kinds of operations: allocation, peer access, kernel launch, data copy and release. In the kernel, however, these operations trigger a sequence of actions including device discovery, process context setup, BO allocation, multi-GPU page table mapping and queue creation. The HIP runtime translates these operations into calls to ROCr, and ROCr issues ioctls to /dev/kfd through libhsakmt.
1.2 Execution Stages and KFD Interfaces
Figure 1 divides the execution of the example program into eight stages and lists, for each stage, the user-space call, the kernel interface, and the kernel objects created or modified.

Figure 1 Execution stages of a multi-GPU compute program and the KFD interfaces
The key points of each stage are as follows:
- Device discovery. The runtime opens
/dev/kfd, and the kernel creates akfd_processfor the calling process. The runtime then reads the topology nodes under/sys/class/kfd/kfd/topologyto obtain the list of GPUs in the system, the VRAM capacity of each GPU, and the XGMI links between GPUs. - Process and per-GPU VM. The runtime opens the render node (
/dev/dri/renderD*) of each GPU and callsAMDKFD_IOC_ACQUIRE_VMwith its file descriptor. The kernel creates akfd_process_devicefor the process on that GPU and converts theamdgpu_vmbelonging to the render node file into a compute VM. On a dual-GPU system, the same process therefore owns two independent GPU address spaces. - Allocation. The allocation step of
hipMalloccallsAMDKFD_IOC_ALLOC_MEMORY_OF_GPU. The kernel selects a memory domain according to the allocation flags, creates anamdgpu_bo, and records the allocation in akgd_mem. The GPU virtual address is chosen by the user-space runtime before the call and passed to the kernel as an argument. - GPU-side mapping. The arguments of
AMDKFD_IOC_MAP_MEMORY_TO_GPUcarry a list of target GPUs. For each GPU in the list, the kernel creates akfd_mem_attachment, adds anamdgpu_bo_vato that GPU’samdgpu_vm, and updates the GPUVM page tables.hipDeviceEnablePeerAccessadds mappings of existing allocations on the peer GPU through the same interface. - CPU-side access. The allocation interface returns an mmap offset. The runtime calls
mmapon the render node with this offset; the kernel locates the BO through the DRM fake offset mechanism and fills the CPU page tables on page faults. Special regions such as doorbells and MMIO are mapped throughmmapon/dev/kfd. - Queue execution.
AMDKFD_IOC_CREATE_QUEUEcreates a user-mode compute queue for the process. The kernel allocates an MQD (Memory Queue Descriptor) and hands the queue over to the hardware scheduler. From then on, user space writes the ring buffer and updates the doorbell directly, and submission no longer goes through the kernel. - Eviction and restore. VRAM pressure or an MMU notifier invalidation causes the kernel to suspend all queues of the process, migrate or revalidate the BOs, and then resume the queues. This process is driven by
amdgpu_amdkfd_fenceand the restore work queue, and is transparent to the application. - Release.
hipFreecallsAMDKFD_IOC_UNMAP_MEMORY_FROM_GPUand thenAMDKFD_IOC_FREE_MEMORY_OF_GPU. The kernel removes the page table mappings on each GPU and frees the attachments, the BO and its backing storage.
Among these stages, stages 3, 4 and 5 directly determine BO creation, physical placement and address mapping, and stage 7 determines how BO placement changes at runtime. These four stages form the focus of the book.
2 KFD Driver Overview
2.1 Layered Structure
The execution of the example program spans the user-space runtime, two kernel drivers and several hardware devices. Figure 2 shows the layering of these components.

Figure 2 Layered overview of the KFD driver
User space consists of the HIP runtime, ROCr (the HSA runtime) and libhsakmt. libhsakmt is the direct caller of the KFD ioctls; it is responsible for allocating GPU virtual addresses, parsing topology information, and wrapping the memory and queue interfaces. Access to the render node is performed by libdrm_amdgpu.
In the kernel, compute functionality is split between two drivers. amdkfd is the compute driver, responsible for process management (kfd_process, kfd_process_device), user-mode queue management (DQM and MQD), SVM and topology. amdgpu is the base driver, responsible for GPUVM page tables, BO management, and the integration with TTM and DRM/GEM. The two drivers interact through the amdgpu_amdkfd_* family of functions. The memory-related interfaces are concentrated in amdgpu_amdkfd_gpuvm.c with the prefix amdgpu_amdkfd_gpuvm_, for example amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu() and amdgpu_amdkfd_gpuvm_map_memory_to_gpu(). With this division, amdkfd does not manipulate page tables or BOs directly; it delegates the work to amdgpu using kgd_mem as the handle.
At the hardware level, each GPU contains a GPU MMU (which walks the GPUVM page tables), local VRAM, and the HWS or MES that schedules compute queues. GPUs access each other’s VRAM over XGMI or PCIe P2P, while GPU access to system memory goes through PCIe and the IOMMU.
2.2 Two Kinds of Device Nodes
A KFD process uses two kinds of device nodes at the same time. /dev/kfd is the single system-wide compute device node and carries all compute ioctls, including process, queue, memory allocation and mapping operations. The render node of each GPU provides the DRM file context of that GPU, which contains an amdgpu_vm private to the file.
AMDKFD_IOC_ACQUIRE_VM links the two kinds of nodes. In kfd_ioctl_acquire_vm(), the kernel obtains the render node’s drm_file from the file descriptor passed by user space, stores it as drm_priv in the kfd_process_device, and calls amdgpu_amdkfd_gpuvm_acquire_process_vm() to convert the contained amdgpu_vm into a compute VM. From then on, KFD obtains the VM on that GPU through drm_priv_to_vm(pdd->drm_priv), and CPU mappings of BOs are also established through the same render node.
2.3 Multi-GPU Organization
kfd_process stores the process’s kfd_process_device instances for all GPUs in the array pdds[MAX_GPU_INSTANCE], and n_pdds records the number of valid entries. Each kfd_process_device corresponds to one GPU and one amdgpu_vm, so a process on N GPUs owns N independent sets of GPUVM page tables.
ROCm uses a unified virtual address design: the same allocation uses the same GPU virtual address on all GPUs. libhsakmt manages these addresses centrally, which guarantees that a pointer refers to the same data in kernel code running on any GPU. Correspondingly, kgd_mem stores a single va field in the kernel, and this address is used when mapping onto every GPU; the difference appears only in the contents of each GPU’s page table entries.
3 The Four-Layer BO Structure
3.1 Composition
An AMDGPU BO is not a single structure. It is described jointly by structures at four layers: DRM, TTM, the AMDGPU driver and KFD. Figure 3 shows the composition of the four layers and how a KFD allocation is mapped across multiple GPUs.

Figure 3 The four-layer BO structure and multi-GPU attachments
| Layer | Structure | Relationship to the lower layer | Main contents |
|---|---|---|---|
| DRM/GEM | drm_gem_object | Base object | Size, reference count, handle, mmap offset (vma_node), dma-buf export |
| TTM | ttm_buffer_object | Embeds drm_gem_object as member base | Current placement resource, system-memory backing ttm, migration and eviction |
| AMDGPU | amdgpu_bo | Embeds ttm_buffer_object as member tbo | Preferred and allowed domains, creation flags, VM association vm_bo, back pointer kfd_bo |
| KFD | kgd_mem | References amdgpu_bo through pointer bo | Unified GPU VA, allocation flags, per-GPU attachment list, validate_list and process_info for eviction and restore |
The lower three layers form an inheritance relationship through structure embedding. ttm_buffer_object embeds drm_gem_object, and amdgpu_bo embeds ttm_buffer_object. Because tbo is not the first member of amdgpu_bo, obtaining the AMDGPU object from the TTM object uses container_of, through the helper ttm_to_amdgpu_bo().
The KFD layer relates to the lower layers differently. kgd_mem does not embed amdgpu_bo; it references it through the bo pointer, and amdgpu_bo points back to kgd_mem through kfd_bo. This design separates two kinds of information: amdgpu_bo describes the buffer itself, including its storage location and memory attributes, while kgd_mem describes one allocation from the process’s point of view, including the virtual address used by the allocation, the GPUs it is mapped to, and its state during eviction and restore. An imported dma-buf is also wrapped in a kgd_mem; in that case is_imported is set and bo points to the amdgpu_bo created by the importer.
3.2 How Physical Storage Is Recorded
Two members of ttm_buffer_object record the physical storage of a BO. resource points to a ttm_resource, which describes the memory domain the BO currently resides in (VRAM, GTT or SYSTEM) and its location within that domain; for a VRAM BO, this location is the offset within VRAM. ttm points to a ttm_tt, which exists only when the BO is backed by system memory; its pages[] holds the system memory pages, and dma_address[] holds the DMA addresses through which devices access those pages.
3.3 BO Classification
AMDKFD_IOC_ALLOC_MEMORY_OF_GPU distinguishes BO types through allocation flags, and amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu() selects the memory domain and TTM object type accordingly.
| Allocation flag | Domain | Physical storage | Typical use |
|---|---|---|---|
VRAM | VRAM | Local VRAM | hipMalloc device memory |
GTT | GTT | System memory pages allocated by the kernel | Buffers shared between host and device |
USERPTR | GTT | Existing anonymous memory pages of the user process | Registering existing host memory |
DOORBELL, MMIO_REMAP | GTT (ttm_bo_type_sg) | Doorbell or register region in a device BAR | User-mode queue submission, register remapping |
A VRAM allocation may additionally carry flags such as PUBLIC (CPU access required) and CONTIGUOUS (physically contiguous). On APUs that prefer GTT, a VRAM-type allocation actually resides in system memory.
4 The Four Address Spaces
4.1 Definitions
The same BO corresponds to different addresses from the viewpoints of different initiators. This book groups these addresses into four kinds.
| Address space | User | Translation unit | Where it is recorded in code |
|---|---|---|---|
| CPU VA | Processes running on the CPU | CPU MMU (process page tables) | Process VMA; a BO is mapped into a VMA through the fake offset in drm_gem_object.vma_node |
| GPU VA | Kernels running on the GPU | GPU MMU (GPUVM multi-level page tables) | kgd_mem->va; amdgpu_bo_va_mapping under each GPU’s amdgpu_bo_va |
| DMA Address | Devices performing DMA | IOMMU (when present) | ttm_tt->dma_address[]; the sg_table of sg BOs and dma-bufs |
| Physical Address | The storage itself | None | For VRAM, the VRAM offset in ttm_resource; for system memory, the physical pages behind ttm_tt->pages[] |
CPU VA and GPU VA are both virtual addresses, translated by the CPU page tables and the GPUVM page tables respectively. A DMA Address is the bus address a device uses to access system memory: when the IOMMU is enabled it is an IOVA in the IOMMU address space, and otherwise it is usually identical to the physical address. A Physical Address is the actual location of the storage: for VRAM it is an offset in the GPU’s internal VRAM address space, and for system memory it is the CPU physical address.
4.2 Translation Paths
The memory domain of a BO determines its access path. Figure 4 shows the address translation paths when the CPU and the GPU access the two kinds of storage.

Figure 4 The four address spaces of a BO and their translation paths
In path ①, when the CPU accesses a VRAM BO, the CPU page table entry points to a physical address within the PCIe BAR, and the BAR window maps onto VRAM. The CPU can access only the VRAM range covered by the BAR window, and this limitation makes CPU accessibility of a VRAM BO an attribute that must be declared at allocation time.
In path ②, when the CPU accesses a GTT or Userptr BO, the CPU page table entry points directly to system memory pages, and no device-side address translation is involved.
In path ③, when the GPU accesses a VRAM BO on the same GPU, the GPUVM page table entry holds the VRAM address; the access stays within the GPU and does not pass through the IOMMU.
In path ④, when the GPU accesses a GTT or Userptr BO, the GPUVM page table entry holds a DMA address from ttm_tt->dma_address[]. The access request issued by the GPU reaches the IOMMU over PCIe, and the IOMMU translates it into a system memory physical address.
The four paths show that the address information of a BO is scattered across several sets of page tables: the CPU page tables, the GPUVM page tables of each GPU, and the IOMMU page tables. When a BO migrates, the related entries in all of these page tables must be updated consistently, and this is the main source of complexity in the eviction and restore mechanism.
5 BOs from a Multi-GPU Perspective
Beyond the four address spaces, a multi-GPU system introduces a further dimension: the same kgd_mem must be mapped onto several GPUs, and each GPU accesses the BO through a different path. In kfd_mem_attach(), the kernel creates one kfd_mem_attachment for each target GPU and selects the attachment type according to the BO type and the relationship between the owning device and the target device.
| Condition | Attachment type | BO used by the target GPU |
|---|---|---|
| The target GPU is the GPU that owns the BO | KFD_MEM_ATT_SHARED | Original BO |
| VRAM BO, target and owning GPUs in the same XGMI hive | KFD_MEM_ATT_SHARED | Original BO |
| GTT or Userptr BO, the two GPUs can reuse the same DMA mapping | KFD_MEM_ATT_SHARED | Original BO |
| Userptr BO, the target GPU requires its own DMA mapping | KFD_MEM_ATT_USERPTR | New sg BO with a DMA mapping for the target GPU |
| Doorbell or MMIO BO | KFD_MEM_ATT_SG | New sg BO mapping the device BAR region |
| Any other cross-device VRAM or GTT BO | KFD_MEM_ATT_DMABUF | BO imported on the target GPU through dma-buf |
Whether a DMA mapping can be reused is decided by reuse_dmamap(): both GPUs access system memory in direct-mapped mode, or both are in the same IOMMU group. For cross-device VRAM access, if the two GPUs are not in the same XGMI hive, the owning GPU’s VRAM must also be accessible to the peer over PCIe (a large BAR configuration); otherwise the mapping fails.
Each attachment corresponds to an amdgpu_bo_va in the target GPU’s amdgpu_vm and records the page table entry flags pte_flags specific to that GPU. During mapping, amdgpu_amdkfd_gpuvm_map_memory_to_gpu() walks the attachment list and, for each attachment not yet mapped, calls amdgpu_vm_bo_update() through update_gpuvm_pte() to write the page tables. As a result, the same kgd_mem uses the same GPU VA on every GPU, while the page table entries point respectively to a local VRAM address, a peer VRAM address within the same hive, or a DMA address accessed over PCIe.
6 Analysis Roadmap of the Book
The preceding sections outlined the complete process of a BO from allocation to mapping and the four address spaces involved. The book develops along two lines, the BO lifecycle and the address spaces, and the subject of each part is as follows.
| Part | Chapter | Subject | Address spaces involved |
|---|---|---|---|
| Part I BOs, Ownership and Physical Placement | Chapter 1 Multi-GPU Compute Scenario and BO Data Structures | Four-layer BO structure and classification | All |
| Chapter 2 KFD Process, Per-GPU VM and Memory Allocation Interfaces | Process context, per-GPU VM, allocation ioctl | GPU VA | |
| Chapter 3 Physical Placement of BOs | Domain selection, TTM placement and VRAM allocation | Physical Address | |
| Part II GPU-Side Addresses: Mapping and GPUVM Page Tables | Chapter 4 GPU-Side Mapping | Attachments, amdgpu_bo_va and the mapping flow | GPU VA |
| Chapter 5 GPUVM Multi-Level Page Tables | Page table structure, page table updates and TLB flushes | GPU VA to Physical Address or DMA Address | |
| Part III CPU-Side Access and System Memory Addressing | Chapter 6 CPU-Side Access: GEM mmap and Fake Offset | Fake offset, mmap and page fault handling | CPU VA |
| Chapter 7 System Memory Addressing: GART, DMA Addresses and IOMMU | Device addressing of system memory | DMA Address | |
| Part IV Runtime and Cross-Device | Chapter 8 Queue Consumption and Eviction/Restore | Eviction, migration and restore | All |
| Chapter 9 SVM: Unified Addressing Across CPU and GPUs | Shared virtual memory and on-demand migration | Unified CPU VA and GPU VA | |
| Chapter 10 Cross-Device Sharing: DMA-BUF and P2P | Cross-device sharing and peer access | DMA Address |
Part I analyzes the composition of BOs and the location of their physical storage; Parts II and III analyze BO addressing from the GPU side and the CPU side respectively; Part IV analyzes how BO placement changes at runtime and how BOs are shared across devices.