diff options
Diffstat (limited to 'tensorflow/compiler/xla/service/hlo_evaluator_test.cc')
-rw-r--r-- | tensorflow/compiler/xla/service/hlo_evaluator_test.cc | 395 |
1 files changed, 202 insertions, 193 deletions
diff --git a/tensorflow/compiler/xla/service/hlo_evaluator_test.cc b/tensorflow/compiler/xla/service/hlo_evaluator_test.cc index 42770d848a..5f575b24a1 100644 --- a/tensorflow/compiler/xla/service/hlo_evaluator_test.cc +++ b/tensorflow/compiler/xla/service/hlo_evaluator_test.cc @@ -22,7 +22,7 @@ limitations under the License. #include <vector> #include "tensorflow/compiler/xla/client/xla_client/xla_builder.h" -#include "tensorflow/compiler/xla/literal_util.h" +#include "tensorflow/compiler/xla/literal.h" #include "tensorflow/compiler/xla/reference_util.h" #include "tensorflow/compiler/xla/service/hlo_computation.h" #include "tensorflow/compiler/xla/service/hlo_element_type_converter.h" @@ -112,9 +112,9 @@ class HloEvaluatorTest : public ::testing::WithParamInterface<bool>, // Verifies that HloEvaluator evaluates a HLO instruction that performs clamp // with 3 operands. TEST_P(HloEvaluatorTest, DoesClamp) { - auto low = Literal::CreateR2<float>({{0.f, 2.f}, {2.f, 4.f}}); - auto value = Literal::CreateR2<float>({{0.f, 5.f}, {0.f, 4.f}}); - auto high = Literal::CreateR2<float>({{2.f, 4.f}, {4.f, 4.f}}); + auto low = LiteralUtil::CreateR2<float>({{0.f, 2.f}, {2.f, 4.f}}); + auto value = LiteralUtil::CreateR2<float>({{0.f, 5.f}, {0.f, 4.f}}); + auto high = LiteralUtil::CreateR2<float>({{2.f, 4.f}, {4.f, 4.f}}); Shape shape = low->shape(); HloComputation::Builder b(TestName()); @@ -127,15 +127,15 @@ TEST_P(HloEvaluatorTest, DoesClamp) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({{0, 4}, {2, 4}}); + auto expected = LiteralUtil::CreateR2<float>({{0, 4}, {2, 4}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } TEST_P(HloEvaluatorTest, DISABLED_DoesClampSpecialBroadcast) { - auto low = Literal::CreateR0<float>(0.f); - auto value = Literal::CreateR2<float>({{-1.f, 0.f}, {1.f, 2.f}}); - auto high = Literal::CreateR0<float>(1.f); + auto low = LiteralUtil::CreateR0<float>(0.f); + auto value = LiteralUtil::CreateR2<float>({{-1.f, 0.f}, {1.f, 2.f}}); + auto high = LiteralUtil::CreateR0<float>(1.f); Shape shape = value->shape(); HloComputation::Builder b(TestName()); @@ -148,7 +148,7 @@ TEST_P(HloEvaluatorTest, DISABLED_DoesClampSpecialBroadcast) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({{0, 0}, {1, 1}}); + auto expected = LiteralUtil::CreateR2<float>({{0, 0}, {1, 1}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -156,9 +156,9 @@ TEST_P(HloEvaluatorTest, DISABLED_DoesClampSpecialBroadcast) { // Verifies that HloEvaluator evaluates a HLO instruction that performs select // with 3 operands. TEST_P(HloEvaluatorTest, DoesSelect) { - auto pred = Literal::CreateR2<bool>({{true, false}, {false, true}}); - auto on_true = Literal::CreateR2<float>({{2.f, 4.f}, {4.f, 4.f}}); - auto on_false = Literal::CreateR2<float>({{0.f, 5.f}, {0.f, 4.f}}); + auto pred = LiteralUtil::CreateR2<bool>({{true, false}, {false, true}}); + auto on_true = LiteralUtil::CreateR2<float>({{2.f, 4.f}, {4.f, 4.f}}); + auto on_false = LiteralUtil::CreateR2<float>({{0.f, 5.f}, {0.f, 4.f}}); Shape shape = on_true->shape(); HloComputation::Builder b(TestName()); @@ -173,7 +173,7 @@ TEST_P(HloEvaluatorTest, DoesSelect) { std::unique_ptr<Literal> result = Evaluate({}); - auto expected = Literal::CreateR2<float>({{2, 5}, {0, 4}}); + auto expected = LiteralUtil::CreateR2<float>({{2, 5}, {0, 4}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -181,46 +181,46 @@ TEST_P(HloEvaluatorTest, DoesSelect) { // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise addition with 2 operands. TEST_P(HloEvaluatorTest, DoesAdd) { - auto lhs = Literal::CreateR2<int64>({{1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int64>({{2, 4}, {4, 4}}); - auto expected = Literal::CreateR2<int64>({{3, 4}, {-96, 8}}); + auto lhs = LiteralUtil::CreateR2<int64>({{1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int64>({{2, 4}, {4, 4}}); + auto expected = LiteralUtil::CreateR2<int64>({{3, 4}, {-96, 8}}); TestBinaryOp(HloOpcode::kAdd, std::move(expected), std::move(lhs), std::move(rhs)); } // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise and with 2 operands. TEST_P(HloEvaluatorTest, DoesAnd) { - auto lhs = Literal::CreateR2<int64>({{1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int64>({{2, 4}, {4, 4}}); - auto expected = Literal::CreateR2<int64>({{0, 0}, {4, 4}}); + auto lhs = LiteralUtil::CreateR2<int64>({{1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int64>({{2, 4}, {4, 4}}); + auto expected = LiteralUtil::CreateR2<int64>({{0, 0}, {4, 4}}); TestBinaryOp(HloOpcode::kAnd, std::move(expected), std::move(lhs), std::move(rhs)); } // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise or with 2 operands. TEST_P(HloEvaluatorTest, DoesOr) { - auto lhs = Literal::CreateR2<int64>({{1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int64>({{2, 4}, {4, 4}}); - auto expected = Literal::CreateR2<int64>({{3, 4}, {-100, 4}}); + auto lhs = LiteralUtil::CreateR2<int64>({{1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int64>({{2, 4}, {4, 4}}); + auto expected = LiteralUtil::CreateR2<int64>({{3, 4}, {-100, 4}}); TestBinaryOp(HloOpcode::kOr, std::move(expected), std::move(lhs), std::move(rhs)); } // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise or with 2 operands. TEST_P(HloEvaluatorTest, DoesXor) { - auto lhs = Literal::CreateR2<int64>({{1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int64>({{2, 4}, {4, 4}}); - auto expected = Literal::CreateR2<int64>({{3, 4}, {-104, 0}}); + auto lhs = LiteralUtil::CreateR2<int64>({{1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int64>({{2, 4}, {4, 4}}); + auto expected = LiteralUtil::CreateR2<int64>({{3, 4}, {-104, 0}}); TestBinaryOp(HloOpcode::kXor, std::move(expected), std::move(lhs), std::move(rhs)); } // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise multiply with 2 operands. TEST_P(HloEvaluatorTest, DoesMultiply) { - auto lhs = Literal::CreateR2<int32>({{-1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int32>( + auto lhs = LiteralUtil::CreateR2<int32>({{-1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int32>( {{std::numeric_limits<int32>::min(), 4}, {4, 4}}); - auto expected = Literal::CreateR2<int32>( + auto expected = LiteralUtil::CreateR2<int32>( {{std::numeric_limits<int32>::min(), 0}, {-400, 16}}); TestBinaryOp(HloOpcode::kMultiply, std::move(expected), std::move(lhs), std::move(rhs)); @@ -228,17 +228,17 @@ TEST_P(HloEvaluatorTest, DoesMultiply) { // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise divide with 2 operands. TEST_P(HloEvaluatorTest, DoesDivideInt64) { - auto lhs = Literal::CreateR2<int64>({{1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int64>({{2, 4}, {4, 4}}); - auto expected = Literal::CreateR2<int64>({{0, 0}, {-25, 1}}); + auto lhs = LiteralUtil::CreateR2<int64>({{1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int64>({{2, 4}, {4, 4}}); + auto expected = LiteralUtil::CreateR2<int64>({{0, 0}, {-25, 1}}); TestBinaryOp(HloOpcode::kDivide, std::move(expected), std::move(lhs), std::move(rhs)); } TEST_P(HloEvaluatorTest, DoesDivideDouble) { - auto lhs = Literal::CreateR2<double>({{1.0, 0.0}, {-100.0, 4.0}}); - auto rhs = Literal::CreateR2<double>({{2.2, 4.0}, {4.0, 4.0}}); + auto lhs = LiteralUtil::CreateR2<double>({{1.0, 0.0}, {-100.0, 4.0}}); + auto rhs = LiteralUtil::CreateR2<double>({{2.2, 4.0}, {4.0, 4.0}}); auto expected = - Literal::CreateR2<double>({{0.45454545454545453, 0}, {-25, 1}}); + LiteralUtil::CreateR2<double>({{0.45454545454545453, 0}, {-25, 1}}); TestBinaryOp(HloOpcode::kDivide, std::move(expected), std::move(lhs), std::move(rhs)); } @@ -246,54 +246,54 @@ TEST_P(HloEvaluatorTest, DoesDivideDouble) { // Verifies that HloEvaluator evaluates a HLO instruction that performs // element-wise abs op with 1 operand. TEST_P(HloEvaluatorTest, DoesAbsR2) { - auto operand = Literal::CreateR2<int64>({{1, -20}, {-100, 4}}); - auto expected = Literal::CreateR2<int64>({{1, 20}, {100, 4}}); + auto operand = LiteralUtil::CreateR2<int64>({{1, -20}, {-100, 4}}); + auto expected = LiteralUtil::CreateR2<int64>({{1, 20}, {100, 4}}); TestUnaryOp(HloOpcode::kAbs, std::move(expected), std::move(operand)); } TEST_P(HloEvaluatorTest, DoesAbsR0) { - auto operand = Literal::CreateR0<float>(-1.0f); - auto expected = Literal::CreateR0<float>(1.0f); + auto operand = LiteralUtil::CreateR0<float>(-1.0f); + auto expected = LiteralUtil::CreateR0<float>(1.0f); TestUnaryOp(HloOpcode::kAbs, std::move(expected), std::move(operand)); } TEST_P(HloEvaluatorTest, DoesAbsR1WithZeroSize) { - auto operand = Literal::CreateR1<float>({}); - auto expected = Literal::CreateR1<float>({}); + auto operand = LiteralUtil::CreateR1<float>({}); + auto expected = LiteralUtil::CreateR1<float>({}); TestUnaryOp(HloOpcode::kAbs, std::move(expected), std::move(operand)); } TEST_P(HloEvaluatorTest, DoesNegateR2) { - auto operand = Literal::CreateR2<int32>( + auto operand = LiteralUtil::CreateR2<int32>( {{0, std::numeric_limits<int32>::min()}, {-1, 4}}); - auto expected = - Literal::CreateR2<int32>({{0, std::numeric_limits<int>::min()}, {1, -4}}); + auto expected = LiteralUtil::CreateR2<int32>( + {{0, std::numeric_limits<int>::min()}, {1, -4}}); TestUnaryOp(HloOpcode::kNegate, std::move(expected), std::move(operand)); } TEST_P(HloEvaluatorTest, DoesCosR2) { - auto operand = Literal::CreateR2<float>({{0, M_PI}, {-M_PI, 2 * M_PI}}); - auto expected = Literal::CreateR2<float>({{1, -1}, {-1, 1}}); + auto operand = LiteralUtil::CreateR2<float>({{0, M_PI}, {-M_PI, 2 * M_PI}}); + auto expected = LiteralUtil::CreateR2<float>({{1, -1}, {-1, 1}}); TestUnaryOp(HloOpcode::kCos, std::move(expected), std::move(operand), use_bfloat16_ ? 0.031250 : 9.5367431640625E-7); } TEST_P(HloEvaluatorTest, DoesSinR2) { - auto operand = Literal::CreateR2<float>({{0, M_PI}, {-M_PI, 2 * M_PI}}); - auto expected = Literal::CreateR2<float>({{0, 0}, {0, 0}}); + auto operand = LiteralUtil::CreateR2<float>({{0, M_PI}, {-M_PI, 2 * M_PI}}); + auto expected = LiteralUtil::CreateR2<float>({{0, 0}, {0, 0}}); TestUnaryOp(HloOpcode::kSin, std::move(expected), std::move(operand), use_bfloat16_ ? 0.031250 : 9.5367431640625E-7); } TEST_P(HloEvaluatorTest, DoesNotR2) { auto operand = - Literal::CreateR2<int32>({{0, std::numeric_limits<int>::min()}, - {-1, std::numeric_limits<int>::max()}}); + LiteralUtil::CreateR2<int32>({{0, std::numeric_limits<int>::min()}, + {-1, std::numeric_limits<int>::max()}}); auto expected = - Literal::CreateR2<int32>({{-1, std::numeric_limits<int>::max()}, - {0, std::numeric_limits<int>::min()}}); + LiteralUtil::CreateR2<int32>({{-1, std::numeric_limits<int>::max()}, + {0, std::numeric_limits<int>::min()}}); TestUnaryOp(HloOpcode::kNot, std::move(expected), std::move(operand)); } // Verifies that HloEvaluator evaluates a HLO Computation with non-parameter nor // constant operands. TEST_P(HloEvaluatorTest, DoesTraverseInstructions) { - auto lhs = Literal::CreateR2<int64>({{1, 0}, {-100, 4}}); - auto rhs = Literal::CreateR2<int64>({{2, 4}, {4, 4}}); - auto rhs2 = Literal::CreateR2<int64>({{1, -20}, {-100, 4}}); + auto lhs = LiteralUtil::CreateR2<int64>({{1, 0}, {-100, 4}}); + auto rhs = LiteralUtil::CreateR2<int64>({{2, 4}, {4, 4}}); + auto rhs2 = LiteralUtil::CreateR2<int64>({{1, -20}, {-100, 4}}); std::vector<const Literal*> args = {lhs.get(), rhs.get(), rhs2.get()}; Shape shape = ShapeUtil::MakeShape(S64, {2, 2}); @@ -314,7 +314,7 @@ TEST_P(HloEvaluatorTest, DoesTraverseInstructions) { std::unique_ptr<Literal> result = Evaluate(args); - auto expected = Literal::CreateR2<int64>({{4, -16}, {-196, 12}}); + auto expected = LiteralUtil::CreateR2<int64>({{4, -16}, {-196, 12}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -324,7 +324,7 @@ TEST_P(HloEvaluatorTest, DoesReshape) { HloComputation::Builder b(TestName()); const int64 dimensions[] = {11, 8, 7, 5, 9}; TF_ASSERT_OK_AND_ASSIGN(auto literal, - Literal::CreateRandomLiteral<F32>( + LiteralUtil::CreateRandomLiteral<F32>( ShapeUtil::MakeShape(F32, dimensions), 0.0, 1.0)); auto literal_clone = literal->CloneToUnique(); HloInstruction* literal_instruction = @@ -349,8 +349,8 @@ TEST_P(HloEvaluatorTest, DoesReshape) { // Verifies Broadcast operation is correctly evaluated. TEST_P(HloEvaluatorTest, DoesBroadcast) { HloComputation::Builder b(TestName()); - auto input_literal = Literal::CreateR2<int32>({{1, 2}, {3, 4}, {5, 6}}); - auto output_literal = Literal::CreateR3<int32>( + auto input_literal = LiteralUtil::CreateR2<int32>({{1, 2}, {3, 4}, {5, 6}}); + auto output_literal = LiteralUtil::CreateR3<int32>( {{{1, 2}, {3, 4}, {5, 6}}, {{1, 2}, {3, 4}, {5, 6}}}); HloInstruction* literal_instruction = b.AddInstruction( HloInstruction::CreateConstant(std::move(input_literal))); @@ -365,8 +365,8 @@ TEST_P(HloEvaluatorTest, DoesBroadcast) { TEST_P(HloEvaluatorTest, DoesBroadcastScalar) { HloComputation::Builder b(TestName()); - auto input_literal = Literal::CreateR0<int32>(111); - auto output_literal = Literal::CreateR2<int32>( + auto input_literal = LiteralUtil::CreateR0<int32>(111); + auto output_literal = LiteralUtil::CreateR2<int32>( {{111, 111}, {111, 111}, {111, 111}, {111, 111}, {111, 111}, {111, 111}}); HloInstruction* literal_instruction = b.AddInstruction( @@ -386,9 +386,9 @@ TEST_P(HloEvaluatorTest, DoesConcatenateSimple) { HloComputation::Builder b(TestName()); HloInstruction* operand1 = b.AddInstruction(HloInstruction::CreateConstant( - Literal::CreateR2<int64>({{-1, -2}, {100, 200}}))); + LiteralUtil::CreateR2<int64>({{-1, -2}, {100, 200}}))); HloInstruction* operand2 = b.AddInstruction(HloInstruction::CreateConstant( - Literal::CreateR2<int64>({{-2, -3}, {-100, -200}}))); + LiteralUtil::CreateR2<int64>({{-2, -3}, {-100, -200}}))); std::vector<HloInstruction*> operands = {operand1, operand2}; @@ -399,8 +399,8 @@ TEST_P(HloEvaluatorTest, DoesConcatenateSimple) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = - Literal::CreateR2<int64>({{-1, -2}, {100, 200}, {-2, -3}, {-100, -200}}); + auto expected = LiteralUtil::CreateR2<int64>( + {{-1, -2}, {100, 200}, {-2, -3}, {-100, -200}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -408,9 +408,9 @@ TEST_P(HloEvaluatorTest, ConcatenateHandlesShapeWithZeroElement) { HloComputation::Builder b(TestName()); HloInstruction* operand1 = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int64>({100, 200}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int64>({100, 200}))); HloInstruction* operand2 = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int64>({}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int64>({}))); std::vector<HloInstruction*> operands = {operand1, operand2}; @@ -421,16 +421,16 @@ TEST_P(HloEvaluatorTest, ConcatenateHandlesShapeWithZeroElement) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR1<int64>({100, 200}); + auto expected = LiteralUtil::CreateR1<int64>({100, 200}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } TEST_P(HloEvaluatorTest, ConvertWithSameLayout) { HloComputation::Builder b(TestName()); - auto input_literal = Literal::CreateR2<int32>({{1, 2}, {3, 4}, {5, 6}}); + auto input_literal = LiteralUtil::CreateR2<int32>({{1, 2}, {3, 4}, {5, 6}}); auto expected = - Literal::CreateR2<float>({{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}}); + LiteralUtil::CreateR2<float>({{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}}); ASSERT_TRUE(LayoutUtil::LayoutsInShapesEqual(input_literal->shape(), expected->shape())); @@ -447,9 +447,9 @@ TEST_P(HloEvaluatorTest, ConvertWithSameLayout) { TEST_P(HloEvaluatorTest, ConvertWithDifferentLayout) { HloComputation::Builder b(TestName()); - auto input_literal = Literal::CreateR2WithLayout<int32>( + auto input_literal = LiteralUtil::CreateR2WithLayout<int32>( {{1, 2}, {3, 4}, {5, 6}}, LayoutUtil::MakeLayout({0, 1})); - auto expected = Literal::CreateR2WithLayout<float>( + auto expected = LiteralUtil::CreateR2WithLayout<float>( {{1.0, 2.0}, {3.0, 4.0}, {5.0, 6.0}}, LayoutUtil::MakeLayout({1, 0})); ASSERT_FALSE(LayoutUtil::LayoutsInShapesEqual(input_literal->shape(), expected->shape())); @@ -478,13 +478,13 @@ PaddingConfig CreatePaddingConfig( } TEST_P(HloEvaluatorTest, Pad2DIntegerArrayWithZeroDimension) { - auto operand = Literal::CreateR2<int32>({{}, {}}); + auto operand = LiteralUtil::CreateR2<int32>({{}, {}}); HloComputation::Builder b(TestName()); auto operand_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(operand))); constexpr int32 kPadValue = 10; - auto pad_value = Literal::CreateR0<int32>(kPadValue); + auto pad_value = LiteralUtil::CreateR0<int32>(kPadValue); auto padding_value_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(pad_value))); @@ -496,7 +496,7 @@ TEST_P(HloEvaluatorTest, Pad2DIntegerArrayWithZeroDimension) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<int32>( + auto expected = LiteralUtil::CreateR2<int32>( {{10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); @@ -506,11 +506,11 @@ TEST_P(HloEvaluatorTest, Pad4DFloatArrayWithInteriorPadding) { HloComputation::Builder b(TestName()); Array4D<float> input_array(3, 2, 1, 1, {1, 2, 3, 4, 5, 6}); - auto input = Literal::CreateR4FromArray4D<float>(input_array); + auto input = LiteralUtil::CreateR4FromArray4D<float>(input_array); HloInstruction* input_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(input))); constexpr float kPadValue = 1.5; - auto pad_value = Literal::CreateR0<float>(kPadValue); + auto pad_value = LiteralUtil::CreateR0<float>(kPadValue); HloInstruction* pad_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(pad_value))); @@ -532,7 +532,7 @@ TEST_P(HloEvaluatorTest, Pad4DFloatArrayWithInteriorPadding) { (*expected_array)(7, 0, 0, 0) = 5.0f; (*expected_array)(7, 2, 0, 0) = 6.0f; - auto expected = Literal::CreateR4FromArray4D<float>(*expected_array); + auto expected = LiteralUtil::CreateR4FromArray4D<float>(*expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -549,12 +549,12 @@ TEST_P(HloEvaluatorTest, NegativePadding2D) { // } auto input_array = MakeUnique<Array2D<float>>(4, 3); input_array->FillUnique(1.0f); - auto input = Literal::CreateR2FromArray2D<float>(*input_array); + auto input = LiteralUtil::CreateR2FromArray2D<float>(*input_array); HloInstruction* input_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(input))); auto pad_value_instruction = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(2.718f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(2.718f))); auto r2_padding_on_dim0_dim1 = CreatePaddingConfig({{{-1, -2, 0}}, {{-2, 4, 0}}}); @@ -574,7 +574,7 @@ TEST_P(HloEvaluatorTest, NegativePadding2D) { (*expected_array)(0, 2) = 2.718f; (*expected_array)(0, 3) = 2.718f; (*expected_array)(0, 4) = 2.718f; - auto expected = Literal::CreateR2FromArray2D<float>(*expected_array); + auto expected = LiteralUtil::CreateR2FromArray2D<float>(*expected_array); EXPECT_TRUE(LiteralTestUtil::Near(*expected, *result, ErrorSpec(0.031250))); } @@ -590,12 +590,12 @@ TEST_P(HloEvaluatorTest, NegativeAndInteriorPadding2D) { // } auto input_array = MakeUnique<Array2D<float>>(4, 3); input_array->FillUnique(1.0f); - auto input = Literal::CreateR2FromArray2D<float>(*input_array); + auto input = LiteralUtil::CreateR2FromArray2D<float>(*input_array); HloInstruction* input_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(input))); auto pad_value_instruction = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(2.718f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(2.718f))); PaddingConfig padding_config = MakeNoPaddingConfig(2); @@ -613,7 +613,7 @@ TEST_P(HloEvaluatorTest, NegativeAndInteriorPadding2D) { std::unique_ptr<Literal> result = Evaluate(); auto expected_array = MakeUnique<Array2D<float>>(0, 9); - auto expected = Literal::CreateR2FromArray2D<float>(*expected_array); + auto expected = LiteralUtil::CreateR2FromArray2D<float>(*expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -630,13 +630,13 @@ TEST_P(HloEvaluatorTest, DotRank2AndRank1) { // } auto lhs_array = MakeUnique<Array2D<float>>(4, 1); lhs_array->FillUnique(1.0f); - auto lhs_literal = Literal::CreateR2FromArray2D<float>(*lhs_array); + auto lhs_literal = LiteralUtil::CreateR2FromArray2D<float>(*lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); // rhs: // f32[2] { 1, 2 }, - auto rhs_literal = Literal::CreateR2<float>({{1, 2}}); + auto rhs_literal = LiteralUtil::CreateR2<float>({{1, 2}}); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -658,7 +658,7 @@ TEST_P(HloEvaluatorTest, DotRank2AndRank1) { {4.f, 8.f}, }); // clang-format on - auto expected = Literal::CreateR2FromArray2D<float>(expected_array); + auto expected = LiteralUtil::CreateR2FromArray2D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -669,7 +669,7 @@ TEST_P(HloEvaluatorTest, DotRank1AndRank2) { // lhs: // f32[3] // { 1, 2, 3 }, - auto lhs_literal = Literal::CreateR1<float>({1, 2, 3}); + auto lhs_literal = LiteralUtil::CreateR1<float>({1, 2, 3}); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); @@ -681,7 +681,7 @@ TEST_P(HloEvaluatorTest, DotRank1AndRank2) { // } auto rhs_array = MakeUnique<Array2D<float>>(3, 2); rhs_array->FillUnique(1.0f); - auto rhs_literal = Literal::CreateR2FromArray2D<float>(*rhs_array); + auto rhs_literal = LiteralUtil::CreateR2FromArray2D<float>(*rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -695,7 +695,7 @@ TEST_P(HloEvaluatorTest, DotRank1AndRank2) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR1<float>({22.f, 28.f}); + auto expected = LiteralUtil::CreateR1<float>({22.f, 28.f}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -712,7 +712,7 @@ TEST_P(HloEvaluatorTest, DotRank2AndRank2) { // } auto lhs_array = MakeUnique<Array2D<float>>(4, 3); lhs_array->FillUnique(1.0f); - auto lhs_literal = Literal::CreateR2FromArray2D<float>(*lhs_array); + auto lhs_literal = LiteralUtil::CreateR2FromArray2D<float>(*lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); @@ -724,7 +724,7 @@ TEST_P(HloEvaluatorTest, DotRank2AndRank2) { // } auto rhs_array = MakeUnique<Array2D<float>>(3, 2); rhs_array->FillUnique(1.0f); - auto rhs_literal = Literal::CreateR2FromArray2D<float>(*rhs_array); + auto rhs_literal = LiteralUtil::CreateR2FromArray2D<float>(*rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -744,7 +744,7 @@ TEST_P(HloEvaluatorTest, DotRank2AndRank2) { {94.f, 124.f}, {130.f, 172.f}, }); - auto expected = Literal::CreateR2FromArray2D<float>(expected_array); + auto expected = LiteralUtil::CreateR2FromArray2D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -753,12 +753,12 @@ TEST_P(HloEvaluatorTest, SimpleConv1D) { HloComputation::Builder b(TestName()); Array3D<float> lhs_array = {{{1, 2, 3}}}; - auto lhs_literal = Literal::CreateR3FromArray3D<float>(lhs_array); + auto lhs_literal = LiteralUtil::CreateR3FromArray3D<float>(lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); Array3D<float> rhs_array = {{{3.f, 4.f}}}; - auto rhs_literal = Literal::CreateR3FromArray3D<float>(rhs_array); + auto rhs_literal = LiteralUtil::CreateR3FromArray3D<float>(rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -792,7 +792,7 @@ TEST_P(HloEvaluatorTest, SimpleConv1D) { std::unique_ptr<Literal> result = Evaluate(); Array3D<float> expected_array = {{{11.f, 18.f, 9.f}}}; - auto expected = Literal::CreateR3FromArray3D<float>(expected_array); + auto expected = LiteralUtil::CreateR3FromArray3D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -809,7 +809,7 @@ TEST_P(HloEvaluatorTest, Simple4x4Conv2DWith2x2Kernel) { {13, 14, 15, 16}, })); // clang-format on - auto lhs_literal = Literal::CreateR4FromArray4D<float>(lhs_array); + auto lhs_literal = LiteralUtil::CreateR4FromArray4D<float>(lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); @@ -820,7 +820,7 @@ TEST_P(HloEvaluatorTest, Simple4x4Conv2DWith2x2Kernel) { {7, 8}, })); // clang-format on - auto rhs_literal = Literal::CreateR4FromArray4D<float>(rhs_array); + auto rhs_literal = LiteralUtil::CreateR4FromArray4D<float>(rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -854,7 +854,7 @@ TEST_P(HloEvaluatorTest, Simple4x4Conv2DWith2x2Kernel) { {149, 160, 171, 80}, })); // clang-format on - auto expected = Literal::CreateR4FromArray4D<float>(expected_array); + auto expected = LiteralUtil::CreateR4FromArray4D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -884,11 +884,11 @@ TEST_P(HloEvaluatorTest, Conv2DGeneralDimensionsReversed) { }}); // clang-format on - auto lhs_literal = Literal::CreateR4FromArray4D<float>(input); + auto lhs_literal = LiteralUtil::CreateR4FromArray4D<float>(input); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); - auto rhs_literal = Literal::CreateR4FromArray4D<float>(weight); + auto rhs_literal = LiteralUtil::CreateR4FromArray4D<float>(weight); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); rhs_instruction = b.AddInstruction(HloInstruction::CreateReverse( @@ -933,7 +933,7 @@ TEST_P(HloEvaluatorTest, Conv2DGeneralDimensionsReversed) { Array4D<float> expected_array({{{{2514, 2685}}}}); Array4D<float> expected_array_bf16({{{{2512, 2672}}}}); // clang-format on - auto expected = Literal::CreateR4FromArray4D<float>( + auto expected = LiteralUtil::CreateR4FromArray4D<float>( use_bfloat16_ ? expected_array_bf16 : expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); @@ -964,11 +964,11 @@ TEST_P(HloEvaluatorTest, Conv2DGeneralDimensions) { }}); // clang-format on - auto lhs_literal = Literal::CreateR4FromArray4D<float>(input); + auto lhs_literal = LiteralUtil::CreateR4FromArray4D<float>(input); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); - auto rhs_literal = Literal::CreateR4FromArray4D<float>(weight); + auto rhs_literal = LiteralUtil::CreateR4FromArray4D<float>(weight); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -1010,7 +1010,7 @@ TEST_P(HloEvaluatorTest, Conv2DGeneralDimensions) { Array4D<float> expected_array({{{{2514, 2685}}}}); Array4D<float> expected_array_bf16({{{{2512, 2672}}}}); // clang-format on - auto expected = Literal::CreateR4FromArray4D<float>( + auto expected = LiteralUtil::CreateR4FromArray4D<float>( use_bfloat16_ ? expected_array_bf16 : expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); @@ -1028,7 +1028,7 @@ TEST_P(HloEvaluatorTest, DilatedBaseConv2DWithHighPadding) { {13, 14, 15, 16}, })); // clang-format on - auto lhs_literal = Literal::CreateR4FromArray4D<float>(lhs_array); + auto lhs_literal = LiteralUtil::CreateR4FromArray4D<float>(lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); @@ -1039,7 +1039,7 @@ TEST_P(HloEvaluatorTest, DilatedBaseConv2DWithHighPadding) { {7, 8}, })); // clang-format on - auto rhs_literal = Literal::CreateR4FromArray4D<float>(rhs_array); + auto rhs_literal = LiteralUtil::CreateR4FromArray4D<float>(rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -1074,7 +1074,7 @@ TEST_P(HloEvaluatorTest, DilatedBaseConv2DWithHighPadding) { {91, 112, 98, 120, 105, 128, 112}, {65, 84, 70, 90, 75, 96, 80}, })); - auto expected = Literal::CreateR4FromArray4D<float>(expected_array); + auto expected = LiteralUtil::CreateR4FromArray4D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -1091,7 +1091,7 @@ TEST_P(HloEvaluatorTest, DilatedBaseConv2DWithLowAndHighPadding) { {13, 14, 15, 16}, })); // clang-format on - auto lhs_literal = Literal::CreateR4FromArray4D<float>(lhs_array); + auto lhs_literal = LiteralUtil::CreateR4FromArray4D<float>(lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); @@ -1102,7 +1102,7 @@ TEST_P(HloEvaluatorTest, DilatedBaseConv2DWithLowAndHighPadding) { {7, 8}, })); // clang-format on - auto rhs_literal = Literal::CreateR4FromArray4D<float>(rhs_array); + auto rhs_literal = LiteralUtil::CreateR4FromArray4D<float>(rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -1138,7 +1138,7 @@ TEST_P(HloEvaluatorTest, DilatedBaseConv2DWithLowAndHighPadding) { {104, 91, 112, 98, 120, 105, 128, 112}, {78, 65, 84, 70, 90, 75, 96, 80}, })); - auto expected = Literal::CreateR4FromArray4D<float>(expected_array); + auto expected = LiteralUtil::CreateR4FromArray4D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -1156,7 +1156,7 @@ TEST_P(HloEvaluatorTest, {13, 14, 15, 16}, })); // clang-format on - auto lhs_literal = Literal::CreateR4FromArray4D<float>(lhs_array); + auto lhs_literal = LiteralUtil::CreateR4FromArray4D<float>(lhs_array); HloInstruction* lhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(lhs_literal))); @@ -1167,7 +1167,7 @@ TEST_P(HloEvaluatorTest, {8, 9, 10}, })); // clang-format on - auto rhs_literal = Literal::CreateR4FromArray4D<float>(rhs_array); + auto rhs_literal = LiteralUtil::CreateR4FromArray4D<float>(rhs_array); HloInstruction* rhs_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(rhs_literal))); @@ -1210,7 +1210,7 @@ TEST_P(HloEvaluatorTest, {0, 0, 0}, {91, 98, 105}, })); - auto expected = Literal::CreateR4FromArray4D<float>(expected_array); + auto expected = LiteralUtil::CreateR4FromArray4D<float>(expected_array); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -1225,9 +1225,9 @@ TEST_F(HloEvaluatorPreciseReduceTest, AddReductionPrecisionTest) { constexpr int kNumElements = 1 << 25; // float += 1 saturates at 1<<24 std::vector<float> v(kNumElements, 1.0f); HloInstruction* arg_instruction = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<float>(v))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<float>(v))); HloInstruction* init_value = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(0.f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.f))); HloComputation::Builder add_computation("add"); Shape scalar_shape = ShapeUtil::MakeShape(F32, {}); @@ -1262,9 +1262,9 @@ void BM_ReducePrecisely(int num_iters) { constexpr int kNumElements = 1 << 25; // float += 1 saturates at 1<<24 std::vector<float> v(kNumElements, 1.0f); HloInstruction* arg_instruction = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<float>(v))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<float>(v))); auto init_value = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(0.f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.f))); HloComputation::Builder add_computation("add"); Shape scalar_shape = ShapeUtil::MakeShape(F32, {}); @@ -1299,13 +1299,13 @@ TEST_P(HloEvaluatorTest, ReduceAdd) { // } auto arg_array = MakeUnique<Array2D<float>>(2, 3); arg_array->FillUnique(1.0f); - auto arg_literal = Literal::CreateR2FromArray2D<float>(*arg_array); + auto arg_literal = LiteralUtil::CreateR2FromArray2D<float>(*arg_array); HloInstruction* arg_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(arg_literal))); auto init_value = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(0.f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.f))); HloComputation::Builder add_computation("add"); Shape scalar_shape = ShapeUtil::MakeShape(F32, {}); @@ -1326,7 +1326,7 @@ TEST_P(HloEvaluatorTest, ReduceAdd) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR1<float>({6, 18}); + auto expected = LiteralUtil::CreateR1<float>({6, 18}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -1341,13 +1341,13 @@ TEST_P(HloEvaluatorTest, ReduceWindowMax) { // } auto arg_array = MakeUnique<Array2D<float>>(2, 3); arg_array->FillUnique(1.0f); - auto arg_literal = Literal::CreateR2FromArray2D<float>(*arg_array); + auto arg_literal = LiteralUtil::CreateR2FromArray2D<float>(*arg_array); HloInstruction* arg_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(arg_literal))); auto init_value = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(0.f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.f))); HloComputation::Builder max_computation("max"); Shape scalar_shape = ShapeUtil::MakeShape(F32, {}); @@ -1378,7 +1378,7 @@ TEST_P(HloEvaluatorTest, ReduceWindowMax) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({{6, 7}}); + auto expected = LiteralUtil::CreateR2<float>({{6, 7}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -1392,13 +1392,13 @@ TEST_P(HloEvaluatorTest, ReduceWindowAdd) { // } auto arg_array = MakeUnique<Array2D<float>>(2, 3); arg_array->FillUnique(1.0f); - auto arg_literal = Literal::CreateR2FromArray2D<float>(*arg_array); + auto arg_literal = LiteralUtil::CreateR2FromArray2D<float>(*arg_array); HloInstruction* arg_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(arg_literal))); auto init_value = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(0.f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.f))); HloComputation::Builder add_computation("add"); Shape scalar_shape = ShapeUtil::MakeShape(F32, {}); @@ -1435,7 +1435,7 @@ TEST_P(HloEvaluatorTest, ReduceWindowAdd) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({{1, 3, 5}, {5, 11, 13}}); + auto expected = LiteralUtil::CreateR2<float>({{1, 3, 5}, {5, 11, 13}}); EXPECT_TRUE(LiteralTestUtil::Equal(*expected, *result)); } @@ -1445,13 +1445,13 @@ TEST_P(HloEvaluatorTest, ReduceWindowAdd6D) { // arg: f32[4,4,4,4,4,4] full of ones. Using small dims to limit run-time. std::vector<int64> input_dims(6, 4); std::unique_ptr<Literal> arg_literal = - Literal::CreateFullWithDescendingLayout<float>(input_dims, 1.0f); + LiteralUtil::CreateFullWithDescendingLayout<float>(input_dims, 1.0f); HloInstruction* arg_instruction = b.AddInstruction(HloInstruction::CreateConstant(std::move(arg_literal))); auto init_value = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR0<float>(0.f))); + HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(0.f))); HloComputation::Builder add_computation("add"); Shape scalar_shape = ShapeUtil::MakeShape(F32, {}); @@ -1498,7 +1498,7 @@ TEST_P(HloEvaluatorTest, ReduceWindowAdd6D) { std::vector<int64> output_dims = {4, 3, 3, 3, 4, 4}; std::unique_ptr<Literal> result_literal = - Literal::CreateFullWithDescendingLayout<float>(output_dims, 8.0f); + LiteralUtil::CreateFullWithDescendingLayout<float>(output_dims, 8.0f); EXPECT_TRUE(LiteralTestUtil::Equal(*result_literal, *result)); } @@ -1513,7 +1513,8 @@ TEST_P(HloEvaluatorTest, StridedSlice) { // } auto operand_array = MakeUnique<Array2D<float>>(3, 5); operand_array->FillUnique(1.0f); - auto operand_literal = Literal::CreateR2FromArray2D<float>(*operand_array); + auto operand_literal = + LiteralUtil::CreateR2FromArray2D<float>(*operand_array); HloInstruction* operand = b.AddInstruction( HloInstruction::CreateConstant(std::move(operand_literal))); @@ -1527,7 +1528,7 @@ TEST_P(HloEvaluatorTest, StridedSlice) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({ + auto expected = LiteralUtil::CreateR2<float>({ {3}, {19}, }); @@ -1545,13 +1546,14 @@ TEST_P(HloEvaluatorTest, DynamicSlice) { // } auto operand_array = MakeUnique<Array2D<float>>(2, 4); operand_array->FillUnique(1.0f); - auto operand_literal = Literal::CreateR2FromArray2D<float>(*operand_array); + auto operand_literal = + LiteralUtil::CreateR2FromArray2D<float>(*operand_array); HloInstruction* operand = b.AddInstruction( HloInstruction::CreateConstant(std::move(operand_literal))); auto start_indices = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int32>({0, 1}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int32>({0, 1}))); Shape shape = ShapeUtil::MakeShape(F32, {2, 3}); b.AddInstruction(HloInstruction::CreateDynamicSlice(shape, operand, @@ -1560,7 +1562,7 @@ TEST_P(HloEvaluatorTest, DynamicSlice) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({ + auto expected = LiteralUtil::CreateR2<float>({ {2, 3, 4}, {6, 7, 8}, }); @@ -1580,13 +1582,14 @@ TEST_P(HloEvaluatorTest, DynamicSliceModSlice) { // } auto operand_array = MakeUnique<Array2D<float>>(2, 4); operand_array->FillUnique(1.0f); - auto operand_literal = Literal::CreateR2FromArray2D<float>(*operand_array); + auto operand_literal = + LiteralUtil::CreateR2FromArray2D<float>(*operand_array); HloInstruction* operand = b.AddInstruction( HloInstruction::CreateConstant(std::move(operand_literal))); auto start_indices = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int32>({2, 1}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int32>({2, 1}))); Shape shape = ShapeUtil::MakeShape(F32, {2, 3}); b.AddInstruction(HloInstruction::CreateDynamicSlice(shape, operand, @@ -1595,7 +1598,7 @@ TEST_P(HloEvaluatorTest, DynamicSliceModSlice) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<float>({ + auto expected = LiteralUtil::CreateR2<float>({ {2, 3, 4}, {6, 7, 8}, }); @@ -1613,16 +1616,17 @@ TEST_P(HloEvaluatorTest, DynamicSliceUpdate) { // } auto operand_array = MakeUnique<Array2D<double>>(2, 3); operand_array->FillUnique(1.0); - auto operand_literal = Literal::CreateR2FromArray2D<double>(*operand_array); + auto operand_literal = + LiteralUtil::CreateR2FromArray2D<double>(*operand_array); HloInstruction* operand = b.AddInstruction( HloInstruction::CreateConstant(std::move(operand_literal))); auto start_indices = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int64>({0, 1}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int64>({0, 1}))); auto update = b.AddInstruction(HloInstruction::CreateConstant( - Literal::CreateR2<double>({{-2.0, -3.0}, {-6.0, -7.0}}))); + LiteralUtil::CreateR2<double>({{-2.0, -3.0}, {-6.0, -7.0}}))); Shape shape = ShapeUtil::MakeShape(F64, {2, 3}); b.AddInstruction(HloInstruction::CreateDynamicUpdateSlice( @@ -1631,7 +1635,7 @@ TEST_P(HloEvaluatorTest, DynamicSliceUpdate) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<double>({ + auto expected = LiteralUtil::CreateR2<double>({ {1, -2, -3}, {5, -6, -7}, }); @@ -1649,12 +1653,13 @@ TEST_P(HloEvaluatorTest, SetAndGetTuples) { // } auto operand_array = MakeUnique<Array2D<double>>(2, 3); operand_array->FillUnique(1.0); - auto operand_literal2 = Literal::CreateR2FromArray2D<double>(*operand_array); + auto operand_literal2 = + LiteralUtil::CreateR2FromArray2D<double>(*operand_array); HloInstruction* operand2 = b.AddInstruction( HloInstruction::CreateConstant(std::move(operand_literal2))); HloInstruction* operand1 = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int64>({0, 1}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int64>({0, 1}))); auto tuple = b.AddInstruction(HloInstruction::CreateTuple({operand1, operand2})); @@ -1666,7 +1671,7 @@ TEST_P(HloEvaluatorTest, SetAndGetTuples) { std::unique_ptr<Literal> result = Evaluate(); - auto expected = Literal::CreateR2<double>({ + auto expected = LiteralUtil::CreateR2<double>({ {1, 2, 3}, {5, 6, 7}, }); @@ -1686,9 +1691,9 @@ TEST_P(HloEvaluatorTest, SetAndGetNestedTuples) { operand_array->FillUnique(1.0); HloInstruction* operand2 = b.AddInstruction(HloInstruction::CreateConstant( - Literal::CreateR2FromArray2D<double>(*operand_array))); + LiteralUtil::CreateR2FromArray2D<double>(*operand_array))); HloInstruction* operand1 = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<int64>({0, 1}))); + HloInstruction::CreateConstant(LiteralUtil::CreateR1<int64>({0, 1}))); auto tuple1 = b.AddInstruction(HloInstruction::CreateTuple({operand1, operand2})); @@ -1706,8 +1711,8 @@ TEST_P(HloEvaluatorTest, SetAndGetNestedTuples) { std::unique_ptr<Literal> result = Evaluate(); auto result_inner_literal = - Literal::CreateR2FromArray2D<double>(*operand_array); - auto expected = Literal::MakeTuple({ + LiteralUtil::CreateR2FromArray2D<double>(*operand_array); + auto expected = LiteralUtil::MakeTuple({ result_inner_literal.get(), result_inner_literal.get(), }); @@ -1735,7 +1740,7 @@ TEST_P(HloEvaluatorTest, Reverse) { {{23.0f}, {24.0f}}}, }); // clang-format on - auto operand_literal = Literal::CreateR4FromArray4D<float>(input); + auto operand_literal = LiteralUtil::CreateR4FromArray4D<float>(input); HloInstruction* operand = b.AddInstruction( HloInstruction::CreateConstant(std::move(operand_literal))); @@ -1746,7 +1751,7 @@ TEST_P(HloEvaluatorTest, Reverse) { std::unique_ptr<Literal> result = Evaluate(); // clang-format off - auto expected = Literal::CreateR4FromArray4D<float>({ + auto expected = LiteralUtil::CreateR4FromArray4D<float>({ {{{23.0f}, {24.0f}}, {{21.0f}, {22.0f}}, {{19.0f}, {20.0f}}}, @@ -1782,11 +1787,11 @@ TEST_P(HloEvaluatorTest, EvaluateWithSubstitutions) { // Evaluate add with param0 = {1, 2, 3, 4}, square = {10, 20, 30, 40}. HloEvaluator evaluator; auto result = evaluator.EvaluateWithSubstitutions( - add, {{param0, Literal::CreateR1<float>({1, 2, 3, 4}).get()}, - {square, Literal::CreateR1<float>({10, 20, 30, 40}).get()}}); + add, {{param0, LiteralUtil::CreateR1<float>({1, 2, 3, 4}).get()}, + {square, LiteralUtil::CreateR1<float>({10, 20, 30, 40}).get()}}); TF_ASSERT_OK(result.status()); EXPECT_TRUE(LiteralTestUtil::Equal( - *Literal::CreateR1<float>({11, 22, 33, 44}), *result.ValueOrDie())); + *LiteralUtil::CreateR1<float>({11, 22, 33, 44}), *result.ValueOrDie())); } // Check that EvaluateWithSubstitutions works if one of the operands to the op @@ -1799,18 +1804,18 @@ TEST_P(HloEvaluatorTest, EvaluateWithSubstitutionsWithConstantOperand) { b.AddInstruction(HloInstruction::CreateParameter(0, shape, "param0")); HloInstruction* square = b.AddInstruction(HloInstruction::CreateBinary( shape, HloOpcode::kMultiply, param0, param0)); - HloInstruction* constant = b.AddInstruction( - HloInstruction::CreateConstant(Literal::CreateR1<float>({1, 2, 3, 4}))); + HloInstruction* constant = b.AddInstruction(HloInstruction::CreateConstant( + LiteralUtil::CreateR1<float>({1, 2, 3, 4}))); HloInstruction* add = b.AddInstruction( HloInstruction::CreateBinary(shape, HloOpcode::kAdd, constant, square)); // Evaluate add with square = {10, 20, 30, 40}. HloEvaluator evaluator; auto result = evaluator.EvaluateWithSubstitutions( - add, {{square, Literal::CreateR1<float>({10, 20, 30, 40}).get()}}); + add, {{square, LiteralUtil::CreateR1<float>({10, 20, 30, 40}).get()}}); TF_ASSERT_OK(result.status()); EXPECT_TRUE(LiteralTestUtil::Equal( - *Literal::CreateR1<float>({11, 22, 33, 44}), *result.ValueOrDie())); + *LiteralUtil::CreateR1<float>({11, 22, 33, 44}), *result.ValueOrDie())); } TEST_P(HloEvaluatorTest, EvaluateGather_TensorFlowGatherV1) { @@ -1830,11 +1835,12 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); - std::unique_ptr<Literal> gather_indices = Literal::CreateR1<int32>({0, 2}); - EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR2<int32>({{1, 2, 3}, {7, 8, 9}}), - *Evaluate({operand.get(), gather_indices.get()}))); + LiteralUtil::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); + std::unique_ptr<Literal> gather_indices = + LiteralUtil::CreateR1<int32>({0, 2}); + EXPECT_TRUE(LiteralTestUtil::Equal( + *LiteralUtil::CreateR2<int32>({{1, 2, 3}, {7, 8, 9}}), + *Evaluate({operand.get(), gather_indices.get()}))); } TEST_P(HloEvaluatorTest, EvaluateGather_TensorFlowGatherV2) { @@ -1854,10 +1860,11 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); - std::unique_ptr<Literal> gather_indices = Literal::CreateR1<int32>({0, 2}); + LiteralUtil::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); + std::unique_ptr<Literal> gather_indices = + LiteralUtil::CreateR1<int32>({0, 2}); EXPECT_TRUE(LiteralTestUtil::Equal( - *Literal::CreateR2<int32>({{1, 3}, {4, 6}, {7, 9}}), + *LiteralUtil::CreateR2<int32>({{1, 3}, {4, 6}, {7, 9}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -1878,11 +1885,11 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); + LiteralUtil::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); std::unique_ptr<Literal> gather_indices = - Literal::CreateR2<int32>({{0, 2}, {2, 1}}); + LiteralUtil::CreateR2<int32>({{0, 2}, {2, 1}}); EXPECT_TRUE(LiteralTestUtil::Equal( - *Literal::CreateR3<int32>( + *LiteralUtil::CreateR3<int32>( {{{1, 3}, {4, 6}, {7, 9}}, {{3, 2}, {6, 5}, {9, 8}}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -1904,13 +1911,13 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR3<int32>({{{-1, 1}, {-2, 2}, {-3, 3}}, // - {{-4, 4}, {-5, 5}, {-6, 6}}, // - {{-7, 7}, {-8, 8}, {-9, 9}}}); + LiteralUtil::CreateR3<int32>({{{-1, 1}, {-2, 2}, {-3, 3}}, // + {{-4, 4}, {-5, 5}, {-6, 6}}, // + {{-7, 7}, {-8, 8}, {-9, 9}}}); std::unique_ptr<Literal> gather_indices = - Literal::CreateR2<int32>({{0, 0}, {1, 0}}); + LiteralUtil::CreateR2<int32>({{0, 0}, {1, 0}}); EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR2<int32>({{-1, 1}, {-4, 4}}), + LiteralTestUtil::Equal(*LiteralUtil::CreateR2<int32>({{-1, 1}, {-4, 4}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -1932,13 +1939,13 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR3<int32>({{{-1, 1}, {-2, 2}, {-3, 3}}, // - {{-4, 4}, {-5, 5}, {-6, 6}}, // - {{-7, 7}, {-8, 8}, {-9, 9}}}); + LiteralUtil::CreateR3<int32>({{{-1, 1}, {-2, 2}, {-3, 3}}, // + {{-4, 4}, {-5, 5}, {-6, 6}}, // + {{-7, 7}, {-8, 8}, {-9, 9}}}); std::unique_ptr<Literal> gather_indices = - Literal::CreateR2<int32>({{0, 0}, {1, 0}}); + LiteralUtil::CreateR2<int32>({{0, 0}, {1, 0}}); EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR2<int32>({{-2, 2}, {-1, 1}}), + LiteralTestUtil::Equal(*LiteralUtil::CreateR2<int32>({{-2, 2}, {-1, 1}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -1959,10 +1966,11 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); - std::unique_ptr<Literal> gather_indices = Literal::CreateR1<int32>({1, 1}); + LiteralUtil::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); + std::unique_ptr<Literal> gather_indices = + LiteralUtil::CreateR1<int32>({1, 1}); EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR2<int32>({{5}}), + LiteralTestUtil::Equal(*LiteralUtil::CreateR2<int32>({{5}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -1983,11 +1991,11 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); std::unique_ptr<Literal> operand = - Literal::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); + LiteralUtil::CreateR2<int32>({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}); std::unique_ptr<Literal> gather_indices = - Literal::CreateR2<int32>({{2, 1}, {1, 1}}); + LiteralUtil::CreateR2<int32>({{2, 1}, {1, 1}}); EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR3<int32>({{{8}}, {{5}}}), + LiteralTestUtil::Equal(*LiteralUtil::CreateR3<int32>({{{8}}, {{5}}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -2007,10 +2015,11 @@ ENTRY main { } )"; ParseAndVerifyModule(hlo_text); - std::unique_ptr<Literal> operand = Literal::CreateR2<int32>({{}, {}, {}}); - std::unique_ptr<Literal> gather_indices = Literal::CreateR1<int32>({0, 2}); + std::unique_ptr<Literal> operand = LiteralUtil::CreateR2<int32>({{}, {}, {}}); + std::unique_ptr<Literal> gather_indices = + LiteralUtil::CreateR1<int32>({0, 2}); EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR2<int32>({{}, {}}), + LiteralTestUtil::Equal(*LiteralUtil::CreateR2<int32>({{}, {}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -2031,11 +2040,11 @@ ENTRY main { )"; ParseAndVerifyModule(hlo_text); - std::unique_ptr<Literal> operand = Literal::CreateR1<int32>({0, 1, 2}); + std::unique_ptr<Literal> operand = LiteralUtil::CreateR1<int32>({0, 1, 2}); std::unique_ptr<Literal> gather_indices = - Literal::CreateR3<int32>({{{0}, {1}}, {{2}, {1}}}); + LiteralUtil::CreateR3<int32>({{{0}, {1}}, {{2}, {1}}}); EXPECT_TRUE( - LiteralTestUtil::Equal(*Literal::CreateR2<int32>({{0, 1}, {2, 1}}), + LiteralTestUtil::Equal(*LiteralUtil::CreateR2<int32>({{0, 1}, {2, 1}}), *Evaluate({operand.get(), gather_indices.get()}))); } @@ -2043,14 +2052,14 @@ ENTRY main { // element-wise comparison with 2 bfloat16 operands. TEST_P(HloEvaluatorTest, DoesCompareBF16) { // lhs >= rhs - auto lhs = Literal::CreateR2<bfloat16>( + auto lhs = LiteralUtil::CreateR2<bfloat16>( {{bfloat16(0.25), bfloat16(0.35), bfloat16(0.125)}, {bfloat16(-0.25), bfloat16(-0.35), bfloat16(-0.125)}}); - auto rhs = Literal::CreateR2<bfloat16>( + auto rhs = LiteralUtil::CreateR2<bfloat16>( {{bfloat16(0.5), bfloat16(0.125), bfloat16(0.125)}, {bfloat16(0.25), bfloat16(-0.375), bfloat16(-0.127)}}); auto expected = - Literal::CreateR2<bool>({{false, true, true}, {false, true, true}}); + LiteralUtil::CreateR2<bool>({{false, true, true}, {false, true, true}}); TestBinaryOp(HloOpcode::kGe, std::move(expected), std::move(lhs), std::move(rhs)); } |