<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>In-Depth Analysis of AMD KFD Driver Design and Implementation on GPUers</title><link>https://en.gpuers.cn/columns/amd-kfd-bo/</link><description>Recent content in In-Depth Analysis of AMD KFD Driver Design and Implementation on GPUers</description><image><title>GPUers</title><url>https://en.gpuers.cn/img/og-cover-en.png</url><link>https://en.gpuers.cn/img/og-cover-en.png</link></image><generator>Hugo</generator><language>en-US</language><lastBuildDate>Thu, 26 Nov 2026 00:00:00 +0800</lastBuildDate><atom:link href="https://en.gpuers.cn/columns/amd-kfd-bo/index.xml" rel="self" type="application/rss+xml"/><item><title>The GEM and TTM Layers of amdgpu_bo</title><link>https://en.gpuers.cn/columns/amd-kfd-bo/0005-002/</link><pubDate>Thu, 26 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/amd-kfd-bo/0005-002/</guid><description>An AMDGPU BO is described jointly by four layers of structures.</description><content:encoded><![CDATA[<p>An AMDGPU BO is described jointly by four layers of structures. The lower two layers, <code>drm_gem_object</code> and <code>ttm_buffer_object</code>, are provided by the DRM core and by the TTM memory manager respectively, and are shared by every DRM driver built on TTM. The GEM layer gives a buffer its identity: reference count, user-space handles, mmap offset, synchronization object and export to other devices. The TTM layer manages the storage behind the buffer: where it is placed, which pages back it, and how it is moved, evicted and destroyed. This article analyzes how these two layers are embedded in <code>amdgpu_bo</code>, the members and callbacks through which each layer fulfills its responsibilities, the cooperation of the two reference counts during creation and release, and the use of both layers in the KFD allocation path.</p>
<h2 id="1-embedding-relationship">1 Embedding Relationship</h2>
<p><code>amdgpu_bo</code> embeds <code>ttm_buffer_object</code> as member <code>tbo</code>, and <code>ttm_buffer_object</code> embeds <code>drm_gem_object</code> as its first member <code>base</code>. Figure 1 shows the nesting of the three structures and the external objects referenced by each layer.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/amd-kfd-bo/0005-002/gem-ttm-embedding.en.png" width="2388" height="1388"
         alt="Figure 1 Embedding of the GEM and TTM layers in amdgpu_bo">
    <figcaption><p>Figure 1 Embedding of the GEM and TTM layers in amdgpu_bo</p></figcaption>
</figure>

<p>Structure embedding implements single inheritance in C. The three layers occupy one contiguous allocation made by a single <code>kvzalloc()</code> in <code>amdgpu_bo_create()</code>, and a pointer to any layer can be converted to the enclosing layer without an additional pointer member.</p>
<table>
	<thead>
			<tr>
					<th>From</th>
					<th>To</th>
					<th>Method</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>amdgpu_bo</code></td>
					<td><code>ttm_buffer_object</code></td>
					<td><code>&amp;bo-&gt;tbo</code></td>
			</tr>
			<tr>
					<td><code>amdgpu_bo</code></td>
					<td><code>drm_gem_object</code></td>
					<td><code>&amp;bo-&gt;tbo.base</code></td>
			</tr>
			<tr>
					<td><code>ttm_buffer_object</code></td>
					<td><code>amdgpu_bo</code></td>
					<td><code>ttm_to_amdgpu_bo()</code>, i.e. <code>container_of(tbo, struct amdgpu_bo, tbo)</code></td>
			</tr>
			<tr>
					<td><code>drm_gem_object</code></td>
					<td><code>amdgpu_bo</code></td>
					<td><code>gem_to_amdgpu_bo()</code>, i.e. <code>container_of(gobj, struct amdgpu_bo, tbo.base)</code></td>
			</tr>
	</tbody>
