Skip to content

Commit 19e5c24

Browse files
committed
fix bug
1 parent d646e47 commit 19e5c24

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

paddle/math/float16.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ limitations under the License. */
1515
#pragma once
1616

1717
#include <cstdint>
18-
#include <istream>
19-
#include <ostream>
2018

2119
#include <cuda.h>
2220
#include "unsupported/Eigen/CXX11/Tensor"
@@ -117,7 +115,8 @@ struct PADDLE_ALIGN(2) float16 {
117115
// float16_t is an alias for __fp16 in arm_fp16.h,
118116
// which is included in arm_neon.h.
119117
PADDLE_HOSTDEVICE inline float16(const float16_t& h) {
120-
x = *reinterpret_cast<uint16_t*>(&h);
118+
float16_t tmp = h;
119+
x = *reinterpret_cast<uint16_t*>(&tmp);
121120
}
122121
#endif
123122

@@ -197,7 +196,8 @@ struct PADDLE_ALIGN(2) float16 {
197196
#if defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) && \
198197
(PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34)
199198
PADDLE_HOSTDEVICE inline float16& operator=(const float16_t& rhs) {
200-
x = *reinterpret_cast<uint16_t*>(&rhs);
199+
float16_t tmp = rhs;
200+
x = *reinterpret_cast<uint16_t*>(&tmp);
201201
return *this;
202202
}
203203
#endif
@@ -460,23 +460,37 @@ __host__ inline bool operator!=(const float16& a, const float16& b) {
460460
return !(a == b);
461461
}
462462

463-
#ifdef PADDLE_NEON_64
464463
__host__ inline bool operator<(const float16& a, const float16& b) {
464+
#ifdef PADDLE_NEON_64
465465
return static_cast<bool>(vclth_f16(float16_t(a), float16_t(b)));
466+
#else
467+
return float(a) < float(b);
468+
#endif // PADDLE_NEON_64
466469
}
467470

468471
__host__ inline bool operator<=(const float16& a, const float16& b) {
472+
#ifdef PADDLE_NEON_64
469473
return static_cast<bool>(vcleh_f16(float16_t(a), float16_t(b)));
474+
#else
475+
return float(a) <= float(b);
476+
#endif // PADDLE_NEON_64
470477
}
471478

472479
__host__ inline bool operator>(const float16& a, const float16& b) {
480+
#ifdef PADDLE_NEON_64
473481
return static_cast<bool>(vcgth_f16(float16_t(a), float16_t(b)));
482+
#else
483+
return float(a) > float(b);
484+
#endif // PADDLE_NEON_64
474485
}
475486

476487
__host__ inline bool operator>=(const float16& a, const float16& b) {
488+
#ifdef PADDLE_NEON_64
477489
return static_cast<bool>(vcgeh_f16(float16_t(a), float16_t(b)));
478-
}
490+
#else
491+
return float(a) >= float(b);
479492
#endif // PADDLE_NEON_64
493+
}
480494

481495
#else // Software emulation on other cpu
482496
PADDLE_HOSTDEVICE inline float16 operator+(const float16& a, const float16& b) {

0 commit comments

Comments
 (0)