[code-reflection] Integrated: [fix][hat] Codegen fixed when passing the kernel context to multiple invoke functions

Juan Fumero duke at openjdk.org
Tue Aug 12 10:50:26 UTC 2025


On Tue, 12 Aug 2025 09:56:00 GMT, Juan Fumero <duke at openjdk.org> wrote:

> This PR fixes the code generator when passing the `kernelContext` object to new invoke functions within the main compute kernel. 
> 
> Code like this:
> ```java 
> @CodeReflection
> public static float compute(@RO KernelContext kc, @RO F32Array matrixA, @RO F32Array matrixB, int size, int j) {
>     float acc = 0;
>     for (int k = 0; k < size; k++) {
>         acc += (matrixA.array(kc.x * size + k) * matrixB.array(k * size + j));
>     }
>     return acc;
> }
> 
> @CodeReflection
> public static void matrixMultiplyKernel1D(@RO KernelContext kc, @RO F32Array matrixA, @RO F32Array matrixB, @RW F32Array matrixC, int size) {
>     if (kc.x < kc.maxX) {
>         for (int j = 0; j < size; j++) {
>             float acc = compute(kc, matrixA, matrixB, size, j);
>             matrixC.array(kc.x * size + j, acc);
>         }
>     }
> }
> 
> 
> Generated the following error when compiling the kernel:
> 
> 
> UNSUPPORTED (log once): buildComputeProgram: cl2Metal failed
> buildStatus =failed
> logLen = 1993 log  = program_source:33:5: error: unknown type name 'hat'
>     hat.KernelContext kc, __global F32Array_t* matrixA, __global F32Array_t* matrixB, int size, int j
>     ^
> 
> 
> This is due to the wrong naming from the `kernelContext` when it gets compiled to OpenCL or CUDA.
> This PR patches this by checking the argument type and replacing with the appropriate CUDA/OpenCL struct. 
> 
> ### How to check?
> 
> 
> HAT=INFO,SHOW_CODE java @hat/run ffi-opencl matmul 1DFC
> 
> 
> This patch has been tested for both the OpenCL and the CUDA HAT Backends.

This pull request has now been integrated.

Changeset: b9b8906c
Author:    Juan Fumero <jjfumero at gmail.com>
Committer: Gary Frost <gfrost at openjdk.org>
URL:       https://git.openjdk.org/babylon/commit/b9b8906cdd8f4d53ac8e34331a983d31070c6300
Stats:     50 lines in 2 files changed: 46 ins; 0 del; 4 mod

[fix][hat] Codegen fixed when passing the kernel context to multiple invoke functions

-------------

PR: https://git.openjdk.org/babylon/pull/519


More information about the babylon-dev mailing list