[PATCH i-g-t, v3 4/6] lib/intel_compute: Allow the user to provide a custom compute kernel
Francois Dugast
francois.dugast at intel.com
Wed Feb 26 11:24:05 UTC 2025
Allow the user to provide a custom compute kernel which will be used
instead of the default compute square one. This custom kernel _must_
fulfill requirements specified in the user_execenv::kernel doc. IGT
does not provide a complete runtime which can run generic kernels.
Allowing custom compute kernels gives us the possibility to leverage
the existing lib/intel_compute infrastructure to test corner cases.
More complex KMD tests will require simple specific compute kernels.
For example this one can trigger a page fault at 0x10000 from the
compute kernel context, so that we run other checks in KMD, all from
IGT:
__kernel void square(__global float* input,
__global float* output,
const unsigned int count) {
int i = get_global_id(0);
const __global uint* addr = 0x10000;
output[i] = *addr;
}
Signed-off-by: Francois Dugast <francois.dugast at intel.com>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
---
lib/intel_compute.c | 26 ++++++++++++++++++--------
lib/intel_compute.h | 14 ++++++++++++++
2 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/lib/intel_compute.c b/lib/intel_compute.c
index cad932c24..04fb83321 100644
--- a/lib/intel_compute.c
+++ b/lib/intel_compute.c
@@ -1778,6 +1778,8 @@ static bool __run_intel_compute_kernel(int fd,
unsigned int batch;
const struct intel_compute_kernels *kernels = intel_compute_square_kernels;
enum intel_driver driver = get_intel_driver(fd);
+ const unsigned char *kernel;
+ unsigned int kernel_size;
for (batch = 0; batch < ARRAY_SIZE(intel_compute_batches); batch++) {
if (ip_ver == intel_compute_batches[batch].ip_ver)
@@ -1795,16 +1797,24 @@ static bool __run_intel_compute_kernel(int fd,
return false;
}
- while (kernels->kernel) {
- if (ip_ver == kernels->ip_ver)
- break;
- kernels++;
+ /* If the user provides a kernel, use it */
+ if (user && user->kernel) {
+ kernel = user->kernel;
+ kernel_size = user->kernel_size;
+ } else {
+ while (kernels->kernel) {
+ if (ip_ver == kernels->ip_ver)
+ break;
+ kernels++;
+ }
+ if (!kernels->kernel)
+ return false;
+ kernel = kernels->kernel;
+ kernel_size = kernels->size;
}
- if (!kernels->kernel)
- return false;
- intel_compute_batches[batch].compute_exec(fd, kernels->kernel,
- kernels->size, eci, user);
+ intel_compute_batches[batch].compute_exec(fd, kernel,
+ kernel_size, eci, user);
return true;
}
diff --git a/lib/intel_compute.h b/lib/intel_compute.h
index 62e2422c4..3f6d0bb1d 100644
--- a/lib/intel_compute.h
+++ b/lib/intel_compute.h
@@ -39,6 +39,20 @@ struct intel_compute_kernels {
struct user_execenv {
/** @vm: use this VM if provided, otherwise create one */
uint32_t vm;
+ /**
+ * @kernel: use this custom kernel if provided, otherwise use a default square kernel
+ *
+ * Custom kernel execution in lib/intel_compute has strong limitations, it does not
+ * allow running any custom kernel. "count" is the size of the input and output arrays
+ * and the provided kernel must have the following prototype:
+ *
+ * __kernel void square(__global float* input,
+ * __global float* output,
+ * const unsigned int count)
+ */
+ const unsigned char *kernel;
+ /** @kernel_size: size of the custom kernel, if provided */
+ unsigned int kernel_size;
};
extern const struct intel_compute_kernels intel_compute_square_kernels[];
--
2.43.0
More information about the igt-dev
mailing list