Skip to content

Commit

Permalink
Add a check that if any single dimension of an xla shape is 0 the dat…
Browse files Browse the repository at this point in the history
…a size is 0.

PiperOrigin-RevId: 636352383
  • Loading branch information
tensorflower-gardener committed May 23, 2024
1 parent 7354cca commit 7d3c6c1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions third_party/xla/xla/shape_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,20 @@ TEST(ShapeUtilTest, Int4ShapeSize) {
EXPECT_EQ(ShapeUtil::ArraySize(int4_shape2), 9216 * 6144 / 2);
}

TEST(XlaShapeUtilTest, ZeroSize) {
// Verify that if any one dimension is 0 we have a zero byte buffer.
std::vector<std::vector<int64_t>> test_cases = {
{0, 64, 128}, {128, 0, 64}, {64, 128, 0},
{0, 63, 127}, {127, 0, 63}, {63, 127, 0},
};
for (const auto& dimensions : test_cases) {
xla::Shape int4_shape = xla::ShapeUtil::MakeShape(xla::S4, dimensions);
int4_shape.mutable_layout()->set_element_size_in_bits(4);
EXPECT_EQ(xla::ShapeUtil::ArrayDataSize(int4_shape), 0);
EXPECT_EQ(xla::ShapeUtil::ArraySize(int4_shape), 0);
}
}

TEST(ShapeUtilTest, DecomposeBitcastToReshape) {
const Shape kInputShape =
ShapeUtil::MakeShapeWithDenseLayout(F32, {1, 16, 17, 3}, {3, 2, 1, 0});
Expand Down

0 comments on commit 7d3c6c1

Please sign in to comment.