| 102 | |
| 103 | template<typename T> |
| 104 | void 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 | |
| 122 | const std::shared_ptr<oneflow::one::Tensor>& Tensor::__internal_tensor() const { return tensor_; } |
| 123 | |