mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[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:
committed by
PyTorch MergeBot
parent
da580123a0
commit
8e0f9fbccf
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user