From 22dfa5fa8aaec63753c73848813e280560a8152f Mon Sep 17 00:00:00 2001 From: Kexin Zhao Date: Thu, 16 Nov 2017 14:39:49 -0800 Subject: [PATCH] fix GPU compiling --- paddle/math/float16.h | 12 ++++++------ paddle/math/tests/CMakeLists.txt | 5 ++++- .../math/tests/{test_float16.cpp => test_float16.cu} | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) rename paddle/math/tests/{test_float16.cpp => test_float16.cu} (98%) diff --git a/paddle/math/float16.h b/paddle/math/float16.h index 3275546e69..6799a83bd3 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 ab4ac38b3c..dc06f99090 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 79f63d3a80..40bc54f5b4 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); -- GitLab