Skip to content

Commit 43938db

Browse files
committed
zero copy for batch_get_tensor()
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
1 parent 577f675 commit 43938db

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

mooncake-integration/store/store_py.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,29 +227,18 @@ class MooncakeStorePyWrapper {
227227
py::gil_scoped_acquire acquire_gil;
228228
auto torch = torch_module();
229229

230+
int i = 0;
230231
for (const auto &buffer_handle : buffer_handles) {
231-
if (!buffer_handle) {
232-
results_list.append(py::none());
233-
continue;
234-
}
235-
236-
auto total_length = buffer_handle->size();
237-
if (total_length <= sizeof(TensorMetadata)) {
238-
LOG(ERROR) << "Invalid data format: insufficient data for "
239-
"metadata";
240-
results_list.append(py::none());
241-
continue;
242-
}
243-
244-
char *exported_data = new char[total_length];
245-
if (!exported_data) {
246-
LOG(ERROR) << "Failed to allocate memory for tensor data";
232+
uint64_t total_length = 0;
233+
auto get_result = store_->get_allocated_internal(keys[i++], total_length);
234+
if (!get_result) {
247235
results_list.append(py::none());
248236
continue;
249237
}
250238

251-
memcpy(exported_data, buffer_handle->ptr(), total_length);
239+
auto exported_data = *get_result;
252240

241+
// Copy metadata from buffer
253242
TensorMetadata metadata;
254243
memcpy(&metadata, exported_data, sizeof(TensorMetadata));
255244

0 commit comments

Comments
 (0)