From bef6b1cfb6d856d908ff695cb02718f7dd526a72 Mon Sep 17 00:00:00 2001 From: David Norman Date: Fri, 5 Jul 2019 12:12:50 +0100 Subject: [PATCH 1/2] Fix compilation errors in exhaustive test --- .../xla/tests/exhaustive_op_test_utils.cc | 8 ++-- .../xla/tests/exhaustive_op_test_utils.h | 42 ++++++++++--------- .../xla/tests/exhaustive_unary_test.cc | 3 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.cc b/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.cc index 465da47faeb..02273d7debd 100644 --- a/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.cc +++ b/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.cc @@ -58,19 +58,19 @@ ExhaustiveOpTestBase::CreateExhaustiveF32Ranges() { namespace { ExhaustiveOpTestBase::ErrorSpec DefaultF64SpecGenerator(float) { - return ExhaustiveOpTestBase::ErrorSpec{0.0001, 0.0001}; + return ExhaustiveOpTestBase::ErrorSpec(0.0001, 0.0001); } ExhaustiveOpTestBase::ErrorSpec DefaultF32SpecGenerator(float) { - return ExhaustiveOpTestBase::ErrorSpec{0.0001, 0.0001}; + return ExhaustiveOpTestBase::ErrorSpec(0.0001, 0.0001); } ExhaustiveOpTestBase::ErrorSpec DefaultF16SpecGenerator(float) { - return ExhaustiveOpTestBase::ErrorSpec{0.001, 0.001}; + return ExhaustiveOpTestBase::ErrorSpec(0.001, 0.001); } ExhaustiveOpTestBase::ErrorSpec DefaultBF16SpecGenerator(float) { - return ExhaustiveOpTestBase::ErrorSpec{0.002, 0.02}; + return ExhaustiveOpTestBase::ErrorSpec(0.002, 0.02); } } // namespace diff --git a/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h b/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h index 3df4de295e3..b6db554cdaa 100644 --- a/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h +++ b/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h @@ -30,6 +30,26 @@ limitations under the License. namespace xla { using Eigen::half; +namespace int_type { +template +struct IntegralTypeWithByteWidth {}; + +template <> +struct IntegralTypeWithByteWidth<2> { + using type = uint16; +}; + +template <> +struct IntegralTypeWithByteWidth<4> { + using type = uint32; +}; + +template <> +struct IntegralTypeWithByteWidth<8> { + using type = uint64; +}; +} + class ExhaustiveOpTestBase : public ClientLibraryTestBase { public: struct ErrorSpec { @@ -41,6 +61,8 @@ class ExhaustiveOpTestBase : public ClientLibraryTestBase { // spec; this only covers the case when both `expected` and `actual` are // equal to 0. bool strict_signed_zeros = false; + + ErrorSpec(float a, float r) : abs_err(a), rel_err(r) {} }; // `ty` is the primitive type being tested. @@ -140,24 +162,6 @@ class ExhaustiveOpTestBase : public ClientLibraryTestBase { } } - template - struct IntegralTypeWithByteWidth {}; - - template <> - struct IntegralTypeWithByteWidth<2> { - using type = uint16; - }; - - template <> - struct IntegralTypeWithByteWidth<4> { - using type = uint32; - }; - - template <> - struct IntegralTypeWithByteWidth<8> { - using type = uint64; - }; - // Converts part or all bits in an uint64 to the value of the floating point // data type being tested. // @@ -170,7 +174,7 @@ class ExhaustiveOpTestBase : public ClientLibraryTestBase { // T is the type of the floating value represented by the `bits`. template T ConvertValue(uint64 bits) { - using I = typename IntegralTypeWithByteWidth::type; + using I = typename int_type::IntegralTypeWithByteWidth::type; I used_bits = static_cast(bits); return BitCast(used_bits); } diff --git a/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc b/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc index 36584b43c59..761d84c2a8e 100644 --- a/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc +++ b/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc @@ -369,7 +369,8 @@ class Exhaustive32BitOrLessUnaryTest // type being tested. template void FillInput(Literal* input_literal) { - using IntegralT = typename IntegralTypeWithByteWidth::type; + using IntegralT = + typename int_type::IntegralTypeWithByteWidth::type; int64 input_size = input_literal->element_count(); int64 begin, end; std::tie(begin, end) = std::get<1>(GetParam()); From 1ba4fd12134334aff10efc6a49930e3cee25f8c1 Mon Sep 17 00:00:00 2001 From: David Norman Date: Tue, 9 Jul 2019 07:25:32 +0100 Subject: [PATCH 2/2] Change the namespace int_type -> test_util --- tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h | 4 ++-- tensorflow/compiler/xla/tests/exhaustive_unary_test.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h b/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h index b6db554cdaa..212c0e6f522 100644 --- a/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h +++ b/tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h @@ -30,7 +30,7 @@ limitations under the License. namespace xla { using Eigen::half; -namespace int_type { +namespace test_util { template struct IntegralTypeWithByteWidth {}; @@ -174,7 +174,7 @@ class ExhaustiveOpTestBase : public ClientLibraryTestBase { // T is the type of the floating value represented by the `bits`. template T ConvertValue(uint64 bits) { - using I = typename int_type::IntegralTypeWithByteWidth::type; + using I = typename test_util::IntegralTypeWithByteWidth::type; I used_bits = static_cast(bits); return BitCast(used_bits); } diff --git a/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc b/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc index 761d84c2a8e..f028e0aee48 100644 --- a/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc +++ b/tensorflow/compiler/xla/tests/exhaustive_unary_test.cc @@ -370,7 +370,7 @@ class Exhaustive32BitOrLessUnaryTest template void FillInput(Literal* input_literal) { using IntegralT = - typename int_type::IntegralTypeWithByteWidth::type; + typename test_util::IntegralTypeWithByteWidth::type; int64 input_size = input_literal->element_count(); int64 begin, end; std::tie(begin, end) = std::get<1>(GetParam());