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

Method from_buffer

oneflow/api/cpp/framework/tensor.cpp:84–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84Tensor Tensor::from_buffer(const void* buffer, const Shape& shape, const Device& device,
85 const DType& dtype) {
86 Tensor tensor(shape, device, dtype);
87 std::shared_ptr<of::one::LocalTensor> local_tensor =
88 tensor.tensor_->AsLocalTensor().GetPtrOrThrow();
89 of::PhysicalRun([&](of::InstructionsBuilder* builder) -> of::Maybe<void> {
90 return builder->AccessBlobByCallback(
91 local_tensor,
92 [buffer, shape, dtype](of::ep::Stream* stream,
93 const std::shared_ptr<of::vm::EagerBlobObject>& eager_blob_object) {
94 of::AutoMemcpy(stream, eager_blob_object->mut_dptr(), buffer,
95 shape.Count(0) * GetDTypeSize(dtype), eager_blob_object->mem_case(),
96 of::memory::MakeHostMemCase());
97 },
98 "mut");
99 }).GetOrThrow();
100 return tensor;
101}
102
103template<typename T>
104void Tensor::copy_to(T* buffer) const {

Callers

nothing calls this directly

Calls 10

PhysicalRunFunction · 0.85
AutoMemcpyFunction · 0.85
GetDTypeSizeFunction · 0.85
MakeHostMemCaseFunction · 0.85
GetPtrOrThrowMethod · 0.80
AccessBlobByCallbackMethod · 0.80
AsLocalTensorMethod · 0.45
GetOrThrowMethod · 0.45
mut_dptrMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected