From 2d5bb375b7d2d2e1839419264b2779b420cdbd79 Mon Sep 17 00:00:00 2001 From: parthaEth Date: Fri, 8 Apr 2016 00:14:44 +0200 Subject: [PATCH 1/7] Static casting scalar types so as to let chlesky module of eigen work with ceres --- Eigen/src/Cholesky/LDLT.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index c3cc3746c..bd4902987 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -266,8 +266,8 @@ template<> struct ldlt_inplace if (size <= 1) { transpositions.setIdentity(); - if (numext::real(mat.coeff(0,0)) > 0) sign = PositiveSemiDef; - else if (numext::real(mat.coeff(0,0)) < 0) sign = NegativeSemiDef; + if (numext::real(mat.coeff(0,0)) > static_cast(0) ) sign = PositiveSemiDef; + else if (numext::real(mat.coeff(0,0)) < static_cast(0)) sign = NegativeSemiDef; else sign = ZeroSign; return true; } @@ -324,12 +324,12 @@ template<> struct ldlt_inplace A21 /= realAkk; if (sign == PositiveSemiDef) { - if (realAkk < 0) sign = Indefinite; + if (realAkk < static_cast(0)) sign = Indefinite; } else if (sign == NegativeSemiDef) { - if (realAkk > 0) sign = Indefinite; + if (realAkk > static_cast(0)) sign = Indefinite; } else if (sign == ZeroSign) { - if (realAkk > 0) sign = PositiveSemiDef; - else if (realAkk < 0) sign = NegativeSemiDef; + if (realAkk > static_cast(0)) sign = PositiveSemiDef; + else if (realAkk < static_cast(0)) sign = NegativeSemiDef; } } From d962fe6a9980065456718b1ab41750dcb76f8971 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 7 Apr 2016 20:28:32 -0700 Subject: [PATCH 2/7] Renamed float16 into cxx11_float16 since the test relies on c++11 features --- unsupported/test/CMakeLists.txt | 3 +-- unsupported/test/{float16.cpp => cxx11_float16.cpp} | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) rename unsupported/test/{float16.cpp => cxx11_float16.cpp} (98%) diff --git a/unsupported/test/CMakeLists.txt b/unsupported/test/CMakeLists.txt index 96652bfcf..c6a92fe73 100644 --- a/unsupported/test/CMakeLists.txt +++ b/unsupported/test/CMakeLists.txt @@ -110,13 +110,12 @@ ei_add_test(minres) ei_add_test(levenberg_marquardt) ei_add_test(kronecker_product) -ei_add_test(float16) - if(EIGEN_TEST_CXX11) # It should be safe to always run these tests as there is some fallback code for # older compiler that don't support cxx11. set(CMAKE_CXX_STANDARD 11) + ei_add_test(cxx11_float16) ei_add_test(cxx11_meta) ei_add_test(cxx11_tensor_simple) # ei_add_test(cxx11_tensor_symmetry) diff --git a/unsupported/test/float16.cpp b/unsupported/test/cxx11_float16.cpp similarity index 98% rename from unsupported/test/float16.cpp rename to unsupported/test/cxx11_float16.cpp index 13f3ddaca..44ffa67b3 100644 --- a/unsupported/test/float16.cpp +++ b/unsupported/test/cxx11_float16.cpp @@ -7,7 +7,7 @@ #define EIGEN_TEST_NO_LONGDOUBLE #define EIGEN_TEST_NO_COMPLEX -#define EIGEN_TEST_FUNC float16 +#define EIGEN_TEST_FUNC cxx11_float16 #include "main.h" #include @@ -138,7 +138,7 @@ void test_functions() VERIFY_IS_APPROX(float(numext::log(half(10.0f))), 2.30273f); } -void test_float16() +void test_cxx11_float16() { CALL_SUBTEST(test_conversion()); CALL_SUBTEST(test_arithmetic()); From 7c47d3e663375743e28bfd8863af1091f3b7c8b1 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 7 Apr 2016 22:50:25 -0700 Subject: [PATCH 3/7] Fixed the type casting benchmarks for fp16 --- bench/tensors/tensor_benchmarks.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bench/tensors/tensor_benchmarks.h b/bench/tensors/tensor_benchmarks.h index 16b388abf..90b9bc741 100644 --- a/bench/tensors/tensor_benchmarks.h +++ b/bench/tensors/tensor_benchmarks.h @@ -46,8 +46,13 @@ template class BenchmarkSuite { void typeCasting(int num_iters) { eigen_assert(m_ == n_); Eigen::array sizes; - sizes[0] = m_; - sizes[1] = k_; + if (sizeof(T) >= sizeof(int)) { + sizes[0] = m_; + sizes[1] = k_; + } else { + sizes[0] = m_ * sizeof(T) / sizeof(int); + sizes[1] = k_ * sizeof(T) / sizeof(int); + } const TensorMap, Eigen::Aligned> A((int*)a_, sizes); TensorMap, Eigen::Aligned> B(b_, sizes); From 63102ee43d3f0507b75a95a3b8ee6ced92316322 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 7 Apr 2016 23:05:20 -0700 Subject: [PATCH 4/7] Turn on the coeffWise benchmarks on fp16 --- bench/tensors/tensor_benchmarks_fp16_gpu.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/tensors/tensor_benchmarks_fp16_gpu.cu b/bench/tensors/tensor_benchmarks_fp16_gpu.cu index 35c6f7489..d34bd73ca 100644 --- a/bench/tensors/tensor_benchmarks_fp16_gpu.cu +++ b/bench/tensors/tensor_benchmarks_fp16_gpu.cu @@ -28,7 +28,7 @@ BM_FuncGPU(shuffling); BM_FuncGPU(padding); BM_FuncGPU(striding); BM_FuncGPU(broadcasting); -//BM_FuncGPU(coeffWiseOp); +BM_FuncGPU(coeffWiseOp); //BM_FuncGPU(algebraicFunc); //BM_FuncGPU(transcendentalFunc); BM_FuncGPU(rowReduction); From 3bd16457e14a79f0293e5cec29e22f7c62a3a359 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 7 Apr 2016 23:28:04 -0700 Subject: [PATCH 5/7] Properly handle complex numbers. --- Eigen/src/Cholesky/LDLT.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index bd4902987..1d767d5c8 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -266,8 +266,8 @@ template<> struct ldlt_inplace if (size <= 1) { transpositions.setIdentity(); - if (numext::real(mat.coeff(0,0)) > static_cast(0) ) sign = PositiveSemiDef; - else if (numext::real(mat.coeff(0,0)) < static_cast(0)) sign = NegativeSemiDef; + if (numext::real(mat.coeff(0,0)) > static_cast(0) ) sign = PositiveSemiDef; + else if (numext::real(mat.coeff(0,0)) < static_cast(0)) sign = NegativeSemiDef; else sign = ZeroSign; return true; } @@ -324,12 +324,12 @@ template<> struct ldlt_inplace A21 /= realAkk; if (sign == PositiveSemiDef) { - if (realAkk < static_cast(0)) sign = Indefinite; + if (realAkk < static_cast(0)) sign = Indefinite; } else if (sign == NegativeSemiDef) { - if (realAkk > static_cast(0)) sign = Indefinite; + if (realAkk > static_cast(0)) sign = Indefinite; } else if (sign == ZeroSign) { - if (realAkk > static_cast(0)) sign = PositiveSemiDef; - else if (realAkk < static_cast(0)) sign = NegativeSemiDef; + if (realAkk > static_cast(0)) sign = PositiveSemiDef; + else if (realAkk < static_cast(0)) sign = NegativeSemiDef; } } From cd2b667ac80adc54df1496273a3cbe83d2eb1607 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 8 Apr 2016 08:12:47 -0400 Subject: [PATCH 6/7] Add references to filed LLVM bugs --- Eigen/src/Core/arch/NEON/PacketMath.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Eigen/src/Core/arch/NEON/PacketMath.h b/Eigen/src/Core/arch/NEON/PacketMath.h index 63a2d9f52..3224c36bd 100644 --- a/Eigen/src/Core/arch/NEON/PacketMath.h +++ b/Eigen/src/Core/arch/NEON/PacketMath.h @@ -179,6 +179,8 @@ template<> EIGEN_STRONG_INLINE Packet4i pdiv(const Packet4i& /*a*/, co // Clang/ARM wrongly advertises __ARM_FEATURE_FMA even when it's not available, // then implements a slow software scalar fallback calling fmaf()! +// Filed LLVM bug: +// https://llvm.org/bugs/show_bug.cgi?id=27216 #if (defined __ARM_FEATURE_FMA) && !(EIGEN_COMP_CLANG && EIGEN_ARCH_ARM) // See bug 936. // FMA is available on VFPv4 i.e. when compiling with -mfpu=neon-vfpv4. @@ -195,6 +197,8 @@ template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& // -march=armv7-a, that is a very common case. // See e.g. this thread: // http://lists.llvm.org/pipermail/llvm-dev/2013-December/068806.html + // Filed LLVM bug: + // https://llvm.org/bugs/show_bug.cgi?id=27219 Packet4f r = c; asm volatile( "vmla.f32 %q[r], %q[a], %q[b]" From 2d072b38c134c60fb796e36466fd4e7a1888ce35 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 8 Apr 2016 12:50:25 -0700 Subject: [PATCH 7/7] Don't test the division by 0 on float16 when compiling with msvc since msvc detects and errors out on divisions by 0. --- unsupported/test/cxx11_float16.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unsupported/test/cxx11_float16.cpp b/unsupported/test/cxx11_float16.cpp index 44ffa67b3..2dc0872d8 100644 --- a/unsupported/test/cxx11_float16.cpp +++ b/unsupported/test/cxx11_float16.cpp @@ -64,9 +64,13 @@ void test_conversion() VERIFY((numext::isnan)(float(half(__half{0xfc01})))); VERIFY((numext::isinf)(float(half(__half{0x7c00})))); VERIFY((numext::isnan)(float(half(__half{0x7c01})))); + +#if !EIGEN_COMP_MSVC + // Visual Studio errors out on divisions by 0 VERIFY((numext::isnan)(float(half(0.0 / 0.0)))); VERIFY((numext::isinf)(float(half(1.0 / 0.0)))); VERIFY((numext::isinf)(float(half(-1.0 / 0.0)))); +#endif // Exactly same checks as above, just directly on the half representation. VERIFY(!(numext::isinf)(half(__half{0x7bff}))); @@ -75,9 +79,13 @@ void test_conversion() VERIFY((numext::isnan)(half(__half{0xfc01}))); VERIFY((numext::isinf)(half(__half{0x7c00}))); VERIFY((numext::isnan)(half(__half{0x7c01}))); + +#if !EIGEN_COMP_MSVC + // Visual Studio errors out on divisions by 0 VERIFY((numext::isnan)(half(0.0 / 0.0))); VERIFY((numext::isinf)(half(1.0 / 0.0))); VERIFY((numext::isinf)(half(-1.0 / 0.0))); +#endif } void test_arithmetic()