Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of float16 support #11180

Open
wants to merge 77 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
560a333
Initial implementation of float16 support
eschnett Jun 30, 2024
cb57004
Define and use SIZEOF__FLOAT16
eschnett Jul 9, 2024
3390e9a
Merge branch 'master' into eschnett/float16-implementation
eschnett Jul 9, 2024
7fd149b
Correct various errors
eschnett Jul 9, 2024
5662f6f
Clean up GDALRasterBand statistics
eschnett Jul 9, 2024
54e82c8
Add more _Float16 #ifdefs
eschnett Jul 9, 2024
d6c2484
Slightly more float16 cleanup
eschnett Jul 10, 2024
1ee5414
zarr: Add more types to DMD_CREATIONDATATYPES
eschnett Jul 26, 2024
b551080
Avoid compiler warnings
eschnett Jul 26, 2024
fd91cec
Correct some test cases
eschnett Jul 26, 2024
20ee002
Correct test case
eschnett Jul 26, 2024
6d96613
Merge branch 'master' into eschnett/float16-implementation
eschnett Jul 26, 2024
f5d3e99
Reformat code
eschnett Jul 26, 2024
26431c2
Reformat code
eschnett Jul 26, 2024
eedd958
Make quicktest pass
eschnett Jul 26, 2024
7d28b1c
Introduce GDALNumericLimits
eschnett Jul 28, 2024
d6d7ad2
Avoid compiler warning
eschnett Jul 28, 2024
a92f5cb
Avoid compiler warning
eschnett Jul 28, 2024
4cf170e
Fix more bugs
eschnett Jul 28, 2024
a86d23a
Improve error messages
eschnett Jul 29, 2024
5961f90
Disable Zarr Python Float16 tests
eschnett Jul 29, 2024
b92c788
Merge branch 'eschnett/float16-implementation' of https://github.com/…
eschnett Jul 29, 2024
06a99ca
Capture current state
eschnett Oct 29, 2024
2a08cbe
Merge branch 'master' into eschnett/float16-implementation
eschnett Oct 29, 2024
35f6d73
Clean up code
eschnett Oct 29, 2024
44f554e
Correct some errors
eschnett Oct 29, 2024
fcbe2c5
Undo cmake change to debug Intel compiler failures
eschnett Oct 30, 2024
f9b4f0c
More float16 changes
eschnett Oct 30, 2024
7befa3a
Remove file
eschnett Oct 30, 2024
38843b6
Use Intel compiler in build_ext
eschnett Oct 30, 2024
c39db9f
Merge branch 'master' into eschnett/float16-implementation
eschnett Oct 30, 2024
46e39ab
Correct Intel compiler name
eschnett Oct 30, 2024
553b667
Allow disabling Float16 support
eschnett Oct 30, 2024
dac5d1e
Merge branch 'master' into eschnett/float16-implementation
eschnett Oct 30, 2024
7f98336
Correct spelling of `memcpy`
eschnett Oct 30, 2024
1fb90b3
Define new type GFloat16
eschnett Oct 31, 2024
a0dd3a7
Re-implement GFloat16
eschnett Oct 31, 2024
fd4b3c4
Undo changes to flatgeobuf
eschnett Oct 31, 2024
d4d358b
Correct nonsensical code
eschnett Oct 31, 2024
4f7c1eb
frmts/gtiff: Handle Float16 by converting to Float32
eschnett Oct 31, 2024
d7bde2a
Allow non-explicit constructores for GFloat16
eschnett Oct 31, 2024
e671938
Include cmath
eschnett Oct 31, 2024
3e7a6f0
Do not document GFloat16
eschnett Oct 31, 2024
e10dc06
Add tests for GFloat16
eschnett Oct 31, 2024
9d3e2f0
Correct preprocessor syntax
eschnett Oct 31, 2024
f70d695
frmts/grib: Include header files properly
eschnett Oct 31, 2024
cf6e2ff
Undo frmts/grib change
eschnett Oct 31, 2024
1a29503
Do not include cmath in cpl_port.h
eschnett Oct 31, 2024
8a7ee51
Make code checkers happy
eschnett Oct 31, 2024
138411d
Remove constexpr from GFloat16 functions
eschnett Nov 1, 2024
9d12db0
Improve code quality and debug
eschnett Nov 1, 2024
c1e33fe
Merge branch 'master' into eschnett/float16-implementation
eschnett Nov 1, 2024
d5496ea
Correct cmake
eschnett Nov 1, 2024
26d0e76
Correct cppcheck syntax
eschnett Nov 1, 2024
eafee05
Work around wrong division-by-zero error
eschnett Nov 1, 2024
43e1189
Merge branch 'master' into eschnett/float16-implementation
eschnett Nov 1, 2024
7a571ea
Update copyright
eschnett Nov 1, 2024
6627a40
Link against libgcc when fuzzing
eschnett Nov 1, 2024
89bb35a
Correct typos
eschnett Nov 1, 2024
d5180e8
CI: Undo fuzzing change
eschnett Nov 1, 2024
11ba08d
Merge branch 'master' into eschnett/float16-implementation
eschnett Nov 1, 2024
d838910
CIFuzz: Link against libgcc
eschnett Nov 1, 2024
8a5dd6f
CI/cppcheck: Ignore false positives
eschnett Nov 1, 2024
01a2cdd
Debug fuzzer
eschnett Nov 2, 2024
f3dcacd
Debug fuzzers
eschnett Nov 2, 2024
2046059
Debug fuzzers
eschnett Nov 2, 2024
da80174
Debug fuzzers
eschnett Nov 2, 2024
1d992dd
Debug fuzzers
eschnett Nov 2, 2024
c81965c
Re-enable all tests
eschnett Nov 2, 2024
29e3379
Remove GDALNumericLimits
eschnett Nov 2, 2024
e1a0d7e
Include <limits>
eschnett Nov 2, 2024
c20ff16
Do not rely on HAVE__FLOAT16 in most places
eschnett Nov 3, 2024
25c1312
Simplify code
eschnett Nov 4, 2024
f19e2db
Merge branch 'master' into eschnett/float16-implementation
eschnett Nov 4, 2024
1f16c8a
CI/CSA: Avoid false positivies
eschnett Nov 4, 2024
658af9d
autotest/gdrivers/zarr: Enable float16 mappings
eschnett Nov 4, 2024
f6c74ec
Document Float16
eschnett Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/icc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

