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

Rollforward with fix. #65005

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ limitations under the License.
#include "absl/types/span.h"
#include "xla/layout_util.h"
#include "xla/service/hlo.pb.h"
#include "xla/shape.h"
#include "xla/shape_util.h"
#include "xla/xla_data.pb.h"
#include "tensorflow/core/platform/errors.h"
Expand All @@ -57,12 +58,16 @@ using ::xla::LogicalBufferProto;
using ::xla::Shape;
using ::xla::ShapeUtil;

const Shape* ResolveShapeIndex(const Shape* shape,
absl::Span<const int64_t> shape_index) {
for (int64_t value : shape_index) {
shape = &shape->tuple_shapes(value);
Shape ResolveShapeIndex(const xla::ShapeProto& shape_proto,
absl::Span<const int64_t> shape_index) {
if (shape_index.empty()) return Shape(shape_proto);
// Choosing the last subshape to maintain historical behavior.
int64_t i = shape_index.back();
if (i >= shape_proto.tuple_shapes_size()) {
LOG(WARNING) << "shape_index out of tuple_shapes range.";
return Shape(shape_proto);
}
return shape;
return Shape(shape_proto.tuple_shapes(i));
}

std::string ShapeDescription(const Shape& shape) {
Expand Down Expand Up @@ -132,12 +137,12 @@ struct LogicalBufferStruct {
LogicalBufferStruct(const LogicalBufferProto& p,
const BufferAllocationStruct& b,
const ::xla::HloInstructionProto& i, uint64_t offset)
: proto(p), buffer_allocation(b), hlo_instruction(i), offset(offset) {
// Get shape of logical buffer.
const Shape top_level_shape(hlo_instruction.shape());
shape =
*ResolveShapeIndex(&top_level_shape, proto.defined_at().shape_index());
}
: proto(p),
buffer_allocation(b),
hlo_instruction(i),
offset(offset),
shape(ResolveShapeIndex(hlo_instruction.shape(),
proto.defined_at().shape_index())) {}

absl::string_view instruction_name() const { return hlo_instruction.name(); }

Expand Down