</table>
<p>Because <code>base</code> is the first member of <code>ttm_buffer_object</code>, a GEM pointer and the corresponding TTM pointer hold the same address. <code>tbo</code> is not the first member of <code>amdgpu_bo</code>, since <code>preferred_domains</code>, <code>allowed_domains</code> and the placement array precede it, so conversions to <code>amdgpu_bo</code> always use <code>container_of</code>. The allocation size is taken from <code>bp-&gt;bo_ptr_size</code>, which allows <code>amdgpu_bo</code> itself to be embedded in a larger structure such as <code>amdgpu_bo_user</code> or <code>amdgpu_bo_vm</code>. BOs created through <code>amdgpu_gem_object_create()</code>, including all KFD BOs, use the plain <code>amdgpu_bo</code>.</p>
<p>The direction of dependency follows the embedding. The GEM layer is unaware of TTM, and TTM is unaware of AMDGPU; each lower layer reaches the upper layers only through callback tables installed by the driver. <code>drm_gem_object.funcs</code> points to <code>amdgpu_gem_object_funcs</code>, and <code>ttm_buffer_object.bdev-&gt;funcs</code> points to <code>amdgpu_bo_driver</code>. These two tables are the points at which AMDGPU policy enters the generic frameworks.</p>
<h2 id="2-responsibilities-of-the-gem-layer">2 Responsibilities of the GEM Layer</h2>
<h3 id="21-identity-and-external-references">2.1 Identity and External References</h3>
<p><code>drm_gem_object</code> records the size of the buffer in <code>size</code> and holds the reference count <code>refcount</code>. Every long-lived holder of the BO owns one GEM reference: each user-space handle in a <code>drm_file</code> (counted additionally in <code>handle_count</code>), each dma-buf exported from the BO, and each kernel user that takes a reference through <code>amdgpu_bo_ref()</code>. <code>amdgpu_bo_ref()</code> and <code>amdgpu_bo_unref()</code> are implemented as <code>drm_gem_object_get()</code> and <code>drm_gem_object_put()</code> on <code>tbo.base</code>, so the AMDGPU driver uses the GEM count as the external lifetime of a BO.</p>
<p>The remaining identity members serve sharing. <code>name</code> is the global name created by the legacy flink interface. <code>dma_buf</code> caches the dma-buf exported from this object, and <code>import_attach</code> records the attachment when the object was imported from another device.</p>
<h3 id="22-mmap-offset">2.2 mmap Offset</h3>
<p>User space maps a BO into the CPU address space by calling <code>mmap</code> on a DRM device file with a fake offset that identifies the BO. <code>vma_node</code> is the node of the BO in the device&rsquo;s <code>drm_vma_offset_manager</code>, and the offset range it occupies is allocated by <code>ttm_bo_init_reserved()</code> for BOs of type <code>ttm_bo_type_device</code> and <code>ttm_bo_type_sg</code>. <code>amdgpu_bo_mmap_offset()</code> returns this offset through <code>drm_vma_node_offset_addr()</code>.</p>
<p>The offset alone does not grant access. <code>vma_node</code> also maintains a list of <code>drm_file</code> instances that are allowed to map the BO, and <code>drm_vma_node_allow()</code> adds a file to this list. An <code>mmap</code> call through a file that is not on the list is rejected. When the mapping is established, <code>amdgpu_gem_object_mmap()</code> refuses Userptr BOs and BOs created with <code>AMDGPU_GEM_CREATE_NO_CPU_ACCESS</code>, and then hands the VMA to <code>drm_gem_ttm_mmap()</code>. Page faults on the VMA are handled by <code>amdgpu_gem_fault()</code> in <code>amdgpu_gem_vm_ops</code>, which fills the CPU page tables according to the current TTM placement of the BO.</p>
<h3 id="23-reservation-object">2.3 Reservation Object</h3>
<p><code>resv</code> points to a <code>dma_resv</code>. By default it points to <code>_resv</code> embedded in the same object; a caller can instead pass a shared <code>dma_resv</code> at creation time so that a group of BOs uses one lock and one fence set. The reservation object has two roles. It is a fence container: every GPU operation that reads or writes the BO adds its fence with a usage class, and waiters use these fences to determine when the BO is idle. It is also the lock that TTM calls the reservation: the members <code>resource</code>, <code>ttm</code>, <code>pin_count</code> and the LRU state of <code>ttm_buffer_object</code> are protected by holding <code>resv</code>. The GEM layer defines the object, and the TTM layer defines the locking rules built upon it.</p>
<h3 id="24-gem-callback-table">2.4 GEM Callback Table</h3>
<p><code>amdgpu_bo_create()</code> sets <code>tbo.base.funcs</code> to <code>amdgpu_gem_object_funcs</code>. The table connects generic GEM operations to AMDGPU implementations.</p>
<table>
	<thead>
			<tr>
					<th>Callback</th>
					<th>AMDGPU implementation</th>
					<th>Function</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>free</code></td>
					<td><code>amdgpu_gem_object_free()</code></td>
					<td>Invoked when the GEM count reaches zero; drops the TTM reference</td>
			</tr>
			<tr>
					<td><code>open</code> / <code>close</code></td>
					<td><code>amdgpu_gem_object_open()</code> / <code>amdgpu_gem_object_close()</code></td>
					<td>Create or remove the <code>amdgpu_bo_va</code> of the BO in the VM of a render node file when a handle is opened or closed</td>
			</tr>
			<tr>
					<td><code>export</code></td>
					<td><code>amdgpu_gem_prime_export()</code></td>
					<td>Export the BO as a dma-buf</td>
			</tr>
			<tr>
					<td><code>vmap</code> / <code>vunmap</code></td>
					<td><code>drm_gem_ttm_vmap()</code> / <code>drm_gem_ttm_vunmap()</code></td>
					<td>Kernel virtual mapping through TTM</td>
			</tr>
			<tr>
					<td><code>mmap</code></td>
					<td><code>amdgpu_gem_object_mmap()</code></td>
					<td>Validate and establish a user-space mapping</td>
			</tr>
			<tr>
					<td><code>vm_ops</code></td>
					<td><code>amdgpu_gem_vm_ops</code></td>
					<td>Page fault, VMA open, close and access handlers</td>
			</tr>
	</tbody>
