Skip to content

Conversation

@enirolf
Copy link
Contributor

@enirolf enirolf commented Oct 11, 2023

This PR adds support to 16-bit (IEEE 754-2008) floating point numbers to RNTuple. In similar vein to 32-bit doubles, this is enabled by changing the column representation of ordinary float fields (i.e., regular float fields are used, but the values are saved to disk using half precision).

Because half-precision floats are only part of the C++ standard from C++23 onwards, for now we use parts of the half library (MIT-licensed) for converting between half- and single-precision floats. For x86 processors, the F16C ISA extension can be enabled to do this conversion on the hardware directly. However, this appears to mess with TFormulaTests.

@enirolf enirolf self-assigned this Oct 11, 2023
@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac11/noimt, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2004/python3.
See console output.

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-3.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2023-10-11T17:31:20.272Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:174:4: error: ‘_Float16’ was not declared in this scope; did you mean ‘_Float64’?
  • [2023-10-11T17:31:20.272Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:176:7: error: ‘fp16Val’ was not declared in this scope
  • [2023-10-11T17:31:20.272Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:176:29: error: ‘_Float16’ does not name a type; did you mean ‘_Float64’?
  • [2023-10-11T17:31:20.272Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:187:4: error: ‘_Float16’ was not declared in this scope; did you mean ‘_Float64’?
  • [2023-10-11T17:31:20.272Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:189:20: error: ‘fp16Val’ was not declared in this scope

@phsft-bot
Copy link

Build failed on ROOT-performance-centos8-multicore/soversion.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Errors:

  • [2023-10-11T18:25:34.265Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:174:4: error: ‘_Float16’ was not declared in this scope
  • [2023-10-11T18:25:34.265Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:176:7: error: ‘fp16Val’ was not declared in this scope
  • [2023-10-11T18:25:34.520Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:176:29: error: ‘_Float16’ does not name a type; did you mean ‘_Float64’?
  • [2023-10-11T18:25:34.520Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:187:4: error: ‘_Float16’ was not declared in this scope
  • [2023-10-11T18:25:34.520Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:189:20: error: ‘fp16Val’ was not declared in this scope

@phsft-bot
Copy link

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(174,4): error C2065: '_Float16': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(174,13): error C2146: syntax error: missing ';' before identifier 'fp16Val' [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(174,13): error C2065: 'fp16Val': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(176,7): error C2065: 'fp16Val': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(176,29): error C2061: syntax error: identifier '_Float16' [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(177,39): error C2065: 'fp16Val': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(187,4): error C2065: '_Float16': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(187,13): error C2146: syntax error: missing ';' before identifier 'fp16Val' [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(187,13): error C2065: 'fp16Val': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]
  • [2023-10-11T18:08:29.273Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(189,20): error C2065: 'fp16Val': undeclared identifier [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]

And 1 more

@github-actions
Copy link

github-actions bot commented Oct 11, 2023

Test Results

       11 files         11 suites   1d 18h 13m 31s ⏱️
  2 481 tests   2 481 ✔️ 0 💤 0
26 220 runs  26 220 ✔️ 0 💤 0

Results for commit fefd73a.

♻️ This comment has been updated with latest results.

@phsft-bot
Copy link

Build failed on mac11/noimt.
See console output.

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link

Build failed on ROOT-performance-centos8-multicore/soversion.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Errors:

  • [2023-10-16T16:32:07.166Z] /data/sftnight/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:17:10: fatal error: ROOT/Float16.hxx: No such file or directory

@phsft-bot
Copy link

Build failed on mac12arm/cxx20.
Running on macphsft26.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2023-10-16T16:34:37.880Z] FAILED: tree/ntuple/CMakeFiles/ROOTNTuple.dir/v7/src/RColumnElement.cxx.o
  • [2023-10-16T16:34:38.139Z] /Users/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:17:10: fatal error: 'ROOT/Float16.hxx' file not found

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2004/python3.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2023-10-16T16:44:02.467Z] FAILED: tree/ntuple/CMakeFiles/ROOTNTuple.dir/v7/src/RColumnElement.cxx.o
  • [2023-10-16T16:44:02.777Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:17:10: fatal error: ROOT/Float16.hxx: No such file or directory

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2023-10-16T16:48:46.748Z] /home/sftnight/build/workspace/root-pullrequests-build/root/tree/ntuple/v7/src/RColumnElement.cxx:17:10: fatal error: ROOT/Float16.hxx: No such file or directory

@phsft-bot
Copy link

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2023-10-16T17:02:59.290Z] C:\build\workspace\root-pullrequests-build\root\tree\ntuple\v7\src\RColumnElement.cxx(17,10): fatal error C1083: Cannot open include file: 'ROOT/Float16.hxx': No such file or directory [C:\build\workspace\root-pullrequests-build\build\tree\ntuple\ROOTNTuple.vcxproj]

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2023-10-17T07:27:44.010Z] C:\build\workspace\root-pullrequests-build\root\core\imt\src\TTaskGroup.cxx(18,10): fatal error C1083: Cannot open include file: 'tbb/task_group.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\imt\Imt.vcxproj]
  • [2023-10-17T07:27:44.285Z] C:\build\workspace\root-pullrequests-build\root\core\imt\src\ROpaqueTaskArena.hxx(1,10): fatal error C1083: Cannot open include file: 'tbb/task_arena.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\imt\Imt.vcxproj]
  • [2023-10-17T07:27:45.429Z] C:\build\workspace\root-pullrequests-build\root\core\imt\src\ROpaqueTaskArena.hxx(1,10): fatal error C1083: Cannot open include file: 'tbb/task_arena.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\imt\Imt.vcxproj]

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-2.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2023-10-17T09:10:02.720Z] C:\build\workspace\root-pullrequests-build\root\core\imt\src\TTaskGroup.cxx(18,10): fatal error C1083: Cannot open include file: 'tbb/task_group.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\imt\Imt.vcxproj]
  • [2023-10-17T09:10:03.001Z] C:\build\workspace\root-pullrequests-build\root\core\imt\src\ROpaqueTaskArena.hxx(1,10): fatal error C1083: Cannot open include file: 'tbb/task_arena.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\imt\Imt.vcxproj]
  • [2023-10-17T09:10:04.178Z] C:\build\workspace\root-pullrequests-build\root\core\imt\src\ROpaqueTaskArena.hxx(1,10): fatal error C1083: Cannot open include file: 'tbb/task_arena.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\imt\Imt.vcxproj]

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2004/python3.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@enirolf enirolf marked this pull request as ready for review October 18, 2023 06:36
Copy link
Contributor

@jblomer jblomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I think it's very good shape.

Let's also add the new column type to the Packing.OnDiskEncoding unit test.

#define HALF_ENABLE_F16C_INTRINSICS __F16C__
#endif
#if HALF_ENABLE_F16C_INTRINSICS
#include <immintrin.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, does this actually enable intrinsics on a "standard platform"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not by default. ROOT would have to be compiled with -mf16c, but this doesn't seem to play nice with projectroot.test.test_TFormulaTests when added to the CMake configuration. It might be worth it to further investigate and come up with a solution, though.

FileRaii fileGuard("test_ntuple_float16.root");

auto f1Fld = RFieldBase::Create("f1", "float").Unwrap();
f1Fld->SetColumnRepresentative({ROOT::Experimental::EColumnType::kReal16});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f1Fld->SetColumnRepresentative({ROOT::Experimental::EColumnType::kReal16});
f1Fld->SetHalfPrecision();

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2004/python3.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

Copy link
Contributor

@jblomer jblomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Let's add one more test to the Packing, OnDiskEncoding unit test in ntuple_packing to verify the on-disk bit pattern is as expected.

floatArray[i] = Internal::HalfToFloat(uint16Array[i]);
ByteSwapIfNecessary(floatArray[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these two lines be reversed (in reverse order to packing)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're completely right!

@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@jblomer jblomer merged commit 21290a4 into root-project:master Nov 12, 2023
@enirolf enirolf deleted the ntuple-float16 branch November 29, 2023 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants