[c10] helpers for runtime c10::alias re-use (#151361)

Summary: we need these to check whether the input tensor was re-sized/strided between executions when choosing to alias

Test Plan: CI

Reviewed By: henryoier

Differential Revision: D73061676

Pull Request resolved: https://github.com/pytorch/pytorch/pull/151361
Approved by: https://github.com/SherlockNoMad
This commit is contained in:
Dylan Maloy
2025-04-17 20:27:14 +00:00
committed by PyTorch MergeBot
parent da580123a0
commit 8e0f9fbccf
2 changed files with 18 additions and 0 deletions

View File

@ -1834,6 +1834,10 @@ struct C10_API TensorImpl : public c10::intrusive_ptr_target {
MemoryFormat::Contiguous); // calls refresh_contiguous()
}
C10_ALWAYS_INLINE const impl::SizesAndStrides& sizes_and_strides() {
return sizes_and_strides_;
}
/**
* Set the sizes and strides of a tensor.
*

View File

@ -50,6 +50,20 @@ class C10_API SizesAndStrides {
}
}
bool operator==(const SizesAndStrides& other) const {
if (size_ != other.size_) {
return false;
}
return !(
isInline()
? std::memcmp(
inlineStorage_, other.inlineStorage_, sizeof(inlineStorage_))
: std::memcmp(
outOfLineStorage_,
other.outOfLineStorage_,
storageBytes(size_)));
}
SizesAndStrides& operator=(const SizesAndStrides& rhs) {
if (this == &rhs) {
return *this;