When I use reshape, when data movement happen?


(Hao Zhang) #1

For example, I call tensordot,
aten/src/ATen/native/Linear.cpp:tensordot call permute and reshape it
aten/src/ATen/native/TensorShape.cpp:permute return as_strided, it seems it just note the strides without data movement
aten/src/ATen/native/TensorShape.cpp:reshape return at::_unsafe_view(self.clone(), shape), it seems that data movement happened in clone, it seems torch permute data in clone.
aten/src/ATen/native/LegacyBridge.cpp:clone give me legacy::th::th_clone
aten/src/ATen/Declarations.cwrap told me it is newClone
aten/src/TH/generic/THTensor.cpp:THTensor
(newClone) return at::_copy_same_type
aten/src/ATen/native/native_functions.yaml said _copy_same_type__cpu
but in aten/src/ATen/native/Copy.cpp:_copy_same_type__cpu I see no code about strides

so when data movement happen indeed?