[code-reflection] RFR: [fix][hat] Codegen fixed when passing the kernel context to multiple invoke functions
duke
duke at openjdk.org
Tue Aug 12 10:03:41 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.
@jjfumero
Your change (at version ea9a7bf815001a618fa742a7dfe10c876b83885c) is now ready to be sponsored by a Committer.
-------------
PR Comment: https://git.openjdk.org/babylon/pull/519#issuecomment-3178657528
More information about the babylon-dev
mailing list