</table>
<h2 id="3-responsibilities-of-the-ttm-layer">3 Responsibilities of the TTM Layer</h2>
<h3 id="31-device-and-object-type">3.1 Device and Object Type</h3>
<p><code>bdev</code> points to the TTM device <code>adev-&gt;mman.bdev</code> of the GPU, which holds the resource managers of all memory types and the driver callback table. <code>type</code> takes one of three values, set at creation and constant afterwards.</p>
<table>
	<thead>
			<tr>
					<th>Type</th>
					<th>mmap offset</th>
					<th>Meaning</th>
					<th>KFD usage</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>ttm_bo_type_device</code></td>
					<td>Yes</td>
					<td>Ordinary buffer that user space may map</td>
					<td>VRAM, GTT and Userptr BOs</td>
			</tr>
			<tr>
					<td><code>ttm_bo_type_kernel</code></td>
					<td>No</td>
					<td>Buffer used only inside the kernel</td>
					<td>Not used for KFD user allocations</td>
			</tr>
			<tr>
					<td><code>ttm_bo_type_sg</code></td>
					<td>Yes</td>
					<td>Buffer whose pages come from an external <code>sg_table</code></td>
					<td>Doorbell and MMIO BOs</td>
			</tr>
	</tbody>
</table>
<p><code>page_alignment</code> is the required alignment of the placement, and <code>destroy</code> is the function that frees the enclosing structure once TTM has released the storage. For AMDGPU it is <code>amdgpu_bo_destroy()</code> or a variant for derived types.</p>
<h3 id="32-placement-resource">3.2 Placement: <code>resource</code></h3>
<p><code>resource</code> points to a <code>ttm_resource</code> that describes the current placement. <code>mem_type</code> identifies the memory type, <code>start</code> is the position within that memory type in pages, <code>size</code> is the size in bytes, and <code>bus</code> describes how the CPU reaches the placement through an I/O aperture such as the VRAM BAR. AMDGPU memory domains map to TTM memory types in <code>amdgpu_bo_placement_from_domain()</code>.</p>
<table>
	<thead>
			<tr>
					<th>AMDGPU domain</th>
					<th>TTM memory type</th>
					<th>Physical storage</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>AMDGPU_GEM_DOMAIN_VRAM</code></td>
					<td><code>TTM_PL_VRAM</code></td>
					<td>Local VRAM</td>
			</tr>
			<tr>
					<td><code>AMDGPU_GEM_DOMAIN_GTT</code></td>
					<td><code>TTM_PL_TT</code>, or <code>AMDGPU_PL_PREEMPT</code> for BOs created with <code>AMDGPU_GEM_CREATE_PREEMPTIBLE</code></td>
					<td>System memory accessible to the GPU</td>
			</tr>
			<tr>
					<td><code>AMDGPU_GEM_DOMAIN_CPU</code></td>
					<td><code>TTM_PL_SYSTEM</code></td>
					<td>System memory not mapped for the GPU</td>
			</tr>
			<tr>
					<td><code>AMDGPU_GEM_DOMAIN_DOORBELL</code></td>
					<td><code>AMDGPU_PL_DOORBELL</code></td>
					<td>Doorbell aperture</td>
			</tr>
	</tbody>
