-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Renaming cv::float16_t and cv::bfloat16_t on 5.x to avoid redefinition #25210
Description
Describe the feature and motivation
cv::float16_t and cv::bfloat16_t are defined in modules/core/include/opencv2/core/cvdef.h, former of which was introduced long time ago, the other of which was added recently. They are created for the usage of fp16 and bf16 across different platforms internally in OpenCV. However, the naming has conflict with arm_neon.h which has definition typedef __fp16 float16_t;, leading to type redefinition or conflict for some of the fp16 intrinsics. For example, clang defines vdupq_n_f16 as a macro:
#ifdef __LITTLE_ENDIAN__
#define vdupq_n_f16(__p0) __extension__ ({ \
float16x8_t __ret; \
float16_t __s0 = __p0; \
__ret = (float16x8_t) {__s0, __s0, __s0, __s0, __s0, __s0, __s0, __s0}; \
__ret; \
})
#else
#define vdupq_n_f16(__p0) __extension__ ({ \
float16x8_t __ret; \
float16_t __s0 = __p0; \
__ret = (float16x8_t) {__s0, __s0, __s0, __s0, __s0, __s0, __s0, __s0}; \
__ret = __builtin_shufflevector(__ret, __ret, 7, 6, 5, 4, 3, 2, 1, 0); \
__ret; \
})
#endifWhen the preprocessor extracts vdupq_n_f16, the type float16_t in it will be treated as cv::float16_t instead of __fp16, leading to a compile error. Also note that C++23 introduces std::float16_t, std::bfloat16_t. Hence, we need to consider the renaming of existing cv::float16_t and cv::bfloat16_t.
Additional context
After a discussion with @vpisarev , we think they can be renamed as:
cv::float16_t -> cv::fp16_t
cv::bfloat16_t -> cv::bf16_t