Skip to contentSkip to conversation

tests/amdgpu: add compute scratch memory test

PATCH New Jesse Zhang 2 participants 2 messages Jul 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/amdgpu: add compute scratch memory test

Add a gfx11 compute scratch-aperture round-trip test on the KGD user-mode-queue (UQM) path. It assembles a small ScratchCopyDword shader and dispatches it in two hops (src -> scratch aperture -> dst); dst == src proves the SPI scratch base and per-wave offset are correct. The aperture base comes from the kernel (dev_info.scratch_base) with a gfx11 constant fallback.

The UQM path exercises the compute CWSR context save/restore area:
lib/amdgpu enables the CWSR path and passes a correctly-sized MQD with a valid ctx_save_area. The compute MQD uAPI gains ctx_save_area_addr/size, ordered after cu_mask_* and the priority fields to match the kernel and libdrm layout.

v2: split per-generation packet emission into
amdgpu_emit_scratch_dispatch_gfx11() selected via a switch, keeping the common dispatch init (and IB bind) shared. (Vitaly)

---
 include/drm-uapi/amdgpu_drm.h           |  22 +-
 lib/amdgpu/amd_registers.h              |  26 +++
 lib/amdgpu/amd_userq.c                  |   7 +-
 lib/amdgpu/compute_utils/amd_dispatch.c | 266 ++++++++++++++++++++++++
 lib/amdgpu/compute_utils/amd_dispatch.h |   3 +
 tests/amdgpu/amd_dispatch.c             |  21 ++
 6 files changed, 333 insertions(+), 12 deletions(-)
include/drm-uapi/amdgpu_drm.h +11 -11
index b2a1688e6..66c37191b 100644
@@ -456,17 +456,6 @@ struct drm_amdgpu_userq_mqd_compute_gfx11 {
 	 * to get the size.
 	 */
 	__u64   eop_va;
-	/**
-	 * @ctx_save_area_addr: Virtual address of the GPU memory for save/restore buffer.
-	 * This must be a from a separate GPU object, and use AMDGPU_INFO IOCTL
-	 * to get the size.
-	 */
-	__u64 ctx_save_area_addr;
-	/**
-	 * @ctx_save_area_size:  Total size allocated for save/restore buffer.
-	 * Use AMDGPU_INFO IOCTL to get the size.
-	 */
-	__u32 ctx_save_area_size;
 	/**
 	 * @cu_mask_ptr: User-space pointer to CU (Compute Unit) mask array
 	 * Points to an array of __u32 values that define which CUs are enabled
@@ -494,6 +483,17 @@ struct drm_amdgpu_userq_mqd_compute_gfx11 {
 	 * Specifies the target XCC (Cross Compute Complex) for PM4 commands
 	 */
 	__u32 pm4_target_xcc;
+	/**
+	 * @ctx_save_area_addr: Virtual address of the GPU memory for save/restore buffer.
+	 * This must be a from a separate GPU object, and use AMDGPU_INFO IOCTL
+	 * to get the size.
+	 */
+	__u64 ctx_save_area_addr;
+	/**
+	 * @ctx_save_area_size:  Total size allocated for save/restore buffer.
+	 * Use AMDGPU_INFO IOCTL to get the size.
+	 */
+	__u32 ctx_save_area_size;
 };
 
 /* userq signal/wait ioctl */
lib/amdgpu/amd_registers.h +26 -0
index ff62b8931..ef87736a2 100644
@@ -34,6 +34,32 @@ enum general_reg {
 	COMPUTE_NUM_THREAD_X,
 };
 