</table>
<p><code>amdgpu_bo_placement_from_domain()</code> fills <code>amdgpu_bo.placements[]</code> with one <code>ttm_place</code> per allowed memory type, and <code>ttm_bo_validate()</code> uses this list to select a memory type and obtain a <code>ttm_resource</code> from its resource manager, evicting other BOs when the preferred memory type is full. The KFD allocation path creates Userptr, Doorbell and MMIO BOs with <code>AMDGPU_GEM_CREATE_PREEMPTIBLE</code>, so these BOs reside in <code>AMDGPU_PL_PREEMPT</code> rather than <code>TTM_PL_TT</code> when they are placed in GTT.</p>
<h3 id="33-system-memory-backing-ttm-and-sg">3.3 System Memory Backing: <code>ttm</code> and <code>sg</code></h3>
<p><code>ttm</code> points to a <code>ttm_tt</code> that records the system memory pages backing the BO. <code>pages[]</code> holds the <code>struct page</code> pointers, <code>dma_address[]</code> holds the DMA address of each page as seen by the GPU, and <code>sg</code> holds an external <code>sg_table</code> when the pages are not owned by TTM. AMDGPU creates the object through the <code>ttm_tt_create</code> callback as <code>amdgpu_ttm_tt</code>, which embeds <code>ttm_tt</code> and adds the Userptr fields <code>userptr</code> and <code>usertask</code> together with GART binding state. A BO placed in VRAM does not use <code>ttm_tt</code> to hold its storage.</p>
<p><code>ttm_buffer_object.sg</code> holds the external <code>sg_table</code> of <code>ttm_bo_type_sg</code> BOs. For KFD Doorbell and MMIO BOs, the table describes a region in a device BAR and is assigned to both <code>tbo.sg</code> and <code>tbo.ttm-&gt;sg</code> after creation.</p>
<h3 id="34-runtime-state">3.4 Runtime State</h3>
<p><code>pin_count</code> prevents eviction and migration while it is non-zero. <code>priority</code> and <code>bulk_move</code> determine the position of the BO on the LRU lists that TTM scans when it searches for eviction candidates. <code>deleted</code> and <code>delayed_delete</code> support deferred destruction, described in section 4. <code>kref</code> is the reference count of the TTM layer.</p>
<h3 id="35-ttm-driver-callbacks">3.5 TTM Driver Callbacks</h3>
<p>The TTM device of AMDGPU is initialized with <code>amdgpu_bo_driver</code>, whose callbacks implement the memory operations that the generic layer cannot perform alone.</p>
<table>
	<thead>
			<tr>
					<th>Callback</th>
					<th>AMDGPU implementation</th>
					<th>Function</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>ttm_tt_create</code> / <code>ttm_tt_populate</code> / <code>ttm_tt_unpopulate</code> / <code>ttm_tt_destroy</code></td>
					<td><code>amdgpu_ttm_tt_*</code>, <code>amdgpu_ttm_backend_destroy()</code></td>
					<td>Create the <code>amdgpu_ttm_tt</code>, allocate or obtain its pages, and release them</td>
			</tr>
			<tr>
					<td><code>eviction_valuable</code> / <code>evict_flags</code></td>
					<td><code>amdgpu_ttm_bo_eviction_valuable()</code> / <code>amdgpu_evict_flags()</code></td>
					<td>Decide whether a BO may be evicted and where it should go</td>
			</tr>
			<tr>
					<td><code>move</code></td>
					<td><code>amdgpu_bo_move()</code></td>
					<td>Move a BO between memory types, using the SDMA engine for copies</td>
			</tr>
			<tr>
					<td><code>delete_mem_notify</code> / <code>release_notify</code></td>
					<td><code>amdgpu_bo_delete_mem_notify()</code> / <code>amdgpu_bo_release_notify()</code></td>
					<td>Notify the driver before storage is freed and when a BO is released</td>
			</tr>
			<tr>
					<td><code>io_mem_reserve</code> / <code>io_mem_pfn</code></td>
					<td><code>amdgpu_ttm_io_mem_reserve()</code> / <code>amdgpu_ttm_io_mem_pfn()</code></td>
					<td>Provide the bus address and page frame numbers for CPU access to VRAM and doorbells</td>
			</tr>
			<tr>
					<td><code>access_memory</code></td>
					<td><code>amdgpu_ttm_access_memory()</code></td>
					<td>Access BO contents for debuggers</td>
			</tr>
	</tbody>
</table>
<h2 id="4-two-reference-counts-and-the-bo-lifetime">4 Two Reference Counts and the BO Lifetime</h2>
<p>The GEM layer and the TTM layer each hold a reference count: <code>drm_gem_object.refcount</code> and <code>ttm_buffer_object.kref</code>. Figure 2 shows how the two counts are initialized during creation and consumed during release.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/amd-kfd-bo/0005-002/bo-lifetime.en.png" width="2428" height="1384"
         alt="Figure 2 Creation and release of amdgpu_bo across the GEM and TTM layers">
    <figcaption><p>Figure 2 Creation and release of amdgpu_bo across the GEM and TTM layers</p></figcaption>
</figure>

