MCPcopy Create free account
hub / github.com/apache/arrow / CopyBuffer

Method CopyBuffer

cpp/src/arrow/device.cc:58–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 }
57
58Result<std::shared_ptr<Buffer>> MemoryManager::CopyBuffer(
59 const std::shared_ptr<Buffer>& buf, const std::shared_ptr<MemoryManager>& to) {
60 const auto& from = buf->memory_manager();
61 auto maybe_buffer = to->CopyBufferFrom(buf, from);
62 COPY_BUFFER_RETURN(maybe_buffer, to);
63 // `to` doesn't support copying from `from`, try the other way
64 maybe_buffer = from->CopyBufferTo(buf, to);
65 COPY_BUFFER_RETURN(maybe_buffer, to);
66 if (!from->is_cpu() && !to->is_cpu()) {
67 // Try an intermediate view on the CPU
68 auto cpu_mm = default_cpu_memory_manager();
69 maybe_buffer = from->ViewBufferTo(buf, cpu_mm);
70 if (!COPY_BUFFER_SUCCESS(maybe_buffer)) {
71 // View failed, try a copy instead
72 // XXX should we have a MemoryManager::IsCopySupportedTo(MemoryManager)
73 // to avoid copying to CPU if copy from CPU to dest is unsupported?
74 maybe_buffer = from->CopyBufferTo(buf, cpu_mm);
75 }
76 if (COPY_BUFFER_SUCCESS(maybe_buffer)) {
77 // Copy from source to CPU succeeded, now try to copy from CPU into dest
78 maybe_buffer = to->CopyBufferFrom(*maybe_buffer, cpu_mm);
79 if (COPY_BUFFER_SUCCESS(maybe_buffer)) {
80 return maybe_buffer;
81 }
82 }
83 }
84
85 return Status::NotImplemented("Copying buffer from ", from->device()->ToString(),
86 " to ", to->device()->ToString(), " not supported");
87}
88
89Result<std::unique_ptr<Buffer>> MemoryManager::CopyNonOwned(
90 const Buffer& buf, const std::shared_ptr<MemoryManager>& to) {

Callers

nothing calls this directly

Calls 8

NotImplementedFunction · 0.70
memory_managerMethod · 0.45
CopyBufferFromMethod · 0.45
CopyBufferToMethod · 0.45
ViewBufferToMethod · 0.45
ToStringMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected