From f82fa64a06f71700a99b641aeb8fc9ef16c0d940 Mon Sep 17 00:00:00 2001 From: kexinzhao Date: Mon, 12 Feb 2018 13:53:06 -0800 Subject: [PATCH] Move float16 into fluid folder (#8394) * move float16 into fluid * fix include * move to platform folder --- paddle/fluid/platform/CMakeLists.txt | 5 ++- paddle/{math => fluid/platform}/float16.h | 31 +++++++------------ .../platform/float16_test.cc} | 2 +- .../platform/float16_test.cu} | 2 +- paddle/math/tests/CMakeLists.txt | 2 -- 5 files changed, 17 insertions(+), 25 deletions(-) rename paddle/{math => fluid/platform}/float16.h (97%) rename paddle/{math/tests/test_float16.cpp => fluid/platform/float16_test.cc} (98%) rename paddle/{math/tests/test_float16.cu => fluid/platform/float16_test.cu} (99%) diff --git a/paddle/fluid/platform/CMakeLists.txt b/paddle/fluid/platform/CMakeLists.txt index 5ce4b3de39d..32e768fdf44 100644 --- a/paddle/fluid/platform/CMakeLists.txt +++ b/paddle/fluid/platform/CMakeLists.txt @@ -27,7 +27,7 @@ ELSE() set(MKLDNN_CTX_DEPS) ENDIF() -# memcpy deoends on device_context, here add deps individually for +# memcpy depends on device_context, here add deps individually for # avoiding cycle dependencies cc_library(device_context SRCS device_context.cc DEPS memory buddy_allocator system_allocator memory_block meta_data meta_cache place eigen3 ${GPU_CTX_DEPS} ${MKLDNN_CTX_DEPS}) @@ -39,3 +39,6 @@ nv_test(nccl_test SRCS nccl_test.cu DEPS dynload_cuda gpu_info device_context) cc_library(profiler SRCS profiler.cc DEPS device_context) cc_test(profiler_test SRCS profiler_test.cc DEPS profiler) + +nv_test(float16_gpu_test SRCS float16_test.cu) +cc_test(float16_test SRCS float16_test.cc) diff --git a/paddle/math/float16.h b/paddle/fluid/platform/float16.h similarity index 97% rename from paddle/math/float16.h rename to paddle/fluid/platform/float16.h index b00a85b082c..c36bfad4bc1 100644 --- a/paddle/math/float16.h +++ b/paddle/fluid/platform/float16.h @@ -68,7 +68,7 @@ namespace paddle { // memory access of float16 struct and also makes float16 compatible // with CUDA half, ARM float16_t, and Eigen::half data types. struct PADDLE_ALIGN(2) float16 { -public: + public: uint16_t x; // Constructors @@ -319,7 +319,7 @@ public: return static_cast(float(*this)); } -private: + private: union Bits { float f; int32_t si; @@ -485,8 +485,7 @@ HOST inline float16 operator+(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&(res.x)) : // clobbers "memory", "v0", "v1"); @@ -502,8 +501,7 @@ HOST inline float16 operator-(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&(res.x)) : // clobbers "memory", "v0", "v1"); @@ -519,8 +517,7 @@ HOST inline float16 operator*(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&(res.x)) : // clobbers "memory", "v0", "v1"); @@ -536,8 +533,7 @@ HOST inline float16 operator/(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&(res.x)) : // clobbers "memory", "v0", "v1"); @@ -588,8 +584,7 @@ HOST inline bool operator==(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&res) : // clobbers "memory", "v0", "v1"); @@ -609,8 +604,7 @@ HOST inline bool operator<(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&res) : // clobbers "memory", "v0", "v1"); @@ -626,8 +620,7 @@ HOST inline bool operator<=(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&res) : // clobbers "memory", "v0", "v1"); @@ -643,8 +636,7 @@ HOST inline bool operator>(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&res) : // clobbers "memory", "v0", "v1"); @@ -660,8 +652,7 @@ HOST inline bool operator>=(const float16& a, const float16& b) { "st1 {v0.h}[0], [%[res_ptr]]\n" : // outputs : // inputs - [a_ptr] "r"(&(a.x)), - [b_ptr] "r"(&(b.x)), + [a_ptr] "r"(&(a.x)), [b_ptr] "r"(&(b.x)), [res_ptr] "r"(&res) : // clobbers "memory", "v0", "v1"); diff --git a/paddle/math/tests/test_float16.cpp b/paddle/fluid/platform/float16_test.cc similarity index 98% rename from paddle/math/tests/test_float16.cpp rename to paddle/fluid/platform/float16_test.cc index 64cc43f9727..bed29dbfa7e 100644 --- a/paddle/math/tests/test_float16.cpp +++ b/paddle/fluid/platform/float16_test.cc @@ -9,7 +9,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/math/float16.h" +#include "paddle/fluid/platform/float16.h" #include diff --git a/paddle/math/tests/test_float16.cu b/paddle/fluid/platform/float16_test.cu similarity index 99% rename from paddle/math/tests/test_float16.cu rename to paddle/fluid/platform/float16_test.cu index 3b2d8cfcece..7e6c9f58aca 100644 --- a/paddle/math/tests/test_float16.cu +++ b/paddle/fluid/platform/float16_test.cu @@ -9,7 +9,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/math/float16.h" +#include "paddle/fluid/platform/float16.h" #include diff --git a/paddle/math/tests/CMakeLists.txt b/paddle/math/tests/CMakeLists.txt index dcd2a345834..d8b7f9e3fc7 100644 --- a/paddle/math/tests/CMakeLists.txt +++ b/paddle/math/tests/CMakeLists.txt @@ -22,7 +22,6 @@ if(WITH_GPU) link_paddle_test(test_Tensor) CUDA_ADD_EXECUTABLE(test_lazyAssign test_lazyAssign.cu) link_paddle_test(test_lazyAssign) - nv_test(test_float16_gpu SRCS test_float16.cu) else() compile_cu_as_cpp(test_Tensor.cu) add_unittest(test_Tensor test_Tensor.cu) @@ -34,4 +33,3 @@ 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) -- GitLab