MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / InplaceView

Function InplaceView

oneflow/core/framework/tensor_methods.cpp:121–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121Maybe<void> InplaceView(const std::shared_ptr<Tensor>& input, const Shape& target_shape,
122 const Stride& target_stride, const int64_t storage_offset) {
123 Symbol<LocalTensorMeta> new_tensor_meta =
124 SymbolOf(LocalTensorMeta(target_shape, target_stride, input->dtype()->data_type(),
125 input->memory_format(), JUST(input->device())));
126
127 bool requires_grad = (autograd::GradMode::is_enabled() && input->requires_grad());
128 std::shared_ptr<EagerLocalTensorImpl> new_tensor_impl = std::make_shared<EagerLocalTensorImpl>(
129 JUST(input->tensor_storage()), storage_offset, /*requires_grad=*/requires_grad,
130 /*is_leaf=*/!requires_grad);
131 JUST(new_tensor_impl->InitEagerBlobObject(
132 new_tensor_meta, JUST(JUST(input->eager_blob_object())->compute_local_dep_object())));
133 JUST(JUST(input->AsLocalTensor())->set_impl(new_tensor_impl));
134 return Maybe<void>::Ok();
135}
136
137Maybe<Tensor> Reshape(const std::shared_ptr<Tensor>& input, const Shape& target_shape) {
138 Stride target_stride(target_shape);

Callers 4

InplaceUnsqueezeFunction · 0.85
InplaceSqueezeFunction · 0.85
InplaceExpandFunction · 0.85
InplaceAsStridedFunction · 0.85

Calls 14

SymbolOfFunction · 0.85
set_implMethod · 0.80
is_enabledFunction · 0.70
LocalTensorMetaClass · 0.50
data_typeMethod · 0.45
dtypeMethod · 0.45
memory_formatMethod · 0.45
deviceMethod · 0.45
requires_gradMethod · 0.45
tensor_storageMethod · 0.45
InitEagerBlobObjectMethod · 0.45

Tested by

no test coverage detected