Skip to content

Commit 64ec0a4

Browse files
majnemercopybara-github
authored andcommitted
[xprof] Use xla::Shape::FromProto for creating Shape.
PiperOrigin-RevId: 758833188
1 parent 8192cec commit 64ec0a4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

xprof/convert/hlo_proto_to_memory_visualization_utils.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,20 @@ using ::xla::StackFrameIndexProto;
6565

6666
Shape ResolveShapeIndex(const xla::ShapeProto& shape_proto,
6767
absl::Span<const int64_t> shape_index) {
68-
if (shape_index.empty()) return Shape(shape_proto);
6968
// Choosing the last subshape to maintain historical behavior.
70-
int64_t i = shape_index.back();
71-
if (i >= shape_proto.tuple_shapes_size()) {
72-
return Shape(shape_proto);
69+
const xla::ShapeProto* proto = &shape_proto;
70+
if (!shape_index.empty()) {
71+
int64_t i = shape_index.back();
72+
if (i < shape_proto.tuple_shapes_size()) {
73+
proto = &shape_proto.tuple_shapes(i);
74+
}
75+
}
76+
absl::StatusOr<Shape> shape = Shape::FromProto(*proto);
77+
if (!shape.ok()) {
78+
LOG(DFATAL) << "Failed to resolve shape index: " << shape.status();
79+
return Shape();
7380
}
74-
return Shape(shape_proto.tuple_shapes(i));
81+
return *shape;
7582
}
7683

7784
std::string ShapeDescription(const Shape& shape) {

0 commit comments

Comments
 (0)