[PATCH] tests/amdgpu: Add test for GPUVM, LDS, and Scratch Aperture Sizes

Srinivasan Shanmugam srinivasan.shanmugam at amd.com
Mon Jul 7 07:09:23 UTC 2025


This patch adds a new IGT subtest "amdgpu-vm-aperture-sizes-test" that
queries the AMDGPU_INFO_DEV_INFO ioctl to validate GPU virtual memory
(GPUVM) aperture sizes, including LDS and scratch base and limit
addresses.

The test prints the LDS and scratch aperture sizes in bytes, gigabytes,
and terabytes, and asserts that the sizes match expected values (e.g.,
4GB).

It also prints and validates the GPUVM virtual address ranges, including
low and high virtual address ranges, and calculates the total GPUVM
size.

Cc: Vitaly Prosyak <vitaly.prosyak at amd.com>
Cc: David Yat Sin <David.YatSin at amd.com>
Cc: Christian König <christian.koenig at amd.com>
Cc: Alex Deucher <alexander.deucher at amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>
---
 tests/amdgpu/amd_vm.c | 90 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tests/amdgpu/amd_vm.c b/tests/amdgpu/amd_vm.c
index 9cd56e2b5..1c5212463 100644
--- a/tests/amdgpu/amd_vm.c
+++ b/tests/amdgpu/amd_vm.c
@@ -13,6 +13,9 @@
 #include "lib/amdgpu/amd_cp_dma.h"
 #include "lib/amdgpu/amd_memory.h"
 
+#define BYTES_IN_GB (1024ULL * 1024ULL * 1024ULL)
+#define BYTES_IN_TB (1024ULL * BYTES_IN_GB)
+
 static bool
 is_vm_tests_enable(uint32_t family_id)
 {
@@ -197,6 +200,88 @@ amdgpu_vm_mapping_test(amdgpu_device_handle device_handle)
 	amdgpu_bo_free(buf);
 }
 
+static void
+amdgpu_vm_aperture_sizes_test(amdgpu_device_handle device_handle)
+{
+	struct drm_amdgpu_info_device dev_info = {0};
+	int r;
+	u64 lds_size, scratch_size;
+	u64 low_range, high_range, total_gpuvm_size;
+
+	r = amdgpu_query_info(device_handle, AMDGPU_INFO_DEV_INFO,
+			      sizeof(dev_info), &dev_info);
+	igt_assert_eq(r, 0);
+
+	lds_size = dev_info.lds_limit - dev_info.lds_base + 1;
+
+	igt_info("LDS Base: 0x%llx\n", (unsigned long long)dev_info.lds_base);
+	igt_info("LDS Limit: 0x%llx\n", (unsigned long long)dev_info.lds_limit);
+	igt_info("LDS aperture size: %llu bytes\n", (unsigned long long)lds_size);
+	igt_info("LDS aperture size: %llu bytes, approx. %llu GB, approx. %llu TB\n",
+		 (unsigned long long)lds_size,
+		 (unsigned long long)(lds_size / BYTES_IN_GB),
+		 (unsigned long long)(lds_size / BYTES_IN_TB));
+
+	scratch_size = dev_info.scratch_limit - dev_info.scratch_base + 1;
+
+	igt_info("Scratch Base: 0x%llx\n", (unsigned long long)dev_info.scratch_base);
+	igt_info("Scratch Limit: 0x%llx\n", (unsigned long long)dev_info.scratch_limit);
+	igt_info("Scratch aperture size: %llu bytes, approx. %llu GB, approx. %llu TB\n",
+		 (unsigned long long)scratch_size,
+		 (unsigned long long)(scratch_size / BYTES_IN_GB),
+		 (unsigned long long)(scratch_size / BYTES_IN_TB));
+
+	/* Validate that limits are greater than bases */
+	igt_assert(dev_info.lds_limit > dev_info.lds_base);
+	igt_assert(dev_info.scratch_limit > dev_info.scratch_base);
+
+	/* Validate size is expected (e.g., 4GB) */
+	igt_assert_eq_u64(dev_info.lds_limit - dev_info.lds_base + 1, 0x100000000ULL);
+	igt_assert_eq_u64(dev_info.scratch_limit - dev_info.scratch_base + 1, 0x100000000ULL);
+
+	/* Print and validate GPUVM virtual address ranges */
+	igt_info("GPUVM virtual_address_offset: 0x%llx\n",
+		 (unsigned long long)dev_info.virtual_address_offset);
+	igt_info("GPUVM virtual_address_max: 0x%llx\n",
+		 (unsigned long long)dev_info.virtual_address_max);
+	igt_info("GPUVM high_va_offset: 0x%llx\n",
+		 (unsigned long long)dev_info.high_va_offset);
+	igt_info("GPUVM high_va_max: 0x%llx\n",
+		 (unsigned long long)dev_info.high_va_max);
+
+	igt_assert(dev_info.virtual_address_max > dev_info.virtual_address_offset);
+
+	if (dev_info.high_va_offset)
+		igt_assert(dev_info.high_va_max > dev_info.high_va_offset);
+
+	low_range = dev_info.virtual_address_max - dev_info.virtual_address_offset;
+	igt_info("GPUVM low range size: 0x%llx\n", (unsigned long long)low_range);
+	igt_info("GPUVM low range size: %llu bytes, approx. %llu GB, approx. %llu TB\n",
+		 (unsigned long long)low_range,
+		 (unsigned long long)(low_range / BYTES_IN_GB),
+		 (unsigned long long)(low_range / BYTES_IN_TB));
+
+	high_range = dev_info.high_va_max > dev_info.high_va_offset ?
+			      dev_info.high_va_max - dev_info.high_va_offset : 0;
+	igt_info("GPUVM high range size: 0x%llx\n", (unsigned long long)high_range);
+	igt_info("GPUVM high range size: %llu bytes, approx. %llu GB, approx. %llu TB\n",
+		 (unsigned long long)high_range,
+		 (unsigned long long)(high_range / BYTES_IN_GB),
+		 (unsigned long long)(high_range / BYTES_IN_TB));
+
+	/* Calculate and print total GPUVM size */
+	total_gpuvm_size = low_range + high_range;
+	igt_info("Total GPUVM size: %llu bytes, approx. %llu GB, approx. %llu TB\n",
+		 (unsigned long long)total_gpuvm_size,
+		 (unsigned long long)(total_gpuvm_size / BYTES_IN_GB),
+		 (unsigned long long)(total_gpuvm_size / BYTES_IN_TB));
+
+	/* Size checks (adjust thresholds as appropriate) */
+	igt_assert(low_range > (1ULL << 30));  // at least 1GB low range
+	if (high_range)
+		igt_assert(high_range > (1ULL << 30));  // at least 1GB high range if present
+}
+
 igt_main
 {
 	amdgpu_device_handle device;
@@ -230,6 +315,11 @@ igt_main
 	igt_subtest("amdgpu-vm-mapping-test")
 	amdgpu_vm_mapping_test(device);
 
+	/* Subtest for GPUVM, scratch, and LDS aperture sizes */
+	igt_describe("Validate GPUVM, scratch, and LDS aperture sizes from amdgpu_info ioctl");
+	igt_subtest("amdgpu-vm-aperture-sizes-test")
+		amdgpu_vm_aperture_sizes_test(device);
+
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);
-- 
2.34.1



More information about the igt-dev mailing list