Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XLA] Fix compilation errors in exhaustive test #30434

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions tensorflow/compiler/xla/tests/exhaustive_op_test_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 23 additions & 19 deletions tensorflow/compiler/xla/tests/exhaustive_op_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ limitations under the License.
namespace xla {
using Eigen::half;

namespace test_util {
template <int N>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After we remove the use of this template in the exhaustive_unary_test.cc, would it be better to put this back to the class as "private" or use anonymous namespace here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still cannot have a specialization of a template class embedded inside a class in official c++. so it has to remain in a separate namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although it could be an anonymous namespace as you say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above - i don't think that IntegralT can be removed from the FillInput function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my reply above - I think we should be able to remove IntegralT from FillInput.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that IntegralT is not int64, but we can still replace IntegralT with int64 here, because ConvertAndReplaceKnownIncorrectValueWith will ensure that we will retrieve the right bits from input_val. I am approving this and will make the change I am talking about later.

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 {
Expand All @@ -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.
Expand Down Expand Up @@ -140,24 +162,6 @@ class ExhaustiveOpTestBase : public ClientLibraryTestBase {
}
}

template <int N>
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.
//
Expand All @@ -170,7 +174,7 @@ class ExhaustiveOpTestBase : public ClientLibraryTestBase {
// T is the type of the floating value represented by the `bits`.
template <typename T>
T ConvertValue(uint64 bits) {
using I = typename IntegralTypeWithByteWidth<sizeof(T)>::type;
using I = typename test_util::IntegralTypeWithByteWidth<sizeof(T)>::type;
I used_bits = static_cast<I>(bits);
return BitCast<T>(used_bits);
}
Expand Down
3 changes: 2 additions & 1 deletion tensorflow/compiler/xla/tests/exhaustive_unary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ class Exhaustive32BitOrLessUnaryTest
// type being tested.
template <typename T>
void FillInput(Literal* input_literal) {
using IntegralT = typename IntegralTypeWithByteWidth<sizeof(T)>::type;
using IntegralT =
typename test_util::IntegralTypeWithByteWidth<sizeof(T)>::type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that this is not use, we can replace the use of IntegralT in the routine with int64.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this is true? IntegralT is a type which depends on the template type T. This does vary from use to use of FillInput.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, IntegralT was left here while it should be remove after I added ConvertAndReplaceKnownIncorrectValueWith.

If input_val is a int64, ConvertAndReplaceKnownIncorrectValueWith will convert it to IntegralT.

  IntegralT input_val = i + begin;
  input_arr[i] = ConvertAndReplaceKnownIncorrectValueWith<T>(input_val, 0);

int64 input_size = input_literal->element_count();
int64 begin, end;
std::tie(begin, end) = std::get<1>(GetParam());
Expand Down