diff --git a/paddle/math/float16.h b/paddle/math/float16.h index 3275546e69ceb503fb6ae61725a971cc3e8341d8..6799a83bd391ab722d8bf1a08cdd9118133bfdcb 100644 --- a/paddle/math/float16.h +++ b/paddle/math/float16.h @@ -118,8 +118,8 @@ struct PADDLE_ALIGN(2) float16 { PADDLE_HOSTDEVICE inline float16(const Eigen::half& h) : x(h.x) {} #endif // USE_EIGEN -#if (PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34) && \ - defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) +#if defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) && \ + (PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34) // __fp16 is a native half precision data type for arm cpu, // float16_t is an alias for __fp16 in arm_fp16.h, // which is included in arm_neon.h. @@ -207,8 +207,8 @@ struct PADDLE_ALIGN(2) float16 { } #endif // USE_EIGEN -#if (PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34) && \ - defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) +#if defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) && \ + (PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34) PADDLE_HOSTDEVICE inline float16& operator=(const float16_t* rhs) { x = *reinterpret_cast(rhs); return *this; @@ -302,8 +302,8 @@ struct PADDLE_ALIGN(2) float16 { } #endif // USE_EIGEN -#if (PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34) && \ - defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) +#if defined(PADDLE_NEON) && defined(PADDLE_ARM_FP16) && \ + (PADDLE_GNUC_VER >= 61 || PADDLE_CLANG_VER >= 34) // check whether it works or not PADDLE_HOSTDEVICE inline operator float16_t() const { float16 h = *this; diff --git a/paddle/math/tests/CMakeLists.txt b/paddle/math/tests/CMakeLists.txt index ab4ac38b3c5aea5239b2b52efe20dffefa62dba1..dc06f990905459d5b63d21596b3e8d2aae603fef 100644 --- a/paddle/math/tests/CMakeLists.txt +++ b/paddle/math/tests/CMakeLists.txt @@ -22,15 +22,18 @@ if(WITH_GPU) link_paddle_test(test_Tensor) CUDA_ADD_EXECUTABLE(test_lazyAssign test_lazyAssign.cu) link_paddle_test(test_lazyAssign) + CUDA_ADD_EXECUTABLE(test_float16 test_float16.cu) + link_paddle_test(test_float16) else() compile_cu_as_cpp(test_Tensor.cu) add_unittest(test_Tensor test_Tensor.cu) compile_cu_as_cpp(test_lazyAssign.cu) add_unittest(test_lazyAssign test_lazyAssign.cu) + compile_cu_as_cpp(test_float16.cu) + add_unittest(test_float16 test_float16.cu) endif(WITH_GPU) add_simple_unittest(test_FPException) add_simple_unittest(test_GpuProfiler) add_simple_unittest(test_BaseMatrix) add_simple_unittest(test_Matrix) -add_simple_unittest(test_float16) diff --git a/paddle/math/tests/test_float16.cpp b/paddle/math/tests/test_float16.cu similarity index 98% rename from paddle/math/tests/test_float16.cpp rename to paddle/math/tests/test_float16.cu index 79f63d3a806ffb016d89368d665dc6bcea885080..40bc54f5b46e0111d10566e5978d338d90e24150 100644 --- a/paddle/math/tests/test_float16.cpp +++ b/paddle/math/tests/test_float16.cu @@ -15,7 +15,7 @@ limitations under the License. */ namespace paddle { #ifdef PADDLE_CUDA_FP16 -TEST(float16, gpu) { +TEST(float16, conversion_gpu) { // Conversion to and from cuda half float16 v1 = half(float16(1.0f)); EXPECT_EQ(v1.x, 0x3c00);