From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 32C0910E046 for ; Fri, 8 Sep 2023 09:14:12 +0000 (UTC) Date: Fri, 8 Sep 2023 11:13:45 +0200 From: Francois Dugast To: Zbigniew =?utf-8?Q?Kempczy=C5=84ski?= Message-ID: References: <20230905133309.365109-1-zbigniew.kempczynski@intel.com> <20230905133309.365109-6-zbigniew.kempczynski@intel.com> Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230905133309.365109-6-zbigniew.kempczynski@intel.com> MIME-Version: 1.0 Subject: Re: [igt-dev] [PATCH i-g-t v2 5/9] lib/intel_compute: Add i915 path in compute library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: On Tue, Sep 05, 2023 at 03:33:05PM +0200, Zbigniew Kempczyński wrote: > Add code which fills requirement to run compute workload on i915. > > Signed-off-by: Zbigniew Kempczyński > Cc: Christoph Manszewski > Cc: Francois Dugast > Cc: Mauro Carvalho Chehab Reviewed-by: Francois Dugast > --- > lib/intel_compute.c | 50 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 49 insertions(+), 1 deletion(-) > > diff --git a/lib/intel_compute.c b/lib/intel_compute.c > index a1e87ef46f..4344844825 100644 > --- a/lib/intel_compute.c > +++ b/lib/intel_compute.c > @@ -8,6 +8,7 @@ > > #include > > +#include "i915/gem_create.h" > #include "igt.h" > #include "xe_drm.h" > #include "lib/igt_syncobj.h" > @@ -38,6 +39,7 @@ struct bo_dict_entry { > uint32_t size; > void *data; > const char *name; > + uint32_t handle; > }; > > struct bo_execenv { > @@ -47,6 +49,10 @@ struct bo_execenv { > /* Xe part */ > uint32_t vm; > uint32_t exec_queue; > + > + /* i915 part */ > + struct drm_i915_gem_execbuffer2 execbuf; > + struct drm_i915_gem_exec_object2 *obj; > }; > > static void bo_execenv_create(int fd, struct bo_execenv *execenv) > @@ -101,6 +107,33 @@ static void bo_execenv_bind(struct bo_execenv *execenv, > } > > syncobj_destroy(fd, sync.handle); > + } else { > + struct drm_i915_gem_execbuffer2 *execbuf = &execenv->execbuf; > + struct drm_i915_gem_exec_object2 *obj; > + > + obj = calloc(entries, sizeof(*obj)); > + execenv->obj = obj; > + > + for (int i = 0; i < entries; i++) { > + bo_dict[i].handle = gem_create(fd, bo_dict[i].size); > + bo_dict[i].data = gem_mmap__device_coherent(fd, bo_dict[i].handle, > + 0, bo_dict[i].size, > + PROT_READ | PROT_WRITE); > + igt_debug("[i: %2d name: %20s] handle: %u, data: %p, addr: %16llx, size: %llx\n", > + i, bo_dict[i].name, > + bo_dict[i].handle, bo_dict[i].data, > + (long long)bo_dict[i].addr, > + (long long)bo_dict[i].size); > + > + obj[i].handle = bo_dict[i].handle; > + obj[i].offset = CANONICAL(bo_dict[i].addr); > + obj[i].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS; > + if (bo_dict[i].addr == ADDR_OUTPUT) > + obj[i].flags |= EXEC_OBJECT_WRITE; > + } > + > + execbuf->buffers_ptr = to_user_pointer(obj); > + execbuf->buffer_count = entries; > } > } > > @@ -123,6 +156,12 @@ static void bo_execenv_unbind(struct bo_execenv *execenv, > } > > syncobj_destroy(fd, sync.handle); > + } else { > + for (int i = 0; i < entries; i++) { > + gem_close(fd, bo_dict[i].handle); > + munmap(bo_dict[i].data, bo_dict[i].size); > + } > + free(execenv->obj); > } > } > > @@ -130,8 +169,17 @@ static void bo_execenv_exec(struct bo_execenv *execenv, uint64_t start_addr) > { > int fd = execenv->fd; > > - if (execenv->driver == INTEL_DRIVER_XE) > + if (execenv->driver == INTEL_DRIVER_XE) { > xe_exec_wait(fd, execenv->exec_queue, start_addr); > + } else { > + struct drm_i915_gem_execbuffer2 *execbuf = &execenv->execbuf; > + struct drm_i915_gem_exec_object2 *obj = execenv->obj; > + int num_objects = execbuf->buffer_count; > + > + execbuf->flags = I915_EXEC_RENDER; > + gem_execbuf(fd, execbuf); > + gem_sync(fd, obj[num_objects - 1].handle); /* batch handle */ > + } > } > > /* > -- > 2.34.1 >