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

Method MakeTensor

oneflow/core/framework/tensor.cpp:101–116  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

99}
100
101/* static */ Maybe<LocalTensor> LocalTensor::MakeTensor(const std::shared_ptr<const Shape>& shape,
102 const std::shared_ptr<const Stride>& stride,
103 DataType dtype, MemoryFormat memory_format,
104 const Symbol<Device>& device, bool is_lazy,
105 bool requires_grad, bool is_leaf) {
106 const auto& tensor_meta = SymbolOf(LocalTensorMeta(*shape, dtype, memory_format, device));
107 if (is_lazy) {
108 const auto& impl = std::make_shared<LazyLocalTensorImpl>(tensor_meta, requires_grad, is_leaf);
109 return std::make_shared<LocalTensor>(impl);
110 } else {
111 const auto& impl = std::make_shared<EagerLocalTensorImpl>(requires_grad, is_leaf);
112 const auto& dep_object = NewLocalDepObject();
113 JUST(impl->InitEagerBlobObject(tensor_meta, dep_object));
114 return std::make_shared<LocalTensor>(impl);
115 }
116}
117
118bool LocalTensor::is_cpu() const { return CHECK_JUST(device())->type() == "cpu"; }
119bool LocalTensor::is_cuda() const { return CHECK_JUST(device())->type() == "cuda"; }

Callers

nothing calls this directly

Calls 6

SymbolOfFunction · 0.85
NewLocalDepObjectFunction · 0.85
GlobalTensorMetaClass · 0.70
NewFunction · 0.70
LocalTensorMetaClass · 0.50
InitEagerBlobObjectMethod · 0.45

Tested by

no test coverage detected