Compute task IDs and object IDs deterministically. (#31)

* Put infrastructure in place to compute task IDs and object IDs.

* Fix version number for common library.

* Compute task IDs and object IDs deterministically.

* Address Stephanie's comments.

* Update task documentation.

* Fix formatting.

* Add more tests and checks.

* Fix formatting.

* Enable DCHECKs and change CHECKs to DCHECKs.
This commit is contained in:
Robert Nishihara
2016-11-08 14:46:34 -08:00
committed by Philipp Moritz
parent 90f88af902
commit 194bdb1d96
15 changed files with 691 additions and 113 deletions
+21 -14
View File
@@ -120,8 +120,13 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
UT_array *val_repr_ptrs;
utarray_new(val_repr_ptrs, &ut_ptr_icd);
int num_returns;
if (!PyArg_ParseTuple(args, "O&Oi", &PyObjectToUniqueID, &function_id,
&arguments, &num_returns)) {
/* The ID of the task that called this task. */
task_id parent_task_id;
/* The number of tasks that the parent task has called prior to this one. */
int parent_counter;
if (!PyArg_ParseTuple(args, "O&OiO&i", &PyObjectToUniqueID, &function_id,
&arguments, &num_returns, &PyObjectToUniqueID,
&parent_task_id, &parent_counter)) {
return -1;
}
size_t size = PyList_Size(arguments);
@@ -138,7 +143,8 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
/* Construct the task specification. */
int val_repr_index = 0;
self->spec =
alloc_task_spec(function_id, size, num_returns, value_data_bytes);
start_construct_task_spec(parent_task_id, parent_counter, function_id,
size, num_returns, value_data_bytes);
/* Add the task arguments. */
for (size_t i = 0; i < size; ++i) {
PyObject *arg = PyList_GetItem(arguments, i);
@@ -154,14 +160,8 @@ static int PyTask_init(PyTask *self, PyObject *args, PyObject *kwds) {
}
}
utarray_free(val_repr_ptrs);
/* Generate and add the object IDs for the return values. */
for (size_t i = 0; i < num_returns; ++i) {
/* TODO(rkn): Later, this should be computed as a deterministic hash of (1)
* the contents of the task, (2) the index i, and (3) a counter of the
* number of tasks launched so far by the parent task. For now, we generate
* it randomly. */
*task_return(self->spec, i) = globally_unique_id();
}
/* Compute the task ID and the return object IDs. */
finish_construct_task_spec(self->spec);
return 0;
}
@@ -171,17 +171,22 @@ static void PyTask_dealloc(PyTask *self) {
}
static PyObject *PyTask_function_id(PyObject *self) {
function_id function_id = *task_function(((PyTask *) self)->spec);
function_id function_id = task_function(((PyTask *) self)->spec);
return PyObjectID_make(function_id);
}
static PyObject *PyTask_task_id(PyObject *self) {
task_id task_id = task_task_id(((PyTask *) self)->spec);
return PyObjectID_make(task_id);
}
static PyObject *PyTask_arguments(PyObject *self) {
int64_t num_args = task_num_args(((PyTask *) self)->spec);
PyObject *arg_list = PyList_New((Py_ssize_t) num_args);
task_spec *task = ((PyTask *) self)->spec;
for (int i = 0; i < num_args; ++i) {
if (task_arg_type(task, i) == ARG_BY_REF) {
object_id object_id = *task_arg_id(task, i);
object_id object_id = task_arg_id(task, i);
PyList_SetItem(arg_list, i, PyObjectID_make(object_id));
} else {
PyObject *s =
@@ -198,7 +203,7 @@ static PyObject *PyTask_returns(PyObject *self) {
PyObject *return_id_list = PyList_New((Py_ssize_t) num_returns);
task_spec *task = ((PyTask *) self)->spec;
for (int i = 0; i < num_returns; ++i) {
object_id object_id = *task_return(task, i);
object_id object_id = task_return(task, i);
PyList_SetItem(return_id_list, i, PyObjectID_make(object_id));
}
return return_id_list;
@@ -207,6 +212,8 @@ static PyObject *PyTask_returns(PyObject *self) {
static PyMethodDef PyTask_methods[] = {
{"function_id", (PyCFunction) PyTask_function_id, METH_NOARGS,
"Return the function ID for this task."},
{"task_id", (PyCFunction) PyTask_task_id, METH_NOARGS,
"Return the task ID for this task."},
{"arguments", (PyCFunction) PyTask_arguments, METH_NOARGS,
"Return the arguments for the task."},
{"returns", (PyCFunction) PyTask_returns, METH_NOARGS,
+1 -1
View File
@@ -7,6 +7,6 @@ common_module = Extension("common",
extra_compile_args=["--std=c99", "-Werror"])
setup(name="Common",
version="0.1",
version="0.01",
description="Common library for Ray",
ext_modules=[common_module])