public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>,
	"Nishit Sharma" <nishit.sharma@intel.com>,
	"Francois Dugast" <francois.dugast@intel.com>
Subject: [PATCH i-g-t v4 2/5] lib/intel_compute: Extend userenv by adding input and output bos
Date: Tue,  3 Mar 2026 14:47:09 +0100	[thread overview]
Message-ID: <20260303134706.41948-9-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20260303134706.41948-7-zbigniew.kempczynski@intel.com>

Input and output addresses if were passed by userenv were related to
SVM addresses so buffers were created in the library and only bound
to offsets user wanted.

Extend this allowing user to pass addresses as well buffer objects
what allows user to set its own input and output data.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Nishit Sharma <nishit.sharma@intel.com>
Cc: Francois Dugast <francois.dugast@intel.com>
---
 lib/intel_compute.c | 70 ++++++++++++++++++++++++++++++++++-----------
 lib/intel_compute.h |  4 +++
 2 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/lib/intel_compute.c b/lib/intel_compute.c
index dfd38b8d8c..1165bdafd9 100644
--- a/lib/intel_compute.c
+++ b/lib/intel_compute.c
@@ -89,6 +89,7 @@ struct bo_dict_entry {
 	const char *name;
 	uint32_t handle;
 	enum bo_dict_type bo_type;
+	bool is_owner;
 };
 
 struct bo_sync {
@@ -169,14 +170,17 @@ static float *get_input_data(const struct bo_execenv *execenv,
 	const struct user_execenv *user = execenv->user;
 	float *input_data;
 
-	if (user && user->input_addr) {
+	if (user && user->input_addr && !user->input_bo) {
 		input_data = from_user_pointer(user->input_addr);
 	} else {
 		struct bo_dict_entry *entry;
 
 		entry = bo_dict_find_by_type(bo_dict, entries, BO_TYPE_INPUT);
 		input_data = (float *) entry->data;
-		bo_randomize(input_data, execenv->loop_count);
+
+		/* Don't randomize on user passed bo */
+		if ((!user) || (user && !user->input_bo))
+			bo_randomize(input_data, execenv->loop_count);
 	}
 
 	return input_data;
@@ -189,7 +193,7 @@ static float *get_output_data(const struct bo_execenv *execenv,
 	const struct user_execenv *user = execenv->user;
 	float *output_data;
 
-	if (user && user->output_addr)
+	if (user && user->output_addr && !user->output_bo)
 		output_data = from_user_pointer(user->output_addr);
 	else {
 		struct bo_dict_entry *entry;
@@ -297,6 +301,7 @@ static void bo_execenv_bind(struct bo_execenv *execenv,
 			uint32_t placement, flags = 0;
 
 			bo_sync->sync = 0;
+			bo_dict[i].is_owner = true;
 
 			switch (alloc_prefs) {
 			case EXECENV_PREF_SYSTEM:
@@ -312,14 +317,38 @@ static void bo_execenv_bind(struct bo_execenv *execenv,
 				break;
 			}
 
-			bo_dict[i].handle = xe_bo_create(fd, execenv->vm, bo_dict[i].size,
-							 placement, flags);
-			bo_dict[i].data = xe_bo_map(fd, bo_dict[i].handle, bo_dict[i].size);
-			xe_vm_bind_async(fd, vm, 0, bo_dict[i].handle, 0, bo_dict[i].addr,
-					 bo_dict[i].size, &sync, 1);
-			xe_wait_ufence(fd, &bo_sync->sync, USER_FENCE_VALUE, exec_queue,
-				       INT64_MAX);
-			memset(bo_dict[i].data, 0, bo_dict[i].size);
+			/*
+			 * For input/output buffers skip their creation if
+			 * were passed from the user
+			 */
+			if (execenv->user && bo_dict[i].bo_type == BO_TYPE_INPUT &&
+			    execenv->user->input_addr) {
+				bo_dict[i].handle = execenv->user->input_bo;
+				bo_dict[i].addr = execenv->user->input_addr;
+				bo_dict[i].size = execenv->array_size * sizeof(float);
+				bo_dict[i].is_owner = false;
+			} else if (execenv->user && bo_dict[i].bo_type == BO_TYPE_OUTPUT &&
+				   execenv->user->output_addr) {
+				bo_dict[i].handle = execenv->user->output_bo;
+				bo_dict[i].addr = execenv->user->output_addr;
+				bo_dict[i].size = execenv->array_size * sizeof(float);
+				bo_dict[i].is_owner = false;
+			} else {
+				bo_dict[i].handle = xe_bo_create(fd, execenv->vm, bo_dict[i].size,
+								 placement, flags);
+			}
+
+			if (bo_dict[i].handle) {
+				xe_vm_bind_async(fd, vm, 0, bo_dict[i].handle, 0, bo_dict[i].addr,
+						 bo_dict[i].size, &sync, 1);
+				xe_wait_ufence(fd, &bo_sync->sync, USER_FENCE_VALUE, exec_queue,
+					       INT64_MAX);
+			}
+
+			if (bo_dict[i].is_owner) {
+				bo_dict[i].data = xe_bo_map(fd, bo_dict[i].handle, bo_dict[i].size);
+				memset(bo_dict[i].data, 0, bo_dict[i].size);
+			}
 
 			igt_debug("[i: %2d name: %20s] data: %p, addr: %16llx, size: %llx\n",
 				  i, bo_dict[i].name, bo_dict[i].data,
@@ -385,11 +414,20 @@ static void bo_execenv_unbind(struct bo_execenv *execenv,
 
 		for (int i = 0; i < entries; i++) {
 			bo_sync->sync = 0;
-			xe_vm_unbind_async(fd, vm, 0, 0, bo_dict[i].addr, bo_dict[i].size, &sync, 1);
-			xe_wait_ufence(fd, &bo_sync->sync, USER_FENCE_VALUE, exec_queue,
-				       INT64_MAX);
-			munmap(bo_dict[i].data, bo_dict[i].size);
-			gem_close(fd, bo_dict[i].handle);
+			if (bo_dict[i].is_owner) {
+				xe_vm_unbind_async(fd, vm, 0, 0, bo_dict[i].addr, bo_dict[i].size, &sync, 1);
+				xe_wait_ufence(fd, &bo_sync->sync, USER_FENCE_VALUE, exec_queue,
+					       INT64_MAX);
+				munmap(bo_dict[i].data, bo_dict[i].size);
+			}
+			/* Keep user buffers intact */
+			if (execenv->user)
+				if ((execenv->user->input_bo && bo_dict[i].bo_type == BO_TYPE_INPUT) ||
+				    (execenv->user->output_bo && bo_dict[i].bo_type == BO_TYPE_OUTPUT))
+					continue;
+
+			if (bo_dict[i].handle)
+				gem_close(fd, bo_dict[i].handle);
 		}
 
 		munmap(bo_sync, bo_size);
diff --git a/lib/intel_compute.h b/lib/intel_compute.h
index 28c1efd55f..0775c8e86c 100644
--- a/lib/intel_compute.h
+++ b/lib/intel_compute.h
@@ -59,6 +59,10 @@ struct user_execenv {
 	bool skip_results_check;
 	/** @array_size: size of input and output arrays */
 	uint32_t array_size;
+	/** @input_bo: override default bo input handle if provided */
+	uint32_t input_bo;
+	/** @output_bo: override default bo output handle if provided */
+	uint32_t output_bo;
 	/** @input_addr: override default address of the input array if provided */
 	uint64_t input_addr;
 	/** @output_addr: override default address of the output array if provided */
-- 
2.43.0


  parent reply	other threads:[~2026-03-03 13:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 13:47 [PATCH i-g-t v4 0/5] Extend compute userenv to support user passed buffers Zbigniew Kempczyński
2026-03-03 13:47 ` [PATCH i-g-t v4 1/5] lib/intel_compute: Add types for input and output buffers Zbigniew Kempczyński
2026-03-03 13:47 ` Zbigniew Kempczyński [this message]
2026-03-03 13:47 ` [PATCH i-g-t v4 3/5] lib/intel_compute: Use user offsets and loop size if provided Zbigniew Kempczyński
2026-03-03 15:07   ` Sharma, Nishit
2026-03-03 16:37     ` Kamil Konieczny
2026-03-03 18:30       ` Sharma, Nishit
2026-03-04  7:56         ` Zbigniew Kempczyński
2026-03-03 16:31   ` Kamil Konieczny
2026-03-03 13:47 ` [PATCH i-g-t v4 4/5] tests/xe_compute: Exercise user passed buffers Zbigniew Kempczyński
2026-03-03 13:47 ` [PATCH i-g-t v4 5/5] tests/xe_compute: Use appropriate feature in compute-square tests Zbigniew Kempczyński
2026-03-03 14:56 ` [PATCH i-g-t v4 0/5] Extend compute userenv to support user passed buffers Sharma, Nishit
2026-03-04  7:59   ` Zbigniew Kempczyński
2026-03-04  3:24 ` ✓ Xe.CI.BAT: success for Extend compute userenv to support user passed buffers (rev4) Patchwork
2026-03-04  3:45 ` ✓ i915.CI.BAT: " Patchwork
2026-03-05  0:46 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-03-05  5:58 ` ✗ i915.CI.Full: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260303134706.41948-9-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@intel.com \
    --cc=francois.dugast@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=nishit.sharma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox