[code-reflection] Integrated: [hat][proposal] ComputeRange and ThreadMesh API for defining 1D, 2D and 3D Ranges

Juan Fumero duke at openjdk.org
Thu Aug 14 11:11:32 UTC 2025


On Fri, 8 Aug 2025 14:00:23 GMT, Juan Fumero <duke at openjdk.org> wrote:

> This PR proposes an extension of the HAT API to leverage 1D, 2D and 3D ranges for the compute context dispatch. 
> A `ComputeRange` is an entity that holds global and local thread mesh. In the future, we can add offsets to it. 
> 
> Each `ThreadMesh` is a triplet representing the number of threads for x,y, and z dimensions. 
> 
> How to dispatch 1D kernels?
> 
> 
> ComputeRange range1D = new ComputeRange(new GlobalMesh1D(size));
> cc.dispatchKernel(range1D,
>                 kc -> myKernel(...));
> 
> 
> How to dispatch 2D kernels?
> 
> 
> ComputeRange range2D = new ComputeRange(new GlobalMesh2D(size, size));
> cc.dispatchKernel(range2D,
>                 kc -> my2DKernel(...));
> 
> 
> How to enable local mesh? 
> 
> We pass a second parameter to the ComputeRange constructor to define local mesh. If it is not passed, then it is `null` and the HAT runtime can select a default set of values. 
> 
> 
> ComputeRange computeRange = new ComputeRange(
>         new GlobalMesh2D(globalSize, globalSize), 
>         new LocalMesh2D(16, 16));
> cc.dispatchKernel(computeRange,
>                 kc -> matrixMultiplyKernel2D(kc, matrixA, matrixB, matrixC, globalSize)
>         );
> 
> 
> In addition, this PR renames the `KernelContext` internal API to map the context ndrange object to native memory to `KernelBufferContext`.
> 
> 
> #### How to check? 
> 
> 
> java @hat/run ffi-opencl matmul 1D
> java @hat/run ffi-opencl matmul 2D
> 
> java @hat/run ffi-cuda matmul 1D
> java @hat/run ffi-cuda matmul 2D

This pull request has now been integrated.

Changeset: 92df1be6
Author:    Juan Fumero <jjfumero at gmail.com>
Committer: Gary Frost <gfrost at openjdk.org>
URL:       https://git.openjdk.org/babylon/commit/92df1be61c8ef32f3ea2ac64c33b340b19737ec6
Stats:     851 lines in 23 files changed: 709 ins; 91 del; 51 mod

[hat][proposal] ComputeRange and ThreadMesh API for defining 1D, 2D and 3D Ranges

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

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


More information about the babylon-dev mailing list