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

Rename remaining float16_t for future proof #25387

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

fengyuentau
Copy link
Member

Resolves comment: #25217 (comment).

std::float16_t and std::bfloat16_t are introduced since c++23: https://en.cppreference.com/w/cpp/types/floating-point.

Pull Request Readiness Checklist

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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Comment on lines 904 to 905
#if !defined(OPENCV_HIDE_FLOAT16_T)
typedef hfloat float16_t;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In original comment there is complete guard condition to avoid using of float16_t in OpenCV code.


__cplusplus

That could be added to C too. No need to make conditions near C++.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maksim's solution #25210 (comment):

#if !(defined __STDCPP_FLOAT16_T__) && !(defined __ARM_NEON)
typedef our_pod_fp16_struct float16_t;
#endif

also looks good. Macro __STDCPP_FLOAT16_T__ stands for the existing of std::float16_t in C++23.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still want to see __OPENCV_BUILD condition here to avoid usage in OpenCV completely (to avoid mistakes like recent issue).

Copy link
Member Author

Choose a reason for hiding this comment

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

I still want to see __OPENCV_BUILD condition here to avoid usage in OpenCV completely (to avoid mistakes like recent issue).

Added.

const float16_t* a = (const float16_t*)_a;
const float16_t* b = (const float16_t*)_b;
float16_t* c = (float16_t*)_c;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we still need this float16_t?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because vdupq_n_f16 at line 505 is an macro defined in Clang arm_neon.h (details in #25210 (comment)). In this macro, float16_t is used, so this typedef has to be saved to make vdupq_n_f16 works unless we undo typedef hfloat float16_t in this file.

Note that vdupq_n_f16 in GCC arm_neon.h is an function.

Copy link
Member Author

@fengyuentau fengyuentau Apr 10, 2024

Choose a reason for hiding this comment

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

Maksim's solution may also work, which is to drop typedef hfloat float16_t for ARM platform: #25210 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

They all are dropped now.

Comment on lines 904 to 905
#if !defined(OPENCV_HIDE_FLOAT16_T)
typedef hfloat float16_t;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

In original comment there is complete guard condition to avoid using of float16_t in OpenCV code.


__cplusplus

That could be added to C too. No need to make conditions near C++.

@asmorkalov asmorkalov merged commit 197626a into opencv:4.x Apr 11, 2024
26 of 28 checks passed
@fengyuentau fengyuentau deleted the complete-float16_t-renaming branch April 11, 2024 12:51
@asmorkalov asmorkalov mentioned this pull request Apr 16, 2024
klatism pushed a commit to klatism/opencv that referenced this pull request May 17, 2024
…enaming

Rename remaining float16_t for future proof opencv#25387

Resolves comment: opencv#25217 (comment).

`std::float16_t` and `std::bfloat16_t` are introduced since c++23: https://en.cppreference.com/w/cpp/types/floating-point.

### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants