[PATCH i-g-t] tests/intel/xe_exec_system_allocator: Add basic compute test

Francois Dugast francois.dugast at intel.com
Mon Apr 28 07:44:13 UTC 2025


The IGT compute library recently received multiple series of updates
to make it usable with the system allocator. This new test demonstrates
and validates how the system allocator and IGT compute can be wired up.
It is intentionally very basic for now.

Cc: Matthew Brost <matthew.brost at intel.com>
Signed-off-by: Francois Dugast <francois.dugast at intel.com>
---
 tests/intel/xe_exec_system_allocator.c | 56 ++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/tests/intel/xe_exec_system_allocator.c b/tests/intel/xe_exec_system_allocator.c
index e1121a862..a2d5353f5 100644
--- a/tests/intel/xe_exec_system_allocator.c
+++ b/tests/intel/xe_exec_system_allocator.c
@@ -18,6 +18,7 @@
 
 #include "igt.h"
 #include "lib/igt_syncobj.h"
+#include "lib/intel_compute.h"
 #include "lib/intel_reg.h"
 #include "xe_drm.h"
 
@@ -1570,6 +1571,57 @@ processes(int fd, int n_exec_queues, int n_execs, size_t bo_size,
 	munmap(pdata, sizeof(*pdata));
 }
 
+/**
+ * SUBTEST: compute-basic
+ * Description: Run a simple compute kernel with the system allocator
+ * Test category: functionality test
+ */
+static void
+test_compute(int fd, struct drm_xe_engine_class_instance *eci, size_t size)
+{
+	struct drm_xe_sync sync = {
+		.type = DRM_XE_SYNC_TYPE_USER_FENCE,
+		.flags = DRM_XE_SYNC_FLAG_SIGNAL,
+		.timeline_value = USER_FENCE_VALUE,
+	};
+	struct bo_sync {
+		uint64_t sync;
+	} *bo_sync;
+	uint32_t vm;
+	struct user_execenv env = {
+		.array_size = size / sizeof(float),
+	};
+	float *compute_input, *compute_output;
+	int i;
+
+	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE | DRM_XE_VM_CREATE_FLAG_FAULT_MODE, 0);
+	bo_sync = aligned_alloc(xe_get_default_alignment(fd), sizeof(*bo_sync));
+	sync.addr = to_user_pointer(&bo_sync->sync);
+	bind_system_allocator(&sync, 1);
+	xe_wait_ufence(fd, &bo_sync->sync, USER_FENCE_VALUE, 0, FIVE_SEC);
+
+	compute_input = aligned_alloc(xe_get_default_alignment(fd), size);
+	igt_assert(compute_input);
+	compute_output = aligned_alloc(xe_get_default_alignment(fd), size);
+	igt_assert(compute_output);
+
+	for (i = 0; i < env.array_size; i++)
+		compute_input[i] = rand() / (float)RAND_MAX;
+
+	env.input_addr = to_user_pointer(compute_input);
+	env.output_addr = to_user_pointer(compute_output);
+	env.vm = vm;
+	run_intel_compute_kernel(fd, &env);
+
+	for (i = 0; i < env.array_size; i++)
+		igt_assert_eq_double(compute_input[i] * compute_input[i], compute_output[i]);
+
+	free(compute_output);
+	free(compute_input);
+	unbind_system_allocator();
+	xe_vm_destroy(fd, vm);
+}
+
 struct section {
 	const char *name;
 	unsigned int flags;
@@ -1847,6 +1899,10 @@ igt_main
 			processes_evict(fd, SZ_8M, SZ_1M, s->flags);
 	}
 
+	igt_subtest("compute-basic")
+		xe_for_each_engine(fd, hwe)
+			test_compute(fd, hwe, SZ_8M);
+
 	igt_fixture {
 		xe_device_put(fd);
 		drm_close_driver(fd);
-- 
2.43.0



More information about the igt-dev mailing list