set -eu

# Set C and C++ compiler flags to disable `_Float16`. This is
# necessary because the system C and C++ compilers don't support it,
# and Python's `build_ext` will use the system compiler to build GDAL
# Python extensions.

cmake ${GDAL_SOURCE_DIR:=..} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=icx \
-DCMAKE_CXX_COMPILER=icx \
-DCMAKE_C_FLAGS=-DGDAL_DISABLE_FLOAT16 \
-DCMAKE_CXX_FLAGS=-DGDAL_DISABLE_FLOAT16 \
-DUSE_CCACHE=ON
make -j$(nproc)

3 changes: 2 additions & 1 deletion alg/gdalchecksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ int CPL_STDCALL GDALChecksumImage(GDALRasterBandH hBand, int nXOff, int nYOff,
const GDALDataType eDataType = GDALGetRasterDataType(hBand);
const bool bComplex = CPL_TO_BOOL(GDALDataTypeIsComplex(eDataType));
const bool bIsFloatingPoint =
(eDataType == GDT_Float32 || eDataType == GDT_Float64 ||
(eDataType == GDT_Float16 || eDataType == GDT_Float32 ||
eDataType == GDT_Float64 || eDataType == GDT_CFloat16 ||
eDataType == GDT_CFloat32 || eDataType == GDT_CFloat64);

const auto IntFromDouble = [](double dfVal)
Expand Down
1 change: 1 addition & 0 deletions alg/gdalmediancut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "cpl_conv.h"
#include "cpl_error.h"
#include "cpl_float.h"
#include "cpl_progress.h"
#include "cpl_vsi.h"
#include "gdal.h"
Expand Down
20 changes: 20 additions & 0 deletions alg/gdalpansharpen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "cpl_conv.h"
#include "cpl_error.h"
#include "cpl_float.h"
#include "cpl_multiproc.h"
#include "cpl_vsi.h"
#include "../frmts/mem/memdataset.h"
Expand Down Expand Up @@ -1008,6 +1009,12 @@ CPLErr GDALPansharpenOperation::WeightedBrovey(
nBandValues, nMaxValue);
break;

case GDT_Float16:
WeightedBrovey(pPanBuffer, pUpsampledSpectralBuffer,
static_cast<GFloat16 *>(pDataBuf), nValues,
nBandValues, nMaxValue);
break;

case GDT_Float32:
WeightedBrovey(pPanBuffer, pUpsampledSpectralBuffer,
static_cast<float *>(pDataBuf), nValues, nBandValues,
Expand Down Expand Up @@ -1089,6 +1096,12 @@ CPLErr GDALPansharpenOperation::WeightedBrovey(
static_cast<std::int64_t *>(pDataBuf), nValues, nBandValues, 0);
break;

case GDT_Float16:
WeightedBrovey3<WorkDataType, GFloat16, FALSE>(
pPanBuffer, pUpsampledSpectralBuffer,
static_cast<GFloat16 *>(pDataBuf), nValues, nBandValues, 0);
break;

case GDT_Float32:
WeightedBrovey3<WorkDataType, float, FALSE>(
pPanBuffer, pUpsampledSpectralBuffer,
Expand Down Expand Up @@ -1764,6 +1777,13 @@ CPLErr GDALPansharpenOperation::PansharpenChunk(
pDataBuf, eBufDataType, nValues, nBandValues);
break;

case GDT_Float16:
eErr = WeightedBrovey(
static_cast<const GFloat16 *>(pPanBuffer),
static_cast<const GFloat16 *>(pUpsampledSpectralBuffer),
pDataBuf, eBufDataType, nValues, nBandValues);
break;

case GDT_Float32:
eErr = WeightedBrovey(
static_cast<const float *>(pPanBuffer),
Expand Down
9 changes: 9 additions & 0 deletions alg/gdalrasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ static void gvBurnScanline(void *pCBData, int nY, int nXStart, int nXEnd,
gvBurnScanlineBasic<std::uint64_t>(psInfo, nY, nXStart, nXEnd,
dfVariant);
break;
case GDT_Float16:
gvBurnScanlineBasic<GFloat16>(psInfo, nY, nXStart, nXEnd,
dfVariant);
break;
case GDT_Float32:
gvBurnScanlineBasic<float>(psInfo, nY, nXStart, nXEnd, dfVariant);
break;
Expand All @@ -252,6 +256,7 @@ static void gvBurnScanline(void *pCBData, int nY, int nXStart, int nXEnd,
break;
case GDT_CInt16:
case GDT_CInt32:
case GDT_CFloat16:
case GDT_CFloat32:
case GDT_CFloat64:
case GDT_Unknown:
Expand Down Expand Up @@ -371,6 +376,9 @@ static void gvBurnPoint(void *pCBData, int nY, int nX, double dfVariant)
case GDT_UInt64:
gvBurnPointBasic<std::uint64_t>(psInfo, nY, nX, dfVariant);
break;
case GDT_Float16:
gvBurnPointBasic<GFloat16>(psInfo, nY, nX, dfVariant);
break;
case GDT_Float32:
gvBurnPointBasic<float>(psInfo, nY, nX, dfVariant);
break;
Expand All @@ -379,6 +387,7 @@ static void gvBurnPoint(void *pCBData, int nY, int nX, double dfVariant)
break;
case GDT_CInt16:
case GDT_CInt32:
case GDT_CFloat16:
case GDT_CFloat32:
case GDT_CFloat64:
case GDT_Unknown:
Expand Down
1 change: 1 addition & 0 deletions alg/gdalwarper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "cpl_conv.h"
#include "cpl_error.h"
#include "cpl_float.h"
#include "cpl_mask.h"
#include "cpl_minixml.h"
#include "cpl_progress.h"
Expand Down
81 changes: 81 additions & 0 deletions alg/gdalwarpkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "cpl_atomic_ops.h"
#include "cpl_conv.h"
#include "cpl_error.h"
#include "cpl_float.h"
#include "cpl_mask.h"
#include "cpl_multiproc.h"
#include "cpl_progress.h"
Expand Down Expand Up @@ -1669,6 +1670,11 @@ static bool GWKSetPixelValue(const GDALWarpKernel *poWK, int iBand,
dfDstImag = 0.0;
break;

case GDT_Float16:
dfDstReal = reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset];
dfDstImag = 0.0;
break;

case GDT_Float32:
dfDstReal = reinterpret_cast<float *>(pabyDst)[iDstOffset];
dfDstImag = 0.0;
Expand All @@ -1691,6 +1697,13 @@ static bool GWKSetPixelValue(const GDALWarpKernel *poWK, int iBand,
reinterpret_cast<GInt32 *>(pabyDst)[iDstOffset * 2 + 1];
break;

case GDT_CFloat16:
dfDstReal =
reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset * 2];
dfDstImag =
reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset * 2 + 1];
break;

case GDT_CFloat32:
dfDstReal = reinterpret_cast<float *>(pabyDst)[iDstOffset * 2];
dfDstImag =
Expand Down Expand Up @@ -1790,6 +1803,11 @@ static bool GWKSetPixelValue(const GDALWarpKernel *poWK, int iBand,
CLAMP(std::int64_t);
break;

case GDT_Float16:
reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset] =
static_cast<GFloat16>(dfReal);
break;

case GDT_Float32:
reinterpret_cast<float *>(pabyDst)[iDstOffset] =
static_cast<float>(dfReal);
Expand Down Expand Up @@ -1851,6 +1869,13 @@ static bool GWKSetPixelValue(const GDALWarpKernel *poWK, int iBand,
break;
}

case GDT_CFloat16:
reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset * 2] =
static_cast<GFloat16>(dfReal);
reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset * 2 + 1] =
static_cast<GFloat16>(dfImag);
break;

case GDT_CFloat32:
reinterpret_cast<float *>(pabyDst)[iDstOffset * 2] =
static_cast<float>(dfReal);
Expand Down Expand Up @@ -1943,6 +1968,10 @@ static bool GWKSetPixelValueReal(const GDALWarpKernel *poWK, int iBand,
reinterpret_cast<std::uint64_t *>(pabyDst)[iDstOffset]);
break;

case GDT_Float16:
dfDstReal = reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset];
break;

case GDT_Float32:
dfDstReal = reinterpret_cast<float *>(pabyDst)[iDstOffset];
break;
Expand All @@ -1953,6 +1982,7 @@ static bool GWKSetPixelValueReal(const GDALWarpKernel *poWK, int iBand,

case GDT_CInt16:
case GDT_CInt32:
case GDT_CFloat16:
case GDT_CFloat32:
case GDT_CFloat64:
case GDT_Unknown:
Expand Down Expand Up @@ -2010,6 +2040,11 @@ static bool GWKSetPixelValueReal(const GDALWarpKernel *poWK, int iBand,
CLAMP(std::int64_t);
break;

case GDT_Float16:
reinterpret_cast<GFloat16 *>(pabyDst)[iDstOffset] =
static_cast<GFloat16>(dfReal);
break;

case GDT_Float32:
reinterpret_cast<float *>(pabyDst)[iDstOffset] =
static_cast<float>(dfReal);
Expand All @@ -2021,6 +2056,7 @@ static bool GWKSetPixelValueReal(const GDALWarpKernel *poWK, int iBand,

case GDT_CInt16:
case GDT_CInt32:
case GDT_CFloat16:
case GDT_CFloat32:
case GDT_CFloat64:
return false;
Expand Down Expand Up @@ -2103,6 +2139,11 @@ static bool GWKGetPixelValue(const GDALWarpKernel *poWK, int iBand,
*pdfImag = 0.0;
break;

case GDT_Float16:
*pdfReal = reinterpret_cast<GFloat16 *>(pabySrc)[iSrcOffset];
*pdfImag = 0.0;
break;

case GDT_Float32:
*pdfReal = reinterpret_cast<float *>(pabySrc)[iSrcOffset];
*pdfImag = 0.0;
Expand All @@ -2123,6 +2164,12 @@ static bool GWKGetPixelValue(const GDALWarpKernel *poWK, int iBand,
*pdfImag = reinterpret_cast<GInt32 *>(pabySrc)[iSrcOffset * 2 + 1];
break;

case GDT_CFloat16:
*pdfReal = reinterpret_cast<GFloat16 *>(pabySrc)[iSrcOffset * 2];
*pdfImag =
reinterpret_cast<GFloat16 *>(pabySrc)[iSrcOffset * 2 + 1];
break;

case GDT_CFloat32:
*pdfReal = reinterpret_cast<float *>(pabySrc)[iSrcOffset * 2];
*pdfImag = reinterpret_cast<float *>(pabySrc)[iSrcOffset * 2 + 1];
Expand Down Expand Up @@ -2203,6 +2250,10 @@ static bool GWKGetPixelValueReal(const GDALWarpKernel *poWK, int iBand,
reinterpret_cast<std::uint64_t *>(pabySrc)[iSrcOffset]);
break;

case GDT_Float16:
*pdfReal = reinterpret_cast<GFloat16 *>(pabySrc)[iSrcOffset];
break;

case GDT_Float32:
*pdfReal = reinterpret_cast<float *>(pabySrc)[iSrcOffset];
break;
Expand All @@ -2213,6 +2264,7 @@ static bool GWKGetPixelValueReal(const GDALWarpKernel *poWK, int iBand,

case GDT_CInt16:
case GDT_CInt32:
case GDT_CFloat16:
case GDT_CFloat32:
case GDT_CFloat64:
case GDT_Unknown:
Expand Down Expand Up @@ -2409,6 +2461,19 @@ static bool GWKGetPixelRow(const GDALWarpKernel *poWK, int iBand,
break;
}

case GDT_Float16:
{
GFloat16 *pSrc =
reinterpret_cast<GFloat16 *>(poWK->papabySrcImage[iBand]);
pSrc += iSrcOffset;
for (int i = 0; i < nSrcLen; i += 2)
{
adfReal[i] = pSrc[i];
adfReal[i + 1] = pSrc[i + 1];
}
break;
}

case GDT_Float32:
{
float *pSrc =
Expand Down Expand Up @@ -2467,6 +2532,22 @@ static bool GWKGetPixelRow(const GDALWarpKernel *poWK, int iBand,
break;
}

case GDT_CFloat16:
{
GFloat16 *pSrc =
reinterpret_cast<GFloat16 *>(poWK->papabySrcImage[iBand]);
pSrc += 2 * iSrcOffset;
for (int i = 0; i < nSrcLen; i += 2)
{
adfReal[i] = pSrc[2 * i];
padfImag[i] = pSrc[2 * i + 1];

adfReal[i + 1] = pSrc[2 * i + 2];
padfImag[i + 1] = pSrc[2 * i + 3];
}
break;
}

case GDT_CFloat32:
{
float *pSrc =
Expand Down
1 change: 1 addition & 0 deletions apps/gdaldem_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#include <limits>

#include "cpl_error.h"
#include "cpl_float.h"
#include "cpl_progress.h"
#include "cpl_string.h"
#include "cpl_vsi.h"
Expand Down
6 changes: 6 additions & 0 deletions apps/gdalinfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,9 @@ char *GDALInfo(GDALDatasetH hDataset, const GDALInfoOptions *psOptions)
case GDT_Int64:
stacDataType = "int64";
break;
case GDT_Float16:
stacDataType = "float16";
break;
case GDT_Float32:
stacDataType = "float32";
break;
Expand All @@ -1083,6 +1086,9 @@ char *GDALInfo(GDALDatasetH hDataset, const GDALInfoOptions *psOptions)
case GDT_CInt32:
stacDataType = "cint32";
break;
case GDT_CFloat16:
stacDataType = "cfloat16";
break;
case GDT_CFloat32:
stacDataType = "cfloat32";
break;
Expand Down
6 changes: 6 additions & 0 deletions apps/gdalmdiminfo_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ static void DumpValue(CPLJSonStreamingWriter &serializer, const GByte *bytes,
case GDT_UInt64:
DumpValue<std::uint64_t>(serializer, bytes);
break;
case GDT_Float16:
DumpValue<GFloat16>(serializer, bytes);
break;
case GDT_Float32:
DumpValue<float>(serializer, bytes);
break;
Expand All @@ -175,6 +178,9 @@ static void DumpValue(CPLJSonStreamingWriter &serializer, const GByte *bytes,
case GDT_CInt32:
DumpComplexValue<GInt32>(serializer, bytes);
break;
case GDT_CFloat16:
DumpComplexValue<GFloat16>(serializer, bytes);
break;
case GDT_CFloat32:
DumpComplexValue<float>(serializer, bytes);
break;
Expand Down
2 changes: 2 additions & 0 deletions autotest/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ set(QUICKTEST_LIST
test-block-cache-4
test-block-cache-5
test-block-cache-6
test-float16
test-copy-words
test-closed-on-destroy-DM
test-threaded-condition
Expand All @@ -303,6 +304,7 @@ set(QUICKTEST_LIST
test-deferred-plugin
)

gdal_gtest_target(testfloat16 test-float16 testfloat16.cpp)
gdal_gtest_target(testcopywords test-copy-words testcopywords.cpp)
gdal_gtest_target(testclosedondestroydm test-closed-on-destroy-DM testclosedondestroydm.cpp)
gdal_gtest_target(testthreadcond test-threaded-condition testthreadcond.cpp)
Expand Down
Loading
Loading