Skip to content

Commit

Permalink
Rename Buffer to GetBuffer.
Browse files Browse the repository at this point in the history
InterpreterValue::Buffer having the same name as Buffer is considered
invalid by GCC.

sed "s/\.Buffer/.GetBuffer/g" -i `find . -name '*.cc'`

PiperOrigin-RevId: 635710161
  • Loading branch information
jreiffers authored and tensorflower-gardener committed May 21, 2024
1 parent a51ee7d commit fde16c7
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ InterpreterValue Bitcast(InterpreterState&, arith::BitcastOp op,
TensorOrMemref<decltype(dummy)> result;
result.view = {};
if (shaped_ty) {
result.buffer = in.Clone().Buffer();
result.buffer = in.Clone().GetBuffer();
} else {
result.buffer = in.AsUnitTensor().Buffer();
result.buffer = in.AsUnitTensor().GetBuffer();
}
return {result};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ InterpreterValue AllocTensor(
InterpreterValue Clone(InterpreterState& state, bufferization::CloneOp,
const InterpreterValue& in) {
if (auto* stats = state.GetOptions().stats) {
stats->heap_size += in.Buffer()->GetByteSize();
stats->heap_size += in.GetBuffer()->GetByteSize();
stats->peak_heap_size = std::max(stats->peak_heap_size, stats->heap_size);
++stats->num_allocations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ llvm::SmallVector<InterpreterValue> UnrealizedConversionCast(
return {DispatchScalarType(r, [&](auto dummy) -> InterpreterValue {
TensorOrMemref<decltype(dummy)> result;
result.view = args[0].View();
result.buffer = args[0].Buffer();
result.buffer = args[0].GetBuffer();
return {result};
})};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace {
InterpreterValue Load(InterpreterState& state, memref::LoadOp,
const InterpreterValue& memref,
ArrayRef<int64_t> indices) {
if (!memref.Buffer()) {
if (!memref.GetBuffer()) {
state.AddFailure("null pointer dereference.");
return {};
}
Expand Down Expand Up @@ -69,11 +69,11 @@ InterpreterValue Alloc(InterpreterState& state, memref::AllocOp alloc,
auto result =
InterpreterValue::MakeTensor(ty.getElementType(), std::move(shape));
if (auto* stats = state.GetOptions().stats) {
stats->heap_size += result.Buffer()->GetByteSize();
stats->heap_size += result.GetBuffer()->GetByteSize();
stats->peak_heap_size = std::max(stats->peak_heap_size, stats->heap_size);
++stats->num_allocations;
}
result.Buffer()->SetAllocatedBy(alloc);
result.GetBuffer()->SetAllocatedBy(alloc);
return result;
}

Expand All @@ -83,18 +83,18 @@ InterpreterValue AllocA(InterpreterState&, memref::AllocaOp alloc,
auto shape = ReplaceDynamicVals(ty.getShape(), dynamic_sizes);
auto result =
InterpreterValue::MakeTensor(ty.getElementType(), std::move(shape));
result.Buffer()->SetIsAlloca();
result.Buffer()->SetAllocatedBy(alloc);
result.GetBuffer()->SetIsAlloca();
result.GetBuffer()->SetAllocatedBy(alloc);
return result;
}

void Dealloc(InterpreterState& state, memref::DeallocOp op,
InterpreterValue memref) {
if (!memref.Buffer()) {
if (!memref.GetBuffer()) {
state.AddFailure("attempting to deallocate null pointer.");
return;
}
auto buffer = memref.Buffer();
auto buffer = memref.GetBuffer();
const auto& view = memref.View();
if (auto* stats = state.GetOptions().stats) {
stats->heap_size -= buffer->GetByteSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ InterpreterValue BitcastConvert(InterpreterState&, mhlo::BitcastConvertOp op,
auto result = DispatchScalarType(ty, [&](auto dummy) -> InterpreterValue {
TensorOrMemref<decltype(dummy)> result;
result.view = {};
result.buffer = in.Clone().Buffer();
result.buffer = in.Clone().GetBuffer();
return {result};
});
auto& out_view = result.View();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ InterpreterValue Bitcast(InterpreterState&, vector::BitCastOp op,
const InterpreterValue& vector) {
ShapedType ty = cast<ShapedType>(op->getResultTypes()[0]);
auto flattened = vector.CoerceLayout({});
auto buffer = flattened.Buffer();
auto buffer = flattened.GetBuffer();
auto view = flattened.View();
view.sizes = llvm::to_vector(ty.getShape());
view.strides = BufferView::GetDefaultStrides(view.sizes);
Expand Down Expand Up @@ -190,7 +190,7 @@ InterpreterValue Broadcast(InterpreterState&, vector::BroadcastOp broadcast,
void CompressStore(InterpreterState& state, vector::CompressStoreOp,
InterpreterValue dst, ArrayRef<int64_t> indices,
TensorOrMemref<bool> mask, InterpreterValue value) {
auto dst_buffer = dst.Buffer();
auto dst_buffer = dst.GetBuffer();
const auto& dst_view = dst.View();
if (dst_view.strides.back() != 1) {
state.AddFailure("trailing dimension must be continguous");
Expand All @@ -202,7 +202,7 @@ void CompressStore(InterpreterState& state, vector::CompressStoreOp,
return;
}

auto src_buffer = value.Buffer();
auto src_buffer = value.GetBuffer();
const auto& src_view = value.View();

// TODO(jreiffers): Bounds checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ void InterpreterState::AddFailure(llvm::StringRef failure) {

void InterpreterScope::Verify() const {
for (auto& [_, value] : values_) {
if (value.IsTensor() && value.Buffer() &&
!value.Buffer()->GetFailure().empty()) {
state_.AddFailure(value.Buffer()->GetFailure());
if (value.IsTensor() && value.GetBuffer() &&
!value.GetBuffer()->GetFailure().empty()) {
state_.AddFailure(value.GetBuffer()->GetFailure());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool Tuple::operator==(const Tuple& other) const {
return true;
}

std::shared_ptr<Buffer> InterpreterValue::Buffer() const {
std::shared_ptr<Buffer> InterpreterValue::GetBuffer() const {
return std::visit(
[](const auto& it) -> std::shared_ptr<interpreter::Buffer> {
if constexpr (is_tensor_or_memref_v<decltype(it)>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct InterpreterValue {
BufferView& View();
const BufferView& View() const;
// Returns the underlying tensor's buffer. Must be a tensor.
std::shared_ptr<Buffer> Buffer() const;
std::shared_ptr<Buffer> GetBuffer() const;

bool IsTensor() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ absl::StatusOr<InterpreterValue> LiteralToValue(
return {DispatchScalarType(type, [&](auto dummy) -> InterpreterValue {
TensorOrMemref<decltype(dummy)> cast;
cast.view = result.View();
cast.buffer = result.Buffer();
cast.buffer = result.GetBuffer();
return {cast};
})};
}
Expand Down

0 comments on commit fde16c7

Please sign in to comment.