|
@@ -43,20 +43,10 @@ extern void _Py_CountReferences(FILE*);
|
|
|
|
|
|
|
|
|
static PyObject *asyncio_module;
|
|
|
-static PyObject *cloudpickle_module;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
static char* starpu_cloudpickle_dumps(PyObject *obj, PyObject **obj_bytes, Py_ssize_t *obj_data_size)
|
|
|
{
|
|
|
-
|
|
|
+ PyObject *cloudpickle_module = PyImport_ImportModule("cloudpickle");
|
|
|
PyObject *dumps = PyObject_GetAttrString(cloudpickle_module, "dumps");
|
|
|
*obj_bytes= PyObject_CallFunctionObjArgs(dumps, obj, NULL);
|
|
|
|
|
@@ -68,7 +58,7 @@ static char* starpu_cloudpickle_dumps(PyObject *obj, PyObject **obj_bytes, Py_ss
|
|
|
|
|
|
static PyObject* starpu_cloudpickle_loads(char* pyString, Py_ssize_t pyString_size)
|
|
|
{
|
|
|
-
|
|
|
+ PyObject *cloudpickle_module = PyImport_ImportModule("cloudpickle");
|
|
|
PyObject *loads = PyObject_GetAttrString(cloudpickle_module, "loads");
|
|
|
PyObject *obj_bytes_str = PyBytes_FromStringAndSize(pyString, pyString_size);
|
|
|
PyObject *obj = PyObject_CallFunctionObjArgs(loads, obj_bytes_str, NULL);
|
|
@@ -96,7 +86,7 @@ void prologue_cb_func(void *cl_arg)
|
|
|
struct starpu_codelet_pack_arg_data data_org;
|
|
|
starpu_codelet_unpack_arg_init(&data_org, &task->cl_arg, &task->cl_arg_size);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
starpu_codelet_pick_arg(&data_org, &func_data, &func_data_size);
|
|
|
|
|
|
starpu_codelet_unpack_arg(&data_org, &argList, sizeof(argList));
|
|
@@ -136,7 +126,6 @@ void prologue_cb_func(void *cl_arg)
|
|
|
char* arg_data = starpu_cloudpickle_dumps(argList, &arg_bytes, &arg_data_size);
|
|
|
starpu_codelet_pack_arg(&data, arg_data, arg_data_size);
|
|
|
Py_DECREF(arg_bytes);
|
|
|
-
|
|
|
|
|
|
starpu_codelet_pack_arg(&data, &fut, sizeof(fut));
|
|
|
|
|
@@ -160,6 +149,9 @@ void starpupy_codelet_func(void *buffers[], void *cl_arg)
|
|
|
Py_ssize_t arg_data_size;
|
|
|
PyObject *argList;
|
|
|
|
|
|
+
|
|
|
+ PyGILState_STATE state = PyGILState_Ensure();
|
|
|
+
|
|
|
|
|
|
|
|
|
struct starpu_task *task = starpu_task_get_current();
|
|
@@ -167,24 +159,10 @@ void starpupy_codelet_func(void *buffers[], void *cl_arg)
|
|
|
struct starpu_codelet_pack_arg_data data;
|
|
|
starpu_codelet_unpack_arg_init(&data, &task->cl_arg, &task->cl_arg_size);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
starpu_codelet_pick_arg(&data, &func_data, &func_data_size);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
starpu_codelet_pick_arg(&data, &arg_data, &arg_data_size);
|
|
|
-
|
|
|
|
|
|
starpu_codelet_unpack_discard_arg(&data);
|
|
|
|
|
@@ -192,9 +170,6 @@ void starpupy_codelet_func(void *buffers[], void *cl_arg)
|
|
|
|
|
|
starpu_codelet_unpack_discard_arg(&data);
|
|
|
|
|
|
-
|
|
|
- PyGILState_STATE state = PyGILState_Ensure();
|
|
|
-
|
|
|
|
|
|
PyObject *pFunc=starpu_cloudpickle_loads(func_data, func_data_size);
|
|
|
|
|
@@ -226,16 +201,19 @@ void starpupy_codelet_func(void *buffers[], void *cl_arg)
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
PyObject *rv = PyObject_CallObject(func_py, argList);
|
|
|
+
|
|
|
+
|
|
|
+ struct starpu_codelet_pack_arg_data data_ret;
|
|
|
+ starpu_codelet_pack_arg_init(&data_ret);
|
|
|
+
|
|
|
|
|
|
if (rv==Py_None)
|
|
|
{
|
|
|
char* rv_data=NULL;
|
|
|
Py_ssize_t rv_data_size=0;
|
|
|
- starpu_codelet_pack_arg(&data, &rv_data_size, sizeof(rv_data_size));
|
|
|
- starpu_codelet_pack_arg(&data, &rv_data, sizeof(rv_data));
|
|
|
+ starpu_codelet_pack_arg(&data_ret, &rv_data_size, sizeof(rv_data_size));
|
|
|
+ starpu_codelet_pack_arg(&data_ret, &rv_data, sizeof(rv_data));
|
|
|
}
|
|
|
|
|
|
else
|
|
@@ -243,15 +221,13 @@ void starpupy_codelet_func(void *buffers[], void *cl_arg)
|
|
|
Py_ssize_t rv_data_size;
|
|
|
PyObject *rv_bytes;
|
|
|
char* rv_data = starpu_cloudpickle_dumps(rv, &rv_bytes, &rv_data_size);
|
|
|
- starpu_codelet_pack_arg(&data, &rv_data_size, sizeof(rv_data_size));
|
|
|
- starpu_codelet_pack_arg(&data, rv_data, rv_data_size);
|
|
|
+ starpu_codelet_pack_arg(&data_ret, &rv_data_size, sizeof(rv_data_size));
|
|
|
+ starpu_codelet_pack_arg(&data_ret, rv_data, rv_data_size);
|
|
|
Py_DECREF(rv_bytes);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- starpu_codelet_pack_arg_fini(&data, &task->cl_arg, &task->cl_arg_size);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ starpu_codelet_pack_arg_fini(&data_ret, &task->cl_ret, &task->cl_ret_size);
|
|
|
|
|
|
Py_DECREF(func_py);
|
|
|
Py_DECREF(argList);
|
|
@@ -269,17 +245,18 @@ void cb_func(void *v)
|
|
|
Py_ssize_t rv_data_size;
|
|
|
PyObject *rv;
|
|
|
|
|
|
+
|
|
|
+ PyGILState_STATE state = PyGILState_Ensure();
|
|
|
+
|
|
|
struct starpu_task *task = starpu_task_get_current();
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
struct starpu_codelet_pack_arg_data data;
|
|
|
starpu_codelet_unpack_arg_init(&data, &task->cl_arg, &task->cl_arg_size);
|
|
|
|
|
|
|
|
|
-
|
|
|
starpu_codelet_unpack_discard_arg(&data);
|
|
|
|
|
|
-
|
|
|
starpu_codelet_unpack_discard_arg(&data);
|
|
|
|
|
|
starpu_codelet_unpack_arg(&data, &fut, sizeof(fut));
|
|
@@ -287,26 +264,23 @@ void cb_func(void *v)
|
|
|
starpu_codelet_unpack_arg(&data, &loop, sizeof(loop));
|
|
|
|
|
|
starpu_codelet_unpack_discard_arg(&data);
|
|
|
-
|
|
|
- starpu_codelet_unpack_arg(&data, &rv_data_size, sizeof(rv_data_size));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-
|
|
|
- PyGILState_STATE state = PyGILState_Ensure();
|
|
|
+
|
|
|
+ struct starpu_codelet_pack_arg_data data_ret;
|
|
|
+ starpu_codelet_unpack_arg_init(&data_ret, &task->cl_ret, &task->cl_ret_size);
|
|
|
+
|
|
|
+ starpu_codelet_unpack_arg(&data_ret, &rv_data_size, sizeof(rv_data_size));
|
|
|
|
|
|
|
|
|
if (rv_data_size==0)
|
|
|
{
|
|
|
+ starpu_codelet_unpack_discard_arg(&data_ret);
|
|
|
rv=Py_None;
|
|
|
}
|
|
|
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- starpu_codelet_pick_arg(&data, &rv_data, &rv_data_size);
|
|
|
+ starpu_codelet_pick_arg(&data_ret, &rv_data, &rv_data_size);
|
|
|
rv=starpu_cloudpickle_loads(rv_data, rv_data_size);
|
|
|
}
|
|
|
|
|
@@ -319,9 +293,7 @@ void cb_func(void *v)
|
|
|
Py_DECREF(rv);
|
|
|
Py_DECREF(fut);
|
|
|
Py_DECREF(loop);
|
|
|
-
|
|
|
|
|
|
-
|
|
|
struct starpu_codelet *func_cl=(struct starpu_codelet *) task->cl;
|
|
|
if (func_cl->model != NULL)
|
|
|
{
|
|
@@ -362,7 +334,7 @@ static PyObject *PyTask_FromTask(struct starpu_task *task)
|
|
|
static size_t sizebase (struct starpu_task *task, unsigned nimpl)
|
|
|
{
|
|
|
int sb;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
struct starpu_codelet_pack_arg_data data;
|
|
|
starpu_codelet_unpack_arg_init(&data, &task->cl_arg, &task->cl_arg_size);
|
|
@@ -379,10 +351,6 @@ static size_t sizebase (struct starpu_task *task, unsigned nimpl)
|
|
|
starpu_codelet_unpack_discard_arg(&data);
|
|
|
|
|
|
starpu_codelet_unpack_arg(&data, &sb, sizeof(sb));
|
|
|
-
|
|
|
- starpu_codelet_unpack_discard_arg(&data);
|
|
|
- starpu_codelet_unpack_discard_arg(&data);
|
|
|
-
|
|
|
|
|
|
return sb;
|
|
|
}
|
|
@@ -512,12 +480,6 @@ static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args)
|
|
|
Py_INCREF(perfmodel);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
struct starpu_codelet_pack_arg_data data;
|
|
|
starpu_codelet_pack_arg_init(&data);
|
|
@@ -539,14 +501,13 @@ static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args)
|
|
|
Py_INCREF(PyTuple_GetItem(argList, i));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
Py_ssize_t func_data_size;
|
|
|
PyObject *func_bytes;
|
|
|
char* func_data = starpu_cloudpickle_dumps(func_py, &func_bytes, &func_data_size);
|
|
|
starpu_codelet_pack_arg(&data, func_data, func_data_size);
|
|
|
Py_DECREF(func_bytes);
|
|
|
-
|
|
|
|
|
|
starpu_codelet_pack_arg(&data, &argList, sizeof(argList));
|
|
|
|
|
@@ -555,7 +516,6 @@ static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args)
|
|
|
starpu_codelet_pack_arg(&data, &loop, sizeof(loop));
|
|
|
|
|
|
task->cl=func_cl;
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -703,6 +663,17 @@ static PyObject* starpu_task_nsubmitted_wrapper(PyObject *self, PyObject *args)
|
|
|
|
|
|
return Py_BuildValue("i", num_task);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+static PyObject* starpu_shutdown_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
+
|
|
|
+ starpu_shutdown();
|
|
|
+
|
|
|
+
|
|
|
+ Py_INCREF(Py_None);
|
|
|
+ return Py_None;
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
@@ -720,6 +691,7 @@ static PyMethodDef starpupyMethods[] =
|
|
|
{"sched_get_min_priority", starpu_sched_get_min_priority_wrapper, METH_VARARGS, "get the number of min priority"},
|
|
|
{"sched_get_max_priority", starpu_sched_get_max_priority_wrapper, METH_VARARGS, "get the number of max priority"},
|
|
|
{"task_nsubmitted", starpu_task_nsubmitted_wrapper, METH_VARARGS, "get the number of submitted tasks which have not completed yet"},
|
|
|
+ {"shutdown", starpu_shutdown_wrapper, METH_VARARGS, "shutdown starpu"},
|
|
|
{NULL, NULL}
|
|
|
};
|
|
|
|
|
@@ -750,13 +722,15 @@ PyMODINIT_FUNC
|
|
|
PyInit_starpupy(void)
|
|
|
{
|
|
|
PyEval_InitThreads();
|
|
|
+
|
|
|
+ Py_BEGIN_ALLOW_THREADS
|
|
|
|
|
|
int ret = starpu_init(NULL);
|
|
|
assert(ret==0);
|
|
|
+ Py_END_ALLOW_THREADS
|
|
|
+
|
|
|
|
|
|
asyncio_module = PyImport_ImportModule("asyncio");
|
|
|
-
|
|
|
- cloudpickle_module = PyImport_ImportModule("cloudpickle");
|
|
|
|
|
|
#ifdef STARPU_PYTHON_HAVE_NUMPY
|
|
|
|