| 116 | } |
| 117 | |
| 118 | Status MemoryManager::CopyBufferSliceToCPU(const std::shared_ptr<Buffer>& buf, |
| 119 | int64_t offset, int64_t length, |
| 120 | uint8_t* out_data) { |
| 121 | if (ARROW_PREDICT_TRUE(buf->is_cpu())) { |
| 122 | memcpy(out_data, buf->data() + offset, static_cast<size_t>(length)); |
| 123 | return Status::OK(); |
| 124 | } |
| 125 | |
| 126 | auto& from = buf->memory_manager(); |
| 127 | auto cpu_mm = default_cpu_memory_manager(); |
| 128 | // Try a view first |
| 129 | auto maybe_buffer_result = from->ViewBufferTo(buf, cpu_mm); |
| 130 | if (!COPY_BUFFER_SUCCESS(maybe_buffer_result)) { |
| 131 | // View failed, try a copy instead |
| 132 | maybe_buffer_result = from->CopyBufferTo(buf, cpu_mm); |
| 133 | } |
| 134 | ARROW_ASSIGN_OR_RAISE(auto maybe_buffer, std::move(maybe_buffer_result)); |
| 135 | if (maybe_buffer != nullptr) { |
| 136 | memcpy(out_data, maybe_buffer->data() + offset, static_cast<size_t>(length)); |
| 137 | return Status::OK(); |
| 138 | } |
| 139 | |
| 140 | return Status::NotImplemented("Copying buffer slice from ", from->device()->ToString(), |
| 141 | " to CPU not supported"); |
| 142 | } |
| 143 | |
| 144 | #undef COPY_BUFFER_RETURN |
| 145 | #undef COPY_BUFFER_SUCCESS |
nothing calls this directly
no test coverage detected