mirror of
https://github.com/wassname/ray.git
synced 2026-09-11 12:43:20 +08:00
cleanup serialization code (#291)
This commit is contained in:
committed by
Robert Nishihara
parent
4a0f35b042
commit
5591aa4665
+1
-46
@@ -6,9 +6,6 @@
|
||||
#include <structmember.h>
|
||||
#define PY_ARRAY_UNIQUE_SYMBOL RAYLIB_ARRAY_API
|
||||
#include <numpy/arrayobject.h>
|
||||
#ifndef __APPLE__
|
||||
#include <arrow/api.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
#include "types.pb.h"
|
||||
@@ -482,23 +479,6 @@ static PyObject* serialize_object(PyObject* self, PyObject* args) {
|
||||
return t;
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
static PyObject* put_arrow(PyObject* self, PyObject* args) {
|
||||
Worker* worker;
|
||||
ObjRef objref;
|
||||
PyObject* value;
|
||||
if (!PyArg_ParseTuple(args, "O&O&O", &PyObjectToWorker, &worker, &PyObjectToObjRef, &objref, &value)) {
|
||||
return NULL;
|
||||
}
|
||||
// The following is reqired, because numbuf expects contiguous arrays at the moment.
|
||||
// This is to make sure that we do not have to do reference counting inside numbuf, it is expected to change.
|
||||
PyArrayObject* array = PyArray_GETCONTIGUOUS((PyArrayObject*) value); // TODO(pcm): put that into numbuf
|
||||
worker->put_arrow(objref, (PyObject*) array);
|
||||
Py_XDECREF(array); // GETCONTIGUOUS from above returned a new reference
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject* allocate_buffer(PyObject* self, PyObject* args) {
|
||||
Worker* worker;
|
||||
ObjRef objref;
|
||||
@@ -536,7 +516,7 @@ static PyObject* get_buffer(PyObject* self, PyObject* args) {
|
||||
return NULL;
|
||||
}
|
||||
void* address = reinterpret_cast<void*>(const_cast<char*>(worker->get_buffer(objref, size, segmentid, metadata_offset)));
|
||||
std::vector<npy_intp> dim({size});
|
||||
std::vector<npy_intp> dim({static_cast<npy_intp>(size)});
|
||||
PyObject* t = PyTuple_New(3);
|
||||
PyTuple_SetItem(t, 0, PyArray_SimpleNewFromData(1, dim.data(), NPY_BYTE, address));
|
||||
PyTuple_SetItem(t, 1, PyInt_FromLong(segmentid));
|
||||
@@ -544,25 +524,6 @@ static PyObject* get_buffer(PyObject* self, PyObject* args) {
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
#ifndef __APPLE__
|
||||
|
||||
static PyObject* get_arrow(PyObject* self, PyObject* args) {
|
||||
Worker* worker;
|
||||
ObjRef objref;
|
||||
if (!PyArg_ParseTuple(args, "O&O&", &PyObjectToWorker, &worker, &PyObjectToObjRef, &objref)) {
|
||||
return NULL;
|
||||
}
|
||||
SegmentId segmentid;
|
||||
PyObject* value = worker->get_arrow(objref, segmentid);
|
||||
PyObject* val_and_segmentid = PyList_New(2);
|
||||
PyList_SetItem(val_and_segmentid, 0, value);
|
||||
PyList_SetItem(val_and_segmentid, 1, PyInt_FromLong(segmentid));
|
||||
return val_and_segmentid;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static PyObject* is_arrow(PyObject* self, PyObject* args) {
|
||||
Worker* worker;
|
||||
ObjRef objref;
|
||||
@@ -1009,15 +970,9 @@ static PyObject* kill_workers(PyObject* self, PyObject* args) {
|
||||
static PyMethodDef RayLibMethods[] = {
|
||||
{ "serialize_object", serialize_object, METH_VARARGS, "serialize an object to protocol buffers" },
|
||||
{ "deserialize_object", deserialize_object, METH_VARARGS, "deserialize an object from protocol buffers" },
|
||||
#ifndef __APPLE__
|
||||
{ "put_arrow", put_arrow, METH_VARARGS, "put an arrow array on the local object store"},
|
||||
#endif
|
||||
{ "allocate_buffer", allocate_buffer, METH_VARARGS, "Allocates and returns buffer for objref."},
|
||||
{ "finish_buffer", finish_buffer, METH_VARARGS, "Makes the buffer immutable and closes memory segment of objref."},
|
||||
{ "get_buffer", get_buffer, METH_VARARGS, "Gets buffer for objref"},
|
||||
#ifndef __APPLE__
|
||||
{ "get_arrow", get_arrow, METH_VARARGS, "get an arrow array from the local object store"},
|
||||
#endif
|
||||
{ "is_arrow", is_arrow, METH_VARARGS, "is the object in the local object store an arrow object?"},
|
||||
{ "unmap_object", unmap_object, METH_VARARGS, "unmap the object from the client's shared memory pool"},
|
||||
{ "serialize_task", serialize_task, METH_VARARGS, "serialize a task to protocol buffers" },
|
||||
|
||||
Reference in New Issue
Block a user