mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
5.x core: rename cv::bfloat16_t to cv::bfloat (#25232)
* rename cv::bfloat16_t to cv::bfloat * clean class bfloat
This commit is contained in:
@@ -405,7 +405,7 @@ inline unsigned cv_abs(unsigned x) { return x; }
|
||||
inline uint64 cv_abs(uint64 x) { return x; }
|
||||
inline uint64 cv_abs(int64 x) { return (uint64)std::abs(x); }
|
||||
inline float cv_abs(float16_t x) { return std::abs((float)x); }
|
||||
inline float cv_abs(bfloat16_t x) { return std::abs((float)x); }
|
||||
inline float cv_abs(bfloat x) { return std::abs((float)x); }
|
||||
inline int cv_absdiff(uchar x, uchar y) { return (int)std::abs((int)x - (int)y); }
|
||||
inline int cv_absdiff(schar x, schar y) { return (int)std::abs((int)x - (int)y); }
|
||||
inline int cv_absdiff(ushort x, ushort y) { return (int)std::abs((int)x - (int)y); }
|
||||
@@ -414,7 +414,7 @@ inline unsigned cv_absdiff(int x, int y) { return (unsigned)(std::max(x, y) - st
|
||||
inline unsigned cv_absdiff(unsigned x, unsigned y) { return std::max(x, y) - std::min(x, y); }
|
||||
inline uint64 cv_absdiff(uint64 x, uint64 y) { return std::max(x, y) - std::min(x, y); }
|
||||
inline float cv_absdiff(float16_t x, float16_t y) { return std::abs((float)x - (float)y); }
|
||||
inline float cv_absdiff(bfloat16_t x, bfloat16_t y) { return std::abs((float)x - (float)y); }
|
||||
inline float cv_absdiff(bfloat x, bfloat y) { return std::abs((float)x - (float)y); }
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normL2Sqr(const _Tp* a, int n)
|
||||
|
||||
@@ -917,11 +917,12 @@ protected:
|
||||
#endif
|
||||
};
|
||||
|
||||
class bfloat16_t
|
||||
class bfloat
|
||||
{
|
||||
public:
|
||||
bfloat16_t() : w(0) {}
|
||||
explicit bfloat16_t(float x)
|
||||
bfloat() : w(0) {}
|
||||
|
||||
explicit bfloat(float x)
|
||||
{
|
||||
Cv32suf in;
|
||||
in.f = x;
|
||||
@@ -935,19 +936,6 @@ public:
|
||||
return out.f;
|
||||
}
|
||||
|
||||
static bfloat16_t fromBits(ushort b)
|
||||
{
|
||||
bfloat16_t result;
|
||||
result.w = b;
|
||||
return result;
|
||||
}
|
||||
static bfloat16_t zero()
|
||||
{
|
||||
bfloat16_t result;
|
||||
result.w = (ushort)0;
|
||||
return result;
|
||||
}
|
||||
ushort bits() const { return w; }
|
||||
protected:
|
||||
ushort w;
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ static inline void depthDispatch(const int depth, Args&&... args)
|
||||
Functor<cv::float16_t>{}(std::forward<Args>(args)...);
|
||||
break;
|
||||
case CV_16BF:
|
||||
Functor<cv::bfloat16_t>{}(std::forward<Args>(args)...);
|
||||
Functor<cv::bfloat>{}(std::forward<Args>(args)...);
|
||||
break;
|
||||
default:
|
||||
CV_Error(cv::Error::BadDepth, "Unsupported matrix type.");
|
||||
|
||||
@@ -247,8 +247,8 @@ CV_EXPORTS void addWeighted32u( const unsigned* src1, size_t step1, const unsign
|
||||
|
||||
CV_EXPORTS void cvt16f32f( const float16_t* src, float* dst, int len );
|
||||
CV_EXPORTS void cvt32f16f( const float* src, float16_t* dst, int len );
|
||||
CV_EXPORTS void cvt16bf32f( const bfloat16_t* src, float* dst, int len );
|
||||
CV_EXPORTS void cvt32f16bf( const float* src, bfloat16_t* dst, int len );
|
||||
CV_EXPORTS void cvt16bf32f( const bfloat* src, float* dst, int len );
|
||||
CV_EXPORTS void cvt32f16bf( const float* src, bfloat* dst, int len );
|
||||
|
||||
CV_EXPORTS void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len, int cn );
|
||||
CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len, int cn );
|
||||
|
||||
@@ -719,13 +719,13 @@ namespace CV__SIMD_NAMESPACE {
|
||||
//! @}
|
||||
|
||||
#ifndef OPENCV_HAL_HAVE_PACK_STORE_BFLOAT16
|
||||
inline v_float32 vx_load_expand(const bfloat16_t* ptr)
|
||||
inline v_float32 vx_load_expand(const bfloat* ptr)
|
||||
{
|
||||
v_uint32 v = vx_load_expand((const ushort*)ptr);
|
||||
return v_reinterpret_as_f32(v_shl<16>(v));
|
||||
}
|
||||
|
||||
inline void v_pack_store(const bfloat16_t* ptr, const v_float32& v)
|
||||
inline void v_pack_store(const bfloat* ptr, const v_float32& v)
|
||||
{
|
||||
v_int32 iv = v_shr<16>(v_reinterpret_as_s32(v));
|
||||
cv::v_pack_store((short*)ptr, iv);
|
||||
|
||||
@@ -3169,14 +3169,14 @@ inline void v_pack_store(float16_t* ptr, const v_float32x8& a)
|
||||
|
||||
/*#define OPENCV_HAL_HAVE_PACK_STORE_BFLOAT16 1
|
||||
|
||||
inline v_float32x8 v256_load_expand(const bfloat16_t* ptr)
|
||||
inline v_float32x8 v256_load_expand(const bfloat* ptr)
|
||||
{
|
||||
__m128i bf = _mm_loadu_si128((const __m128i*)ptr);
|
||||
__m256i f = _mm256_unpacklo_epi16(_mm256_setzero_si256(), _mm256_castsi128_si256(bf));
|
||||
return v_float32x8(_mm256_castsi256_ps(f));
|
||||
}
|
||||
|
||||
inline void v_pack_store(bfloat16_t* ptr, const v_float32x8& a)
|
||||
inline void v_pack_store(bfloat* ptr, const v_float32x8& a)
|
||||
{
|
||||
__m256i f = _mm256_castps_si256(a.val);
|
||||
f = _mm256_packs_epi32(_mm256_srai_epi32(f, 16), f);
|
||||
|
||||
@@ -163,7 +163,7 @@ template<> inline uint64 saturate_cast<uint64>(double v) { return (int64)rou
|
||||
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(float16_t v) { return saturate_cast<_Tp>((float)v); }
|
||||
template<typename _Tp> static inline _Tp saturate_cast(bfloat16_t v) { return saturate_cast<_Tp>((float)v); }
|
||||
template<typename _Tp> static inline _Tp saturate_cast(bfloat v) { return saturate_cast<_Tp>((float)v); }
|
||||
template<typename _Tp> static inline _Tp saturate_cast(bool v) { return saturate_cast<_Tp>(v ? 1 : 0); }
|
||||
|
||||
// in theory, we could use a LUT for 8u/8s->16f conversion,
|
||||
@@ -179,20 +179,20 @@ template<> inline float16_t saturate_cast<float16_t>(int64 v) { return float16
|
||||
template<> inline float16_t saturate_cast<float16_t>(float v) { return float16_t(v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(double v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(float16_t v) { return v; }
|
||||
template<> inline float16_t saturate_cast<float16_t>(bfloat16_t v) { return float16_t((float)v); }
|
||||
template<> inline float16_t saturate_cast<float16_t>(bfloat v) { return float16_t((float)v); }
|
||||
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(uchar v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(schar v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(ushort v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(short v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(unsigned v){ return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(int v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(uint64 v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(int64 v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(float v) { return bfloat16_t(v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(double v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(float16_t v) { return bfloat16_t((float)v); }
|
||||
template<> inline bfloat16_t saturate_cast<bfloat16_t>(bfloat16_t v) { return v; }
|
||||
template<> inline bfloat saturate_cast<bfloat>(uchar v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(schar v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(ushort v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(short v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(unsigned v){ return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(int v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(uint64 v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(int64 v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(float v) { return bfloat(v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(double v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(float16_t v) { return bfloat((float)v); }
|
||||
template<> inline bfloat saturate_cast<bfloat>(bfloat v) { return v; }
|
||||
|
||||
template<> inline bool saturate_cast<bool>(uchar v) { return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(schar v) { return v != 0; }
|
||||
@@ -205,7 +205,7 @@ template<> inline bool saturate_cast<bool>(double v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(uint64_t v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(int64_t v){ return v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(float16_t v){ return (float)v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(bfloat16_t v){ return (float)v != 0; }
|
||||
template<> inline bool saturate_cast<bool>(bfloat v){ return (float)v != 0; }
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
@@ -321,10 +321,10 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<bfloat16_t>
|
||||
template<> class DataType<bfloat>
|
||||
{
|
||||
public:
|
||||
typedef bfloat16_t value_type;
|
||||
typedef bfloat value_type;
|
||||
typedef float work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
@@ -431,7 +431,7 @@ template<> class TypeDepth<CV_16F>
|
||||
template<> class TypeDepth<CV_16BF>
|
||||
{
|
||||
enum { depth = CV_16BF };
|
||||
typedef bfloat16_t value_type;
|
||||
typedef bfloat value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_Bool>
|
||||
|
||||
Reference in New Issue
Block a user