<p>During creation, <code>amdgpu_bo_create()</code> allocates the structure and calls <code>drm_gem_private_object_init()</code>, which sets the GEM count to one, initializes <code>_resv</code> and resets <code>vma_node</code>. After installing the GEM callback table and computing the placement from the requested domain, it calls <code>ttm_bo_init_reserved()</code>. This function sets the TTM count to one, records <code>bdev</code>, <code>type</code> and <code>destroy</code>, selects the external or embedded reservation object, allocates the mmap offset for device and sg BOs, locks the reservation object and calls <code>ttm_bo_validate()</code> to allocate the initial <code>ttm_resource</code>. <code>amdgpu_bo_create()</code> then performs AMDGPU-specific initialization such as VRAM clearing and unlocks the reservation object.</p>
<p>The two counts have different holders. The GEM count is held by external users: handles, dma-bufs and driver code. The TTM count is held by TTM itself. TTM functions that operate on BOs found on LRU lists, such as eviction and swapout, take a temporary reference with <code>ttm_bo_get_unless_zero()</code>, which fails for an object whose count has already reached zero; the plain <code>ttm_bo_get()</code> is internal to TTM. In normal operation the TTM count stays at one, and the release of the last GEM reference drives the release of the TTM reference.</p>
<p>During release, <code>drm_gem_object_put()</code> drops a GEM reference. When the count reaches zero, the GEM core calls <code>amdgpu_gem_object_free()</code>, which unregisters the HMM notifier of Userptr BOs and calls <code>ttm_bo_fini()</code>, dropping the TTM reference through <code>ttm_bo_put()</code>. When the TTM count reaches zero, <code>ttm_bo_release()</code> calls the driver&rsquo;s <code>release_notify</code> callback, removes the mmap offset and examines the fences in the reservation object. For KFD BOs, <code>amdgpu_bo_release_notify()</code> removes the eviction fences of the process and, for VRAM allocated with <code>AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE</code>, clears the VRAM before it is returned.</p>
<p>If all fences have signaled, <code>ttm_bo_release()</code> frees the <code>ttm_tt</code> and the <code>ttm_resource</code> through <code>ttm_bo_cleanup_memtype_use()</code> and then calls <code>bo-&gt;destroy</code>. If the GPU is still using the BO, the release cannot complete immediately. TTM then sets <code>deleted</code>, reinitializes <code>kref</code> to one and queues <code>delayed_delete</code> on a work queue; the worker waits for the fences and completes the same cleanup. The BO therefore outlives its last external reference for as long as the hardware needs it, and this deferral is invisible to the GEM layer, whose count has already reached zero. Finally, <code>amdgpu_bo_destroy()</code> calls <code>drm_gem_object_release()</code> to release the GEM-side resources, including the embedded <code>_resv</code>, and frees the memory with <code>kvfree()</code>.</p>
<h2 id="5-the-gem-and-ttm-layers-in-the-kfd-allocation-path">5 The GEM and TTM Layers in the KFD Allocation Path</h2>
<p><code>amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()</code> creates the BO for a KFD allocation and connects it to <code>kgd_mem</code>. The steps that act on the GEM and TTM layers are listed below.</p>
<table>
	<thead>
			<tr>
					<th>Step</th>
					<th>Call</th>
					<th>Layer</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Create the BO</td>
					<td><code>amdgpu_gem_object_create(adev, size, 1, alloc_domain, alloc_flags, bo_type, NULL, &amp;gobj, xcp_id + 1)</code></td>
					<td>GEM and TTM</td>
			</tr>
			<tr>
					<td>Authorize CPU mapping</td>
					<td><code>drm_vma_node_allow(&amp;gobj-&gt;vma_node, drm_priv)</code></td>
					<td>GEM</td>
			</tr>
			<tr>
					<td>Create a GEM handle</td>
					<td><code>drm_gem_handle_create(adev-&gt;kfd.client.file, gobj, &amp;mem-&gt;gem_handle)</code></td>
					<td>GEM</td>
			</tr>
			<tr>
					<td>Attach the external sg table</td>
					<td><code>bo-&gt;tbo.sg = sg; bo-&gt;tbo.ttm-&gt;sg = sg</code> (Doorbell and MMIO only)</td>
					<td>TTM</td>
			</tr>
			<tr>
					<td>Link to <code>kgd_mem</code></td>
					<td><code>bo-&gt;kfd_bo = mem; mem-&gt;bo = bo</code></td>
					<td>AMDGPU and KFD</td>
			</tr>
			<tr>
					<td>Return the mmap offset</td>
					<td><code>amdgpu_bo_mmap_offset(bo)</code></td>
					<td>GEM</td>
			</tr>
	</tbody>
