[lworld+fp16] RFR: 8329817: Augment prototype Float16 class

Jatin Bhateja jbhateja at openjdk.org
Tue Jun 11 17:27:27 UTC 2024


On Fri, 7 Jun 2024 04:22:49 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> Sketch of a more full-featured API for Float16.
>
> This PR has some known to-do items, including testing, but the PR does provide a more full featured API set on par with Float or Double, although without all the float/double handling method in Math/StrictMath.
> 
> One to-do item is writing the double -> float16 conversion routine. Other items include adjusting the binary <-> decimal conversion process to deal with the reduced precision of float16.

Hey @jddarcy,

Taking the liberty to append some notes on this PR for future extensions for flat layout representation. Your comments and suggestion will be highly appreciated.

Q. What will it take to support a flat layout for an array of Float16 values ?

A.  I will begin by mentioning some basic terminology related to nullity restrictions.

1) ImpliciltyConstructible :  An instance which is always assigned a default value and guarantees non-nullability by construction.
2) NullRestricted              :  A value field if null restricted will never be assigned a null value during its lifetime.  

Another question which I wanted to answer here is about representing a null value, a value object if not null restricted must be able to encode a null value in some form, for example, a value class with just one 32 bit integer field can only accommodate integral value range in 2s complement representation, in order to encode a null value it may need additional bit, thus a 32 bit integer with nullity may need more than 32 bits storage. Thus with a mix of null and non-null values flattening may not be much useful due to heterogeneity in element sizes. To simplify layout flattening we can always assume uniform element size by  always assuming null encoding, but then it may add complexities in auto-vectorizing these contiguously placed values.  

With above definitions in place,  it becomes easy for runtime to generate a flat memory layout for arrays of Float16 types if implicit constructability and non-nullability are always guaranteed.

Existing ValueBased classes under --enable-preview option ensures generating InlineKlass. 

Since we are making Float16 a value based class, hence we can extend the scope of value based classes to imply 1) and 2), but its a behavioral change and may impact semantics of existing value classes. For the time being we can decorate Float16 with 1) and 2) annotations along with some minor modifications in executions engines. to ensure flat layout.

Only doubt I have is w.r.t to application of NullRestricted annotation to an array, since its target type is a FIELD, thus it technically does not cover an array element.  

I have created a follow-up JBS for facilitating flat array layout for Float16 values.
https://bugs.openjdk.org/browse/JDK-8333852

Best Regards,
Jatin

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

PR Comment: https://git.openjdk.org/valhalla/pull/1117#issuecomment-2161269886



More information about the valhalla-dev mailing list