| 82 | } |
| 83 | |
| 84 | Tensor 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 | |
| 103 | template<typename T> |
| 104 | void Tensor::copy_to(T* buffer) const { |
nothing calls this directly
no test coverage detected