Skip to content

Commit 3205923

Browse files
reedwmThe ml_dtypes Authors
authored andcommitted
Add float8_base as friend class to FP4 and FP6 types.
This fixes a compile error on Clang 12 and below. Clang had a bug where if a superclass instantiated an instance of a subclass with a constructor defined in the superclass and brought into the subclass with a using-declaration, and the constructor had at least two arguments, compilation would fail. See https://godbolt.org/z/aeP9sP5x5 for an example. The error would complain that the superclass does not have access to the subclass's protected members, despite the constructor being declared in the superclass itself. The fix is to make the superclass a friend class of the subclass. This is already done in float8.h, but wasn't done in mxfloat.h. openxla/xla#19096 was rolled back since it added an include of mxfloat.h in TensorFlow, causing an Android TensorFlow build using Android NDK r21e to fail since this NDK uses Clang 9. PiperOrigin-RevId: 713847187
1 parent f656f18 commit 3205923

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ml_dtypes/include/mxfloat.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace mxfloat_internal {
3535
template <typename Derived>
3636
class mxfloat6_base : public float8_internal::float8_base<Derived> {
3737
using Base = float8_internal::float8_base<Derived>;
38+
friend class float8_internal::float8_base<Derived>;
3839
using Base::Base;
3940

4041
public:
@@ -54,6 +55,7 @@ class mxfloat6_base : public float8_internal::float8_base<Derived> {
5455
template <typename Derived>
5556
class mxfloat4_base : public float8_internal::float8_base<Derived> {
5657
using Base = float8_internal::float8_base<Derived>;
58+
friend class float8_internal::float8_base<Derived>;
5759
using Base::Base;
5860

5961
public:
@@ -74,6 +76,7 @@ class float6_e2m3fn : public mxfloat6_base<float6_e2m3fn> {
7476
// Exponent: 2, Mantissa: 3, bias: 1.
7577
// Extended range: no inf, no NaN.
7678
using Base = mxfloat6_base<float6_e2m3fn>;
79+
friend class float8_internal::float8_base<float6_e2m3fn>;
7780
using Base::Base;
7881

7982
public:
@@ -86,6 +89,7 @@ class float6_e3m2fn : public mxfloat6_base<float6_e3m2fn> {
8689
// Exponent: 3, Mantissa: 2, bias: 3.
8790
// Extended range: no inf, no NaN.
8891
using Base = mxfloat6_base<float6_e3m2fn>;
92+
friend class float8_internal::float8_base<float6_e3m2fn>;
8993
using Base::Base;
9094

9195
public:
@@ -98,6 +102,7 @@ class float4_e2m1fn : public mxfloat4_base<float4_e2m1fn> {
98102
// Exponent: 2, Mantissa: 1, bias: 1.
99103
// Extended range: no inf, no NaN.
100104
using Base = mxfloat4_base<float4_e2m1fn>;
105+
friend class float8_internal::float8_base<float4_e2m1fn>;;
101106
using Base::Base;
102107

103108
public:

0 commit comments

Comments
 (0)