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

Method copy_to

oneflow/api/cpp/framework/tensor.cpp:104–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103template<typename T>
104void Tensor::copy_to(T* buffer) const {
105 std::shared_ptr<of::one::LocalTensor> local_tensor = tensor_->AsLocalTensor().GetPtrOrThrow();
106 const auto shape = this->shape();
107
108 const auto& Callback = [buffer, shape](
109 of::ep::Stream* stream,
110 const std::shared_ptr<of::vm::EagerBlobObject>& eager_blob_object) {
111 of::AutoMemcpy(stream, buffer, eager_blob_object->mut_dptr(), shape.Count(0) * sizeof(T),
112 of::memory::MakeHostMemCase(), eager_blob_object->mem_case());
113 };
114 auto btb = std::make_shared<of::BlockingThenBusy>();
115 CHECK_JUST(of::PhysicalRun([&](of::InstructionsBuilder* builder) -> of::Maybe<void> {
116 return builder->SyncAccessBlobByCallback(local_tensor, btb, Callback, "const");
117 }));
118 TRY(btb->WaitUntilCntEqualZero(of::VirtualMachine::GetPredicatorNoMoreInstructionsFinished()))
119 .GetOrThrow();
120}
121
122const std::shared_ptr<oneflow::one::Tensor>& Tensor::__internal_tensor() const { return tensor_; }
123

Callers 5

ForwardFunction · 0.80
TESTFunction · 0.80
TESTFunction · 0.80
TestReluFunction · 0.80
TESTFunction · 0.80

Calls 11

shapeMethod · 0.95
AutoMemcpyFunction · 0.85
MakeHostMemCaseFunction · 0.85
PhysicalRunFunction · 0.85
GetPtrOrThrowMethod · 0.80
AsLocalTensorMethod · 0.45
mut_dptrMethod · 0.45
CountMethod · 0.45
GetOrThrowMethod · 0.45
WaitUntilCntEqualZeroMethod · 0.45

Tested by 5

ForwardFunction · 0.64
TESTFunction · 0.64
TESTFunction · 0.64
TestReluFunction · 0.64
TESTFunction · 0.64