1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #29369 from abhishek-gola:fp8_support

FP8 support in core module #29369

Core part of https://github.com/opencv/opencv/issues/29313

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Abhishek Gola
2026-07-15 18:15:01 +05:30
committed by GitHub
parent 18f9bffb0d
commit 34074075b2
19 changed files with 766 additions and 22 deletions
+13 -4
View File
@@ -13,6 +13,15 @@ const int ARITHM_MAX_CHANNELS = 4;
const int ARITHM_MAX_NDIMS = 4;
const int ARITHM_MAX_SIZE_LOG = 10;
// fp8 (E4M3) is excluded from the tolerance-checked element-wise pool: its 3-bit
// mantissa can't meet these tests' error bounds and out-of-range inputs overflow to
// NaN. fp8 conversion/arithmetic is covered directly in test_fp8.cpp.
static const _OutputArray::DepthMask DEPTH_MASK_ALL_NO_FP8 =
_OutputArray::DepthMask(_OutputArray::DEPTH_MASK_ALL &
~((1 << CV_8F_E4M3FN) | (1 << CV_8F_E4M3FNUZ)));
static const _OutputArray::DepthMask DEPTH_MASK_ALL_BUT_8S_NO_FP8 =
_OutputArray::DepthMask(DEPTH_MASK_ALL_NO_FP8 & ~_OutputArray::DEPTH_MASK_8S);
struct BaseElemWiseOp
{
enum
@@ -41,7 +50,7 @@ struct BaseElemWiseOp
virtual int getRandomType(RNG& rng)
{
return cvtest::randomType(rng, _OutputArray::DEPTH_MASK_ALL_BUT_8S, 1,
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S_NO_FP8, 1,
ninputs > 1 ? ARITHM_MAX_CHANNELS : 4);
}
@@ -895,8 +904,8 @@ struct ConvertScaleOp : public BaseElemWiseOp
}
int getRandomType(RNG& rng)
{
int srctype = cvtest::randomType(rng, _OutputArray::DEPTH_MASK_ALL, 1, ARITHM_MAX_CHANNELS);
ddepth = cvtest::randomType(rng, _OutputArray::DEPTH_MASK_ALL, 1, 1);
int srctype = cvtest::randomType(rng, DEPTH_MASK_ALL_NO_FP8, 1, ARITHM_MAX_CHANNELS);
ddepth = cvtest::randomType(rng, DEPTH_MASK_ALL_NO_FP8, 1, 1);
return srctype;
}
double getMaxErr(int)
@@ -994,7 +1003,7 @@ struct ConvertScaleAbsOp : public BaseElemWiseOp
}
int getRandomType(RNG& rng)
{
return cvtest::randomType(rng, _OutputArray::DEPTH_MASK_ALL, 1,
return cvtest::randomType(rng, DEPTH_MASK_ALL_NO_FP8, 1,
ninputs > 1 ? ARITHM_MAX_CHANNELS : 4);
}
double getMaxErr(int)