| 1071 | }; |
| 1072 | |
| 1073 | TEST_F(TensorBundleAlignmentTest, AlignmentTest) { |
| 1074 | { |
| 1075 | BundleWriter::Options opts; |
| 1076 | opts.data_alignment = 42; |
| 1077 | BundleWriter writer(Env::Default(), Prefix("foo"), opts); |
| 1078 | TF_EXPECT_OK(writer.Add("foo_003", Constant_2x3<float>(3))); |
| 1079 | TF_EXPECT_OK(writer.Add("foo_000", Constant_2x3<float>(0))); |
| 1080 | TF_EXPECT_OK(writer.Add("foo_002", Constant_2x3<float>(2))); |
| 1081 | TF_EXPECT_OK(writer.Add("foo_001", Constant_2x3<float>(1))); |
| 1082 | TF_ASSERT_OK(writer.Finish()); |
| 1083 | } |
| 1084 | { |
| 1085 | BundleReader reader(Env::Default(), Prefix("foo")); |
| 1086 | TF_ASSERT_OK(reader.status()); |
| 1087 | EXPECT_EQ( |
| 1088 | AllTensorKeys(&reader), |
| 1089 | std::vector<string>({"foo_000", "foo_001", "foo_002", "foo_003"})); |
| 1090 | Expect<float>(&reader, "foo_000", Constant_2x3<float>(0)); |
| 1091 | Expect<float>(&reader, "foo_001", Constant_2x3<float>(1)); |
| 1092 | Expect<float>(&reader, "foo_002", Constant_2x3<float>(2)); |
| 1093 | Expect<float>(&reader, "foo_003", Constant_2x3<float>(3)); |
| 1094 | } |
| 1095 | { |
| 1096 | BundleReader reader(Env::Default(), Prefix("foo")); |
| 1097 | TF_ASSERT_OK(reader.status()); |
| 1098 | ExpectNext<float>(&reader, Constant_2x3<float>(0)); |
| 1099 | ExpectNext<float>(&reader, Constant_2x3<float>(1)); |
| 1100 | ExpectNext<float>(&reader, Constant_2x3<float>(2)); |
| 1101 | ExpectNext<float>(&reader, Constant_2x3<float>(3)); |
| 1102 | EXPECT_TRUE(reader.Valid()); |
| 1103 | reader.Next(); |
| 1104 | EXPECT_FALSE(reader.Valid()); |
| 1105 | } |
| 1106 | { |
| 1107 | BundleReader reader(Env::Default(), Prefix("foo")); |
| 1108 | TF_ASSERT_OK(reader.status()); |
| 1109 | ExpectAlignment<float>(&reader, "foo_000", 42); |
| 1110 | ExpectAlignment<float>(&reader, "foo_001", 42); |
| 1111 | ExpectAlignment<float>(&reader, "foo_002", 42); |
| 1112 | ExpectAlignment<float>(&reader, "foo_003", 42); |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | static void BM_BundleAlignmentByteOff(int iters, int alignment, |
| 1117 | int tensor_size) { |