[code-reflection] RFR: Second Proposal to generalize handling of Vector Types based on 644 [v2]

Juan Fumero jfumero at openjdk.org
Fri Oct 31 09:43:41 UTC 2025


On Fri, 31 Oct 2025 09:38:41 GMT, Juan Fumero <jfumero at openjdk.org> wrote:

>> This PR adds another proposal for generalising HAT Vector Types. 
>> 
>> It is based on PR #644 as an alternative approach. So we can evaluate each proposal and device which one to move forward. 
>> 
>> This approach replaces the `@HATVectorType` annotation with a set of interfaces to identify base type and width of the vector type being represented. 
>> 
>> For instance:
>> 
>> 
>> public interface _V {
>>     PrimitiveType type();
>>     int width();
>> }
>> 
>> public interface _V4 extends _V {
>> 
>>     @CodeReflection
>>     @Override
>>     default int width() {
>>         return 4;
>>     }
>> }
>> 
>> 
>> public interface Float4 extends _V4 {
>> 
>>     float x();
>>     float y();
>>     float z();
>>     float w();
>> 
>>     @CodeReflection
>>     @Override
>>     default PrimitiveType type() {
>>         return JavaType.FLOAT;
>>     }
>> 
>>    ...
>> 
>> }
>> 
>> 
>> Note that both methods, width and type, are annotated with `@CodeReflection`. During the "dialectify" process, this approach builds the code models for both methods and inspects the meta-data values. 
>> 
>> Some restrictions:
>> 
>> - `Float4` is not an `iFace` interface due to the small granularity. 
>> - Usually, these types are inspected from the kernel code, so we don't have instance objects.
>> - Returning `PrimitiveType` from the `type` method allows us to be restricted in the amount of base types to support. 
>> 
>> 
>> How to test:
>> 
>> For OpenCL:
>> 
>> 
>> HAT=SHOW_CODE,SHOW_COMPILATION_PHASES java @hat/otest ffi-opencl hat.test.TestVectorTypes
>> 
>> 
>> For CUDA:
>> 
>> 
>> 
>> HAT=SHOW_CODE,SHOW_COMPILATION_PHASES java @hat/otest ffi-cuda hat.test.TestVectorTypes
>> 
>> 
>> This PR has been tested with both OpenCL and CUDA backends.
>
> Juan Fumero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   [hat] Cleanup phase utils

This version works with the latest version of code-reflection and the OpenCL/CUDA backends.

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

PR Comment: https://git.openjdk.org/babylon/pull/647#issuecomment-3472153689


More information about the babylon-dev mailing list