[code-reflection] RFR: [hat][proposal] ComputeRange and ThreadMesh API for defining 1D, 2D and 3D Ranges
Juan Fumero
duke at openjdk.org
Mon Aug 11 09:56:24 UTC 2025
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 ThreadMesh1D(size));
cc.dispatchKernel(range1D,
kc -> myKernel(...));
How to dispatch 2D kernels?
ComputeRange range2D = new ComputeRange(new ThreadMesh2D(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 ThreadMesh2D(globalSize, globalSize),
new ThreadMesh2D(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
-------------
Commit messages:
- [hat] Javadoc for the rest of the ComputeRange Class
- [hat] Add threadmesh subtyping to keep consistency accross dimensions between global and local
- [hat] ThreadBlock dispatcher enabled for the CUDA backend
- [hat][api] Proposal for ComputeRange and ThreadMesh
Changes: https://git.openjdk.org/babylon/pull/516/files
Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=516&range=00
Stats: 639 lines in 18 files changed: 507 ins; 97 del; 35 mod
Patch: https://git.openjdk.org/babylon/pull/516.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/516/head:pull/516
PR: https://git.openjdk.org/babylon/pull/516
More information about the babylon-dev
mailing list