+/*
+ * Absolute register offsets (mm*) of the COMPUTE SH registers, from
+ * drivers/gpu/drm/amd/include/asic_reg/gca/gfx_7_2_d.h (gfx9+ regs from
+ * gc_12_0_0_offset.h, converted to the mm scheme). A PM4 SET_SH_REG packet
+ * carries (mm_offset - PACKET3_SET_SH_REG_START); use SH_REG(name) below so
+ * the emit sites read as register names instead of magic numbers.
+ */
+#define PACKET3_SET_SH_REG_START		0x00002c00
+#define mmCOMPUTE_START_X			0x2e04
+#define mmCOMPUTE_NUM_THREAD_X			0x2e07
+#define mmCOMPUTE_PGM_LO			0x2e0c
+#define mmCOMPUTE_DISPATCH_SCRATCH_BASE_LO	0x2e10
+#define mmCOMPUTE_DISPATCH_SCRATCH_BASE_HI	0x2e11
+#define mmCOMPUTE_PGM_RSRC1			0x2e12
+#define mmCOMPUTE_PGM_RSRC2			0x2e13
+#define mmCOMPUTE_RESOURCE_LIMITS		0x2e15
+#define mmCOMPUTE_TMPRING_SIZE			0x2e18
+#define mmCOMPUTE_PGM_RSRC3			0x2e28
+#define mmCOMPUTE_USER_DATA_0			0x2e40
+
+/* PM4 SET_SH_REG register-field offset for a named compute register. */
+#define SH_REG(mmreg)		((mmreg) - PACKET3_SET_SH_REG_START)
+
+/* COMPUTE_PGM_RSRC2.SCRATCH_EN (bit 0). */
+#define COMPUTE_PGM_RSRC2__SCRATCH_EN		0x1
+
 struct amd_reg {
 	enum general_reg reg_name;
 	int 	 reg_offset;
lib/amdgpu/amd_userq.c +6 -1
index 98a53223d..f94991971 100644
@@ -3,6 +3,11 @@
  * Copyright 2025 Advanced Micro Devices, Inc.
  */
 
+/* libdrm exposes amdgpu_query_cwsr_info + struct drm_amdgpu_info_cwsr; enable
+ * the CWSR path so compute userq passes a valid ctx_save_area to the
+ * (cwsr-enabled) kernel. */
+#define HAVE_AMDGPU_INFO_CWSR 1
+
 #include "amd_userq.h"
 #include "amd_memory.h"
 #include "amd_PM4.h"
@@ -298,7 +303,7 @@ void amdgpu_user_queue_create(amdgpu_device_handle device_handle, struct amdgpu_
 	uint64_t gtt_flags = 0, queue_flags = 0;
 	struct drm_amdgpu_userq_mqd_gfx11 gfx_mqd;
 	struct drm_amdgpu_userq_mqd_sdma_gfx11 sdma_mqd;
-	struct drm_amdgpu_userq_mqd_compute_gfx11 compute_mqd;
+	struct drm_amdgpu_userq_mqd_compute_gfx11 compute_mqd = {0};
 	uint32_t ctl_stack_size_bytes = 0, dbg_mem_size_bytes = 0, min_save_area_size = 0;
 	bool compute_need_cwsr = false;
 	void *mqd;
lib/amdgpu/compute_utils/amd_dispatch.c +266 -0

285 lines not on this page · raw message

lib/amdgpu/compute_utils/amd_dispatch.h +3 -0
index 45858ba4b..6a0612779 100644
@@ -44,5 +44,8 @@ int amdgpu_memcpy_dispatch_test(amdgpu_device_handle device_handle,
 void amdgpu_dispatch_hang_slow_helper(amdgpu_device_handle device_handle,
 				      uint32_t ip_type, const struct pci_addr *pci, bool userq);
 
+int amdgpu_scratch_dispatch_test(amdgpu_device_handle device_handle,
+			       uint32_t ip_type, uint32_t version);
+
 
 #endif
tests/amdgpu/amd_dispatch.c +21 -0
index 44aa2d128..0496050b9 100644
@@ -42,6 +42,19 @@ amdgpu_dispatch_hang_compute(amdgpu_device_handle device_handle,
 	amdgpu_gfx_dispatch_test(device_handle, AMDGPU_HW_IP_COMPUTE, error, pci, userq);
 }
 
+static void
+amdgpu_dispatch_scratch_compute(amdgpu_device_handle device_handle)
+{
+	struct drm_amdgpu_info_hw_ip info;
+	uint32_t version;
+	int r;
+
+	r = amdgpu_query_hw_ip_info(device_handle, AMDGPU_HW_IP_COMPUTE, 0, &info);
+	igt_assert_eq(r, 0);
+	version = info.hw_ip_version_major;
+	amdgpu_scratch_dispatch_test(device_handle, AMDGPU_HW_IP_COMPUTE, version);
+}
+
 static void
 amdgpu_gpu_reset_test(amdgpu_device_handle device_handle, int drm_amdgpu,
 		const struct pci_addr *pci)
@@ -216,6 +229,14 @@ int igt_main()
 		}
 	}
 
+	igt_describe("Compute scratch(private) memory round-trip via aperture, kfdtest FlatScratchAccess port (user queue path)");
+	igt_subtest_with_dynamic("amdgpu-scratch-test-compute-with-IP-COMPUTE-UQM") {
+		if (enable_test && userq_arr_cap[AMD_IP_COMPUTE]) {
+			igt_dynamic_f("amdgpu-scratch-test-compute-uqm")
+			amdgpu_dispatch_scratch_compute(device);
+		}
+	}
+
 	igt_fixture() {
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);
Signature · 1 line
2.49.0
#1 lore raw

✗ Fi.CI.BUILD: failure for tests/amdgpu: add compute scratch memory test (rev2)

== Series Details ==

== Series Details ==

Series: tests/amdgpu: add compute scratch memory test (rev2)
URL : https://patchwork.freedesktop.org/series/169971/
State : failure

== Summary ==

Applying: tests/amdgpu: add compute scratch memory test Patch failed at 0001 tests/amdgpu: add compute scratch memory test When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".