</table>
<p><code>bo_type</code> is <code>ttm_bo_type_device</code> except for Doorbell and MMIO BOs, which use <code>ttm_bo_type_sg</code>. The reservation argument is <code>NULL</code>, so every KFD BO uses its own embedded <code>_resv</code>. <code>drm_priv</code> is the render node file associated with the process by <code>AMDKFD_IOC_ACQUIRE_VM</code>, so the returned mmap offset is valid only for <code>mmap</code> on that render node.</p>
<p>The GEM handle is not created in a user-space file. amdgpu registers an in-kernel DRM client named <code>kfd</code> for each device, and KFD creates the handle in the file of this client. The handle keeps a GEM reference for the lifetime of the allocation and is the input of <code>drm_gem_prime_handle_to_dmabuf()</code> when KFD exports the BO as a dma-buf, for example to establish a <code>KFD_MEM_ATT_DMABUF</code> attachment on another GPU. <code>amdgpu_amdkfd_gpuvm_free_memory_of_gpu()</code> deletes the handle with <code>drm_gem_handle_delete()</code>, and the release of this reference starts the release sequence of section 4 once no other holder remains.</p>
<p>The GEM and TTM layers thus provide the generic object model and memory management of a BO: identity, sharing, synchronization, placement, backing pages and deferred destruction. The AMDGPU-specific policy, including the preferred and allowed domains, the creation flags, the association with GPU virtual memory and the link to <code>kgd_mem</code>, resides in the members of <code>amdgpu_bo</code> outside <code>tbo</code>.</p>
]]></content:encoded></item><item><title>AMDGPU BO Design Overview</title><link>https://en.gpuers.cn/columns/amd-kfd-bo/0005-001/</link><pubDate>Wed, 25 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/amd-kfd-bo/0005-001/</guid><description>In the ROCm compute stack, every piece of device memory allocated by an application corresponds to a buffer object (BO) in the kernel.</description><content:encoded><![CDATA[<p>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.</p>
<h2 id="1-multi-gpu-compute-scenario">1 Multi-GPU Compute Scenario</h2>
<h3 id="11-example-program">1.1 Example Program</h3>
<p>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.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="line"><span class="cl"><span class="kt">float</span> <span class="o">*</span><span class="n">a0</span><span class="p">,</span> <span class="o">*</span><span class="n">a1</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="n">hipSetDevice</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span> <span class="n">hipMalloc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">a0</span><span class="p">,</span> <span class="n">size</span><span class="p">);</span>            <span class="cm">/* VRAM of GPU 0 */</span>
</span></span><span class="line"><span class="cl"><span class="n">hipSetDevice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="n">hipMalloc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">a1</span><span class="p">,</span> <span class="n">size</span><span class="p">);</span>            <span class="cm">/* VRAM of GPU 1 */</span>
</span></span><span class="line"><span class="cl"><span class="n">hipSetDevice</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span> <span class="n">hipDeviceEnablePeerAccess</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span> <span class="cm">/* GPU 0 accesses GPU 1 VRAM */</span>
</span></span><span class="line"><span class="cl"><span class="n">hipLaunchKernelGGL</span><span class="p">(</span><span class="n">kern</span><span class="p">,</span> <span class="n">grid</span><span class="p">,</span> <span class="n">block</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">a0</span><span class="p">,</span> <span class="n">a1</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">hipMemcpy</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">a0</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">hipMemcpyDeviceToHost</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">hipFree</span><span class="p">(</span><span class="n">a1</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="n">hipFree</span><span class="p">(</span><span class="n">a0</span><span class="p">);</span>
</span></span></code></pre></div><p>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 <code>/dev/kfd</code> through libhsakmt.</p>
<h3 id="12-execution-stages-and-kfd-interfaces">1.2 Execution Stages and KFD Interfaces</h3>
<p>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.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/amd-kfd-bo/0005-001/kfd-multigpu-flow.en.png" width="2435" height="1465"
         alt="Figure 1 Execution stages of a multi-GPU compute program and the KFD interfaces">
    <figcaption><p>Figure 1 Execution stages of a multi-GPU compute program and the KFD interfaces</p></figcaption>
</figure>

<p>The key points of each stage are as follows:</p>
<ol>
<li>Device discovery. The runtime opens <code>/dev/kfd</code>, and the kernel creates a <code>kfd_process</code> for the calling process. The runtime then reads the topology nodes under <code>/sys/class/kfd/kfd/topology</code> to obtain the list of GPUs in the system, the VRAM capacity of each GPU, and the XGMI links between GPUs.</li>
<li>Process and per-GPU VM. The runtime opens the render node (<code>/dev/dri/renderD*</code>) of each GPU and calls <code>AMDKFD_IOC_ACQUIRE_VM</code> with its file descriptor. The kernel creates a <code>kfd_process_device</code> for the process on that GPU and converts the <code>amdgpu_vm</code> belonging to the render node file into a compute VM. On a dual-GPU system, the same process therefore owns two independent GPU address spaces.</li>
<li>Allocation. The allocation step of <code>hipMalloc</code> calls <code>AMDKFD_IOC_ALLOC_MEMORY_OF_GPU</code>. The kernel selects a memory domain according to the allocation flags, creates an <code>amdgpu_bo</code>, and records the allocation in a <code>kgd_mem</code>. The GPU virtual address is chosen by the user-space runtime before the call and passed to the kernel as an argument.</li>
<li>GPU-side mapping. The arguments of <code>AMDKFD_IOC_MAP_MEMORY_TO_GPU</code> carry a list of target GPUs. For each GPU in the list, the kernel creates a <code>kfd_mem_attachment</code>, adds an <code>amdgpu_bo_va</code> to that GPU&rsquo;s <code>amdgpu_vm</code>, and updates the GPUVM page tables. <code>hipDeviceEnablePeerAccess</code> adds mappings of existing allocations on the peer GPU through the same interface.</li>
<li>CPU-side access. The allocation interface returns an mmap offset. The runtime calls <code>mmap</code> on 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 through <code>mmap</code> on <code>/dev/kfd</code>.</li>
<li>Queue execution. <code>AMDKFD_IOC_CREATE_QUEUE</code> creates 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.</li>
<li>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 <code>amdgpu_amdkfd_fence</code> and the restore work queue, and is transparent to the application.</li>
<li>Release. <code>hipFree</code> calls <code>AMDKFD_IOC_UNMAP_MEMORY_FROM_GPU</code> and then <code>AMDKFD_IOC_FREE_MEMORY_OF_GPU</code>. The kernel removes the page table mappings on each GPU and frees the attachments, the BO and its backing storage.</li>
</ol>
<p>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.</p>
<h2 id="2-kfd-driver-overview">2 KFD Driver Overview</h2>
<h3 id="21-layered-structure">2.1 Layered Structure</h3>
<p>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.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/amd-kfd-bo/0005-001/kfd-driver-layers.en.png" width="2468" height="1468"
         alt="Figure 2 Layered overview of the KFD driver">
    <figcaption><p>Figure 2 Layered overview of the KFD driver</p></figcaption>
</figure>

<p>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.</p>
<p>In the kernel, compute functionality is split between two drivers. amdkfd is the compute driver, responsible for process management (<code>kfd_process</code>, <code>kfd_process_device</code>), 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 <code>amdgpu_amdkfd_*</code> family of functions. The memory-related interfaces are concentrated in <code>amdgpu_amdkfd_gpuvm.c</code> with the prefix <code>amdgpu_amdkfd_gpuvm_</code>, for example <code>amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu()</code> and <code>amdgpu_amdkfd_gpuvm_map_memory_to_gpu()</code>. With this division, amdkfd does not manipulate page tables or BOs directly; it delegates the work to amdgpu using <code>kgd_mem</code> as the handle.</p>
<p>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&rsquo;s VRAM over XGMI or PCIe P2P, while GPU access to system memory goes through PCIe and the IOMMU.</p>
<h3 id="22-two-kinds-of-device-nodes">2.2 Two Kinds of Device Nodes</h3>
<p>A KFD process uses two kinds of device nodes at the same time. <code>/dev/kfd</code> 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 <code>amdgpu_vm</code> private to the file.</p>
<p><code>AMDKFD_IOC_ACQUIRE_VM</code> links the two kinds of nodes. In <code>kfd_ioctl_acquire_vm()</code>, the kernel obtains the render node&rsquo;s <code>drm_file</code> from the file descriptor passed by user space, stores it as <code>drm_priv</code> in the <code>kfd_process_device</code>, and calls <code>amdgpu_amdkfd_gpuvm_acquire_process_vm()</code> to convert the contained <code>amdgpu_vm</code> into a compute VM. From then on, KFD obtains the VM on that GPU through <code>drm_priv_to_vm(pdd-&gt;drm_priv)</code>, and CPU mappings of BOs are also established through the same render node.</p>
<h3 id="23-multi-gpu-organization">2.3 Multi-GPU Organization</h3>
<p><code>kfd_process</code> stores the process&rsquo;s <code>kfd_process_device</code> instances for all GPUs in the array <code>pdds[MAX_GPU_INSTANCE]</code>, and <code>n_pdds</code> records the number of valid entries. Each <code>kfd_process_device</code> corresponds to one GPU and one <code>amdgpu_vm</code>, so a process on N GPUs owns N independent sets of GPUVM page tables.</p>
<p>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, <code>kgd_mem</code> stores a single <code>va</code> field in the kernel, and this address is used when mapping onto every GPU; the difference appears only in the contents of each GPU&rsquo;s page table entries.</p>
<h2 id="3-the-four-layer-bo-structure">3 The Four-Layer BO Structure</h2>
<h3 id="31-composition">3.1 Composition</h3>
<p>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.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/amd-kfd-bo/0005-001/bo-structure.en.png" width="2388" height="1248"
         alt="Figure 3 The four-layer BO structure and multi-GPU attachments">
    <figcaption><p>Figure 3 The four-layer BO structure and multi-GPU attachments</p></figcaption>
</figure>

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

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/amd-kfd-bo/0005-001/bo-address-spaces.en.png" width="2428" height="1392"
         alt="Figure 4 The four address spaces of a BO and their translation paths">
    <figcaption><p>Figure 4 The four address spaces of a BO and their translation paths</p></figcaption>
</figure>

<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>In path ④, when the GPU accesses a GTT or Userptr BO, the GPUVM page table entry holds a DMA address from <code>ttm_tt-&gt;dma_address[]</code>. The access request issued by the GPU reaches the IOMMU over PCIe, and the IOMMU translates it into a system memory physical address.</p>
<p>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.</p>
<h2 id="5-bos-from-a-multi-gpu-perspective">5 BOs from a Multi-GPU Perspective</h2>
<p>Beyond the four address spaces, a multi-GPU system introduces a further dimension: the same <code>kgd_mem</code> must be mapped onto several GPUs, and each GPU accesses the BO through a different path. In <code>kfd_mem_attach()</code>, the kernel creates one <code>kfd_mem_attachment</code> 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.</p>
<table>
	<thead>
			<tr>
					<th>Condition</th>
					<th>Attachment type</th>
					<th>BO used by the target GPU</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>The target GPU is the GPU that owns the BO</td>
					<td><code>KFD_MEM_ATT_SHARED</code></td>
					<td>Original BO</td>
			</tr>
			<tr>
					<td>VRAM BO, target and owning GPUs in the same XGMI hive</td>
					<td><code>KFD_MEM_ATT_SHARED</code></td>
					<td>Original BO</td>
			</tr>
			<tr>
					<td>GTT or Userptr BO, the two GPUs can reuse the same DMA mapping</td>
					<td><code>KFD_MEM_ATT_SHARED</code></td>
					<td>Original BO</td>
			</tr>
			<tr>
					<td>Userptr BO, the target GPU requires its own DMA mapping</td>
					<td><code>KFD_MEM_ATT_USERPTR</code></td>
					<td>New sg BO with a DMA mapping for the target GPU</td>
			</tr>
			<tr>
					<td>Doorbell or MMIO BO</td>
					<td><code>KFD_MEM_ATT_SG</code></td>
					<td>New sg BO mapping the device BAR region</td>
			</tr>
			<tr>
					<td>Any other cross-device VRAM or GTT BO</td>
					<td><code>KFD_MEM_ATT_DMABUF</code></td>
					<td>BO imported on the target GPU through dma-buf</td>
			</tr>
	</tbody>
</table>
<p>Whether a DMA mapping can be reused is decided by <code>reuse_dmamap()</code>: 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&rsquo;s VRAM must also be accessible to the peer over PCIe (a large BAR configuration); otherwise the mapping fails.</p>
<p>Each attachment corresponds to an <code>amdgpu_bo_va</code> in the target GPU&rsquo;s <code>amdgpu_vm</code> and records the page table entry flags <code>pte_flags</code> specific to that GPU. During mapping, <code>amdgpu_amdkfd_gpuvm_map_memory_to_gpu()</code> walks the attachment list and, for each attachment not yet mapped, calls <code>amdgpu_vm_bo_update()</code> through <code>update_gpuvm_pte()</code> to write the page tables. As a result, the same <code>kgd_mem</code> 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.</p>
<h2 id="6-analysis-roadmap-of-the-book">6 Analysis Roadmap of the Book</h2>
<p>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.</p>
<table>
	<thead>
			<tr>
					<th>Part</th>
					<th>Chapter</th>
					<th>Subject</th>
					<th>Address spaces involved</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Part I BOs, Ownership and Physical Placement</td>
					<td>Chapter 1 Multi-GPU Compute Scenario and BO Data Structures</td>
					<td>Four-layer BO structure and classification</td>
					<td>All</td>
			</tr>
			<tr>
					<td></td>
					<td>Chapter 2 KFD Process, Per-GPU VM and Memory Allocation Interfaces</td>
					<td>Process context, per-GPU VM, allocation ioctl</td>
					<td>GPU VA</td>
			</tr>
			<tr>
					<td></td>
					<td>Chapter 3 Physical Placement of BOs</td>
					<td>Domain selection, TTM placement and VRAM allocation</td>
					<td>Physical Address</td>
			</tr>
			<tr>
					<td>Part II GPU-Side Addresses: Mapping and GPUVM Page Tables</td>
					<td>Chapter 4 GPU-Side Mapping</td>
					<td>Attachments, <code>amdgpu_bo_va</code> and the mapping flow</td>
					<td>GPU VA</td>
			</tr>
			<tr>
					<td></td>
					<td>Chapter 5 GPUVM Multi-Level Page Tables</td>
					<td>Page table structure, page table updates and TLB flushes</td>
					<td>GPU VA to Physical Address or DMA Address</td>
			</tr>
			<tr>
					<td>Part III CPU-Side Access and System Memory Addressing</td>
					<td>Chapter 6 CPU-Side Access: GEM mmap and Fake Offset</td>
					<td>Fake offset, mmap and page fault handling</td>
					<td>CPU VA</td>
			</tr>
			<tr>
					<td></td>
					<td>Chapter 7 System Memory Addressing: GART, DMA Addresses and IOMMU</td>
					<td>Device addressing of system memory</td>
					<td>DMA Address</td>
			</tr>
			<tr>
					<td>Part IV Runtime and Cross-Device</td>
					<td>Chapter 8 Queue Consumption and Eviction/Restore</td>
					<td>Eviction, migration and restore</td>
					<td>All</td>
			</tr>
			<tr>
					<td></td>
					<td>Chapter 9 SVM: Unified Addressing Across CPU and GPUs</td>
					<td>Shared virtual memory and on-demand migration</td>
					<td>Unified CPU VA and GPU VA</td>
			</tr>
			<tr>
					<td></td>
					<td>Chapter 10 Cross-Device Sharing: DMA-BUF and P2P</td>
					<td>Cross-device sharing and peer access</td>
					<td>DMA Address</td>
			</tr>
	</tbody>
</table>
<p>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.</p>
]]></content:encoded></item></channel></rss>