|
@@ -37,374 +37,391 @@ extern void _Py_CountReferences(FILE*);
|
|
|
|
|
|
|
|
|
|
|
|
-static PyObject* asyncio_module;
|
|
|
+static PyObject *asyncio_module;
|
|
|
|
|
|
|
|
|
-struct codelet_struct {
|
|
|
- PyObject* f;
|
|
|
- PyObject* argList;
|
|
|
- PyObject* rv;
|
|
|
- PyObject* fut;
|
|
|
- PyObject* lp;
|
|
|
+struct codelet_args
|
|
|
+{
|
|
|
+ PyObject *f;
|
|
|
+ PyObject *argList;
|
|
|
+ PyObject *rv;
|
|
|
+ PyObject *fut;
|
|
|
+ PyObject *lp;
|
|
|
};
|
|
|
-typedef struct codelet_struct codelet_st;
|
|
|
|
|
|
|
|
|
-void codelet_func(void *buffers[], void *cl_arg){
|
|
|
-
|
|
|
- codelet_st* cst = (codelet_st*) cl_arg;
|
|
|
-
|
|
|
-
|
|
|
- PyGILState_STATE state = PyGILState_Ensure();
|
|
|
-
|
|
|
-
|
|
|
- if (!PyCallable_Check(cst->f)) {
|
|
|
-
|
|
|
- printf("py_callback: expected a callable function\n");
|
|
|
- exit(1);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for (int i=0; i < PyTuple_Size(cst->argList); i++){
|
|
|
- PyObject* obj=PyTuple_GetItem(cst->argList, i);
|
|
|
- const char* tp = Py_TYPE(obj)->tp_name;
|
|
|
- if(strcmp(tp, "_asyncio.Future") == 0){
|
|
|
-
|
|
|
- PyObject * fut_result = PyObject_CallMethod(obj, "result", NULL);
|
|
|
-
|
|
|
- PyTuple_SetItem(cst->argList, i, fut_result);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- PyObject *pRetVal = PyObject_CallObject(cst->f, cst->argList);
|
|
|
- cst->rv=pRetVal;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- PyGILState_Release(state);
|
|
|
-
|
|
|
+void codelet_func(void *buffers[], void *cl_arg)
|
|
|
+{
|
|
|
+ struct codelet_args *cst = (struct codelet_args*) cl_arg;
|
|
|
+
|
|
|
+
|
|
|
+ PyGILState_STATE state = PyGILState_Ensure();
|
|
|
+
|
|
|
+
|
|
|
+ if (!PyCallable_Check(cst->f))
|
|
|
+ {
|
|
|
+ printf("py_callback: expected a callable function\n");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i=0; i < PyTuple_Size(cst->argList); i++)
|
|
|
+ {
|
|
|
+ PyObject *obj = PyTuple_GetItem(cst->argList, i);
|
|
|
+ const char *tp = Py_TYPE(obj)->tp_name;
|
|
|
+ if(strcmp(tp, "_asyncio.Future") == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ PyObject *fut_result = PyObject_CallMethod(obj, "result", NULL);
|
|
|
+
|
|
|
+ PyTuple_SetItem(cst->argList, i, fut_result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *pRetVal = PyObject_CallObject(cst->f, cst->argList);
|
|
|
+ cst->rv = pRetVal;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ PyGILState_Release(state);
|
|
|
}
|
|
|
|
|
|
|
|
|
-void cb_func(void *v){
|
|
|
-
|
|
|
- struct starpu_task *task=starpu_task_get_current();
|
|
|
- codelet_st* cst = (codelet_st*) task->cl_arg;
|
|
|
-
|
|
|
-
|
|
|
- PyGILState_STATE state = PyGILState_Ensure();
|
|
|
-
|
|
|
-
|
|
|
- PyObject * set_result = PyObject_GetAttrString(cst->fut, "set_result");
|
|
|
- PyObject * loop_callback = PyObject_CallMethod(cst->lp, "call_soon_threadsafe", "(O,O)", set_result, cst->rv);
|
|
|
-
|
|
|
- Py_DECREF(loop_callback);
|
|
|
- Py_DECREF(set_result);
|
|
|
- Py_DECREF(cst->rv);
|
|
|
- Py_DECREF(cst->fut);
|
|
|
- Py_DECREF(cst->lp);
|
|
|
-
|
|
|
-
|
|
|
- struct starpu_codelet * func_cl=(struct starpu_codelet *) task->cl;
|
|
|
- if (func_cl->model != NULL){
|
|
|
- struct starpu_perfmodel *perf =(struct starpu_perfmodel *) func_cl->model;
|
|
|
- PyObject* perfmodel=PyCapsule_New(perf, "Perf", 0);
|
|
|
- Py_DECREF(perfmodel);
|
|
|
- }
|
|
|
-
|
|
|
- for(int i = 0; i < PyTuple_Size(cst->argList); i++){
|
|
|
- Py_DECREF(PyTuple_GetItem(cst->argList, i));
|
|
|
- }
|
|
|
- Py_DECREF(cst->argList);
|
|
|
-
|
|
|
-
|
|
|
- PyGILState_Release(state);
|
|
|
-
|
|
|
-
|
|
|
- free(task->cl);
|
|
|
- free(task->cl_arg);
|
|
|
- if (task->name!=NULL){
|
|
|
- free(task->name);
|
|
|
- }
|
|
|
-
|
|
|
+void cb_func(void *v)
|
|
|
+{
|
|
|
+ struct starpu_task *task = starpu_task_get_current();
|
|
|
+ struct codelet_args *cst = (struct codelet_args*) task->cl_arg;
|
|
|
+
|
|
|
+
|
|
|
+ PyGILState_STATE state = PyGILState_Ensure();
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *set_result = PyObject_GetAttrString(cst->fut, "set_result");
|
|
|
+ PyObject *loop_callback = PyObject_CallMethod(cst->lp, "call_soon_threadsafe", "(O,O)", set_result, cst->rv);
|
|
|
+
|
|
|
+ Py_DECREF(loop_callback);
|
|
|
+ Py_DECREF(set_result);
|
|
|
+ Py_DECREF(cst->rv);
|
|
|
+ Py_DECREF(cst->fut);
|
|
|
+ Py_DECREF(cst->lp);
|
|
|
+
|
|
|
+
|
|
|
+ struct starpu_codelet *func_cl=(struct starpu_codelet *) task->cl;
|
|
|
+ if (func_cl->model != NULL)
|
|
|
+ {
|
|
|
+ struct starpu_perfmodel *perf =(struct starpu_perfmodel *) func_cl->model;
|
|
|
+ PyObject *perfmodel=PyCapsule_New(perf, "Perf", 0);
|
|
|
+ Py_DECREF(perfmodel);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(int i = 0; i < PyTuple_Size(cst->argList); i++)
|
|
|
+ {
|
|
|
+ Py_DECREF(PyTuple_GetItem(cst->argList, i));
|
|
|
+ }
|
|
|
+ Py_DECREF(cst->argList);
|
|
|
+
|
|
|
+
|
|
|
+ PyGILState_Release(state);
|
|
|
+
|
|
|
+
|
|
|
+ free(task->cl);
|
|
|
+ free(task->cl_arg);
|
|
|
+ if (task->name!=NULL)
|
|
|
+ {
|
|
|
+ free(task->name);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-static struct starpu_task *PyTask_AsTask(PyObject* obj){
|
|
|
- return (struct starpu_task *) PyCapsule_GetPointer(obj, "Task");
|
|
|
+static struct starpu_task *PyTask_AsTask(PyObject *obj)
|
|
|
+{
|
|
|
+ return (struct starpu_task *) PyCapsule_GetPointer(obj, "Task");
|
|
|
}
|
|
|
|
|
|
|
|
|
-static void del_Task(PyObject *obj) {
|
|
|
- struct starpu_task* obj_task=PyTask_AsTask(obj);
|
|
|
- obj_task->destroy=1;
|
|
|
+static void del_Task(PyObject *obj)
|
|
|
+{
|
|
|
+ struct starpu_task *obj_task=PyTask_AsTask(obj);
|
|
|
+ obj_task->destroy=1;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject *PyTask_FromTask(struct starpu_task *task) {
|
|
|
- return PyCapsule_New(task, "Task", del_Task);
|
|
|
+static PyObject *PyTask_FromTask(struct starpu_task *task)
|
|
|
+{
|
|
|
+ return PyCapsule_New(task, "Task", del_Task);
|
|
|
}
|
|
|
|
|
|
|
|
|
-static size_t sizebase (struct starpu_task * task, unsigned nimpl){
|
|
|
-
|
|
|
- codelet_st* cst = (codelet_st*) task->cl_arg;
|
|
|
+static size_t sizebase (struct starpu_task *task, unsigned nimpl)
|
|
|
+{
|
|
|
+ struct codelet_args *cst = (struct codelet_args*) task->cl_arg;
|
|
|
|
|
|
- PyObject* obj=PyTuple_GetItem(cst->argList, 0);
|
|
|
-
|
|
|
- int n = PyList_Size(obj);
|
|
|
+ PyObject *obj=PyTuple_GetItem(cst->argList, 0);
|
|
|
+
|
|
|
+ int n = PyList_Size(obj);
|
|
|
|
|
|
- return n;
|
|
|
+ return n;
|
|
|
}
|
|
|
|
|
|
-static void del_Perf(PyObject *obj){
|
|
|
- struct starpu_perfmodel *perf=(struct starpu_perfmodel*)PyCapsule_GetPointer(obj, "Perf");
|
|
|
- free(perf);
|
|
|
+static void del_Perf(PyObject *obj)
|
|
|
+{
|
|
|
+ struct starpu_perfmodel *perf=(struct starpu_perfmodel*)PyCapsule_GetPointer(obj, "Perf");
|
|
|
+ free(perf);
|
|
|
}
|
|
|
-
|
|
|
-static PyObject* init_perfmodel(PyObject *self, PyObject *args){
|
|
|
|
|
|
- char* sym;
|
|
|
+
|
|
|
+static PyObject* init_perfmodel(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
+ char *sym;
|
|
|
|
|
|
- if (!PyArg_ParseTuple(args, "s", &sym))
|
|
|
- return NULL;
|
|
|
+ if (!PyArg_ParseTuple(args, "s", &sym))
|
|
|
+ return NULL;
|
|
|
|
|
|
-
|
|
|
- struct starpu_perfmodel *perf=(struct starpu_perfmodel*)calloc(1, sizeof(struct starpu_perfmodel));
|
|
|
+
|
|
|
+ struct starpu_perfmodel *perf=(struct starpu_perfmodel*)calloc(1, sizeof(struct starpu_perfmodel));
|
|
|
|
|
|
-
|
|
|
- char* p =strdup(sym);
|
|
|
- perf->symbol=p;
|
|
|
- perf->type=STARPU_HISTORY_BASED;
|
|
|
+
|
|
|
+ char *p =strdup(sym);
|
|
|
+ perf->symbol=p;
|
|
|
+ perf->type=STARPU_HISTORY_BASED;
|
|
|
|
|
|
-
|
|
|
- PyObject *perfmodel=PyCapsule_New(perf, "Perf", NULL);
|
|
|
+
|
|
|
+ PyObject *perfmodel=PyCapsule_New(perf, "Perf", NULL);
|
|
|
|
|
|
- return perfmodel;
|
|
|
+ return perfmodel;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
-static PyObject* free_perfmodel(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
- PyObject* perfmodel;
|
|
|
- if (!PyArg_ParseTuple(args, "O", &perfmodel))
|
|
|
- return NULL;
|
|
|
+static PyObject* free_perfmodel(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
+ PyObject *perfmodel;
|
|
|
+ if (!PyArg_ParseTuple(args, "O", &perfmodel))
|
|
|
+ return NULL;
|
|
|
|
|
|
-
|
|
|
- struct starpu_perfmodel *perf=PyCapsule_GetPointer(perfmodel, "Perf");
|
|
|
+
|
|
|
+ struct starpu_perfmodel *perf=PyCapsule_GetPointer(perfmodel, "Perf");
|
|
|
|
|
|
- starpu_save_history_based_model(perf);
|
|
|
-
|
|
|
- free(perf->symbol);
|
|
|
- starpu_perfmodel_deinit(perf);
|
|
|
- free(perf);
|
|
|
+ starpu_save_history_based_model(perf);
|
|
|
+
|
|
|
+
|
|
|
+ starpu_perfmodel_deinit(perf);
|
|
|
+ free(perf);
|
|
|
|
|
|
-
|
|
|
- Py_INCREF(Py_None);
|
|
|
- return Py_None;
|
|
|
+
|
|
|
+ Py_INCREF(Py_None);
|
|
|
+ return Py_None;
|
|
|
}
|
|
|
|
|
|
-static PyObject* starpu_save_history_based_model_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
- PyObject* perfmodel;
|
|
|
- if (!PyArg_ParseTuple(args, "O", &perfmodel))
|
|
|
- return NULL;
|
|
|
+static PyObject* starpu_save_history_based_model_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
+ PyObject *perfmodel;
|
|
|
+ if (!PyArg_ParseTuple(args, "O", &perfmodel))
|
|
|
+ return NULL;
|
|
|
|
|
|
-
|
|
|
- struct starpu_perfmodel *perf=PyCapsule_GetPointer(perfmodel, "Perf");
|
|
|
+
|
|
|
+ struct starpu_perfmodel *perf=PyCapsule_GetPointer(perfmodel, "Perf");
|
|
|
|
|
|
- starpu_save_history_based_model(perf);
|
|
|
+ starpu_save_history_based_model(perf);
|
|
|
|
|
|
-
|
|
|
- Py_INCREF(Py_None);
|
|
|
- return Py_None;
|
|
|
+
|
|
|
+ Py_INCREF(Py_None);
|
|
|
+ return Py_None;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
-
|
|
|
- PyObject* loop = PyObject_CallMethod(asyncio_module, "get_running_loop", NULL);
|
|
|
-
|
|
|
- PyObject* fut = PyObject_CallMethod(loop, "create_future", NULL);
|
|
|
-
|
|
|
-
|
|
|
- PyObject* func_py = PyTuple_GetItem(args, 0);
|
|
|
- Py_INCREF(func_py);
|
|
|
-
|
|
|
-
|
|
|
- struct starpu_task *task=starpu_task_create();
|
|
|
- task->destroy=0;
|
|
|
-
|
|
|
- PyObject* PyTask=PyTask_FromTask(task);
|
|
|
-
|
|
|
-
|
|
|
- PyObject_SetAttrString(fut, "starpu_task", PyTask);
|
|
|
-
|
|
|
- for (int i=1; i < PyTuple_Size(args)-1; i++){
|
|
|
- PyObject* obj=PyTuple_GetItem(args, i);
|
|
|
- const char* tp = Py_TYPE(obj)->tp_name;
|
|
|
- if(strcmp(tp, "_asyncio.Future") == 0){
|
|
|
-
|
|
|
- PyObject* fut_task=PyObject_GetAttrString(obj, "starpu_task");
|
|
|
-
|
|
|
- starpu_task_declare_deps(task, 1, PyTask_AsTask(fut_task));
|
|
|
-
|
|
|
- Py_DECREF(fut_task);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- struct starpu_codelet *func_cl=(struct starpu_codelet*)malloc(sizeof(struct starpu_codelet));
|
|
|
-
|
|
|
- starpu_codelet_init(func_cl);
|
|
|
- func_cl->cpu_func=&codelet_func;
|
|
|
-
|
|
|
-
|
|
|
- PyObject* dict_option = PyTuple_GetItem(args, PyTuple_Size(args)-1);
|
|
|
- PyObject* perfmodel = PyDict_GetItemString(dict_option, "perfmodel");
|
|
|
- const char* tp_perf = Py_TYPE(perfmodel)->tp_name;
|
|
|
- if (strcmp(tp_perf, "PyCapsule")==0){
|
|
|
-
|
|
|
- struct starpu_perfmodel *perf=PyCapsule_GetPointer(perfmodel, "Perf");
|
|
|
- func_cl->model=perf;
|
|
|
- Py_INCREF(perfmodel);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- codelet_st *cst = (codelet_st*)malloc(sizeof(codelet_st));
|
|
|
- cst->f = func_py;
|
|
|
- cst->fut = fut;
|
|
|
- cst->lp = loop;
|
|
|
-
|
|
|
- Py_INCREF(fut);
|
|
|
- Py_INCREF(loop);
|
|
|
-
|
|
|
-
|
|
|
+static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
+
|
|
|
+ PyObject *loop = PyObject_CallMethod(asyncio_module, "get_running_loop", NULL);
|
|
|
+
|
|
|
+ PyObject *fut = PyObject_CallMethod(loop, "create_future", NULL);
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *func_py = PyTuple_GetItem(args, 0);
|
|
|
+ Py_INCREF(func_py);
|
|
|
+
|
|
|
+
|
|
|
+ struct starpu_task *task=starpu_task_create();
|
|
|
+ task->destroy=0;
|
|
|
+
|
|
|
+ PyObject *PyTask=PyTask_FromTask(task);
|
|
|
+
|
|
|
+
|
|
|
+ PyObject_SetAttrString(fut, "starpu_task", PyTask);
|
|
|
+
|
|
|
+ for (int i=1; i < PyTuple_Size(args)-1; i++)
|
|
|
+ {
|
|
|
+ PyObject *obj=PyTuple_GetItem(args, i);
|
|
|
+ const char* tp = Py_TYPE(obj)->tp_name;
|
|
|
+ if(strcmp(tp, "_asyncio.Future") == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ PyObject *fut_task=PyObject_GetAttrString(obj, "starpu_task");
|
|
|
+
|
|
|
+ starpu_task_declare_deps(task, 1, PyTask_AsTask(fut_task));
|
|
|
+
|
|
|
+ Py_DECREF(fut_task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ struct starpu_codelet *func_cl=(struct starpu_codelet*)malloc(sizeof(struct starpu_codelet));
|
|
|
+
|
|
|
+ starpu_codelet_init(func_cl);
|
|
|
+ func_cl->cpu_funcs[0]=&codelet_func;
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *dict_option = PyTuple_GetItem(args, PyTuple_Size(args)-1);
|
|
|
+ PyObject *perfmodel = PyDict_GetItemString(dict_option, "perfmodel");
|
|
|
+ const char *tp_perf = Py_TYPE(perfmodel)->tp_name;
|
|
|
+ if (strcmp(tp_perf, "PyCapsule")==0)
|
|
|
+ {
|
|
|
+
|
|
|
+ struct starpu_perfmodel *perf=PyCapsule_GetPointer(perfmodel, "Perf");
|
|
|
+ func_cl->model=perf;
|
|
|
+ Py_INCREF(perfmodel);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ struct codelet_args *cst = (struct codelet_args*)malloc(sizeof(struct codelet_args));
|
|
|
+ cst->f = func_py;
|
|
|
+ cst->fut = fut;
|
|
|
+ cst->lp = loop;
|
|
|
+
|
|
|
+ Py_INCREF(fut);
|
|
|
+ Py_INCREF(loop);
|
|
|
+
|
|
|
+
|
|
|
if (PyTuple_Size(args)==2)
|
|
|
cst->argList = PyTuple_New(0);
|
|
|
- else{
|
|
|
+ else
|
|
|
+ {
|
|
|
cst->argList = PyTuple_New(PyTuple_Size(args)-2);
|
|
|
- for (int i=0; i < PyTuple_Size(args)-2; i++){
|
|
|
- PyObject* tmp=PyTuple_GetItem(args, i+1);
|
|
|
+ for (int i=0; i < PyTuple_Size(args)-2; i++)
|
|
|
+ {
|
|
|
+ PyObject *tmp=PyTuple_GetItem(args, i+1);
|
|
|
PyTuple_SetItem(cst->argList, i, tmp);
|
|
|
Py_INCREF(PyTuple_GetItem(cst->argList, i));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- task->cl=func_cl;
|
|
|
- task->cl_arg=cst;
|
|
|
-
|
|
|
-
|
|
|
- PyObject* PyName = PyDict_GetItemString(dict_option, "name");
|
|
|
- const char* name_type = Py_TYPE(PyName)->tp_name;
|
|
|
- if (strcmp(name_type, "NoneType")!=0){
|
|
|
- PyObject* pStrObj = PyUnicode_AsUTF8String(PyName);
|
|
|
- char* name_str = PyBytes_AsString(pStrObj);
|
|
|
- char* name = strdup(name_str);
|
|
|
-
|
|
|
- task->name=name;
|
|
|
- Py_DECREF(pStrObj);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- PyObject* PySync = PyDict_GetItemString(dict_option, "synchronous");
|
|
|
- unsigned sync=PyLong_AsUnsignedLong(PySync);
|
|
|
-
|
|
|
- task->synchronous=sync;
|
|
|
-
|
|
|
-
|
|
|
- PyObject* PyPrio = PyDict_GetItemString(dict_option, "priority");
|
|
|
- int prio=PyLong_AsLong(PyPrio);
|
|
|
-
|
|
|
- task->priority=prio;
|
|
|
-
|
|
|
-
|
|
|
- PyObject* PyColor = PyDict_GetItemString(dict_option, "color");
|
|
|
- const char* color_type = Py_TYPE(PyColor)->tp_name;
|
|
|
- if (strcmp(color_type, "NoneType")!=0){
|
|
|
- unsigned color=PyLong_AsUnsignedLong(PyColor);
|
|
|
-
|
|
|
- task->color=color;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- PyObject* PyFlops = PyDict_GetItemString(dict_option, "flops");
|
|
|
- const char* flops_type = Py_TYPE(PyFlops)->tp_name;
|
|
|
- if (strcmp(flops_type, "NoneType")!=0){
|
|
|
- double flop=PyFloat_AsDouble(PyFlops);
|
|
|
-
|
|
|
- task->flops=flop;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- starpu_task_submit(task);
|
|
|
- task->callback_func=&cb_func;
|
|
|
- if (strcmp(tp_perf, "PyCapsule")==0){
|
|
|
- struct starpu_perfmodel *perf =(struct starpu_perfmodel *) func_cl->model;
|
|
|
- perf->size_base=&sizebase;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return fut;
|
|
|
-
|
|
|
+ task->cl=func_cl;
|
|
|
+ task->cl_arg=cst;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *PyName = PyDict_GetItemString(dict_option, "name");
|
|
|
+ const char *name_type = Py_TYPE(PyName)->tp_name;
|
|
|
+ if (strcmp(name_type, "NoneType")!=0)
|
|
|
+ {
|
|
|
+ PyObject *pStrObj = PyUnicode_AsUTF8String(PyName);
|
|
|
+ char* name_str = PyBytes_AsString(pStrObj);
|
|
|
+ char* name = strdup(name_str);
|
|
|
+
|
|
|
+ task->name=name;
|
|
|
+ Py_DECREF(pStrObj);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *PySync = PyDict_GetItemString(dict_option, "synchronous");
|
|
|
+ unsigned sync=PyLong_AsUnsignedLong(PySync);
|
|
|
+
|
|
|
+ task->synchronous=sync;
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *PyPrio = PyDict_GetItemString(dict_option, "priority");
|
|
|
+ int prio=PyLong_AsLong(PyPrio);
|
|
|
+
|
|
|
+ task->priority=prio;
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *PyColor = PyDict_GetItemString(dict_option, "color");
|
|
|
+ const char *color_type = Py_TYPE(PyColor)->tp_name;
|
|
|
+ if (strcmp(color_type, "NoneType")!=0)
|
|
|
+ {
|
|
|
+ unsigned color=PyLong_AsUnsignedLong(PyColor);
|
|
|
+
|
|
|
+ task->color=color;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ PyObject *PyFlops = PyDict_GetItemString(dict_option, "flops");
|
|
|
+ const char *flops_type = Py_TYPE(PyFlops)->tp_name;
|
|
|
+ if (strcmp(flops_type, "NoneType")!=0)
|
|
|
+ {
|
|
|
+ double flops=PyFloat_AsDouble(PyFlops);
|
|
|
+
|
|
|
+ task->flops=flops;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int ret = starpu_task_submit(task);
|
|
|
+ assert(ret==0);
|
|
|
+ task->callback_func=&cb_func;
|
|
|
+ if (strcmp(tp_perf, "PyCapsule")==0)
|
|
|
+ {
|
|
|
+ struct starpu_perfmodel *perf =(struct starpu_perfmodel *) func_cl->model;
|
|
|
+ perf->size_base=&sizebase;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return fut;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_task_wait_for_all_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
+static PyObject* starpu_task_wait_for_all_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
|
|
|
Py_BEGIN_ALLOW_THREADS
|
|
|
- starpu_task_wait_for_all();
|
|
|
+ starpu_task_wait_for_all();
|
|
|
Py_END_ALLOW_THREADS
|
|
|
|
|
|
-
|
|
|
+
|
|
|
Py_INCREF(Py_None);
|
|
|
- return Py_None;
|
|
|
+ return Py_None;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_pause_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
+static PyObject* starpu_pause_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
|
|
|
starpu_pause();
|
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
- return Py_None;
|
|
|
+ return Py_None;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_resume_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
+static PyObject* starpu_resume_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
|
|
|
starpu_resume();
|
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
- return Py_None;
|
|
|
+ return Py_None;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_cpu_worker_get_count_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
-
|
|
|
- int num_cpu=starpu_cpu_worker_get_count();
|
|
|
+static PyObject* starpu_cpu_worker_get_count_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
+
|
|
|
+ int num_cpu=starpu_cpu_worker_get_count();
|
|
|
|
|
|
-
|
|
|
- return Py_BuildValue("I", num_cpu);
|
|
|
+
|
|
|
+ return Py_BuildValue("I", num_cpu);
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_sched_get_min_priority_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
+static PyObject* starpu_sched_get_min_priority_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
|
|
|
int min_prio=starpu_sched_get_min_priority();
|
|
|
|
|
@@ -413,8 +430,8 @@ static PyObject* starpu_sched_get_min_priority_wrapper(PyObject *self, PyObject
|
|
|
}
|
|
|
|
|
|
|
|
|
-static PyObject* starpu_sched_get_max_priority_wrapper(PyObject *self, PyObject *args){
|
|
|
-
|
|
|
+static PyObject* starpu_sched_get_max_priority_wrapper(PyObject *self, PyObject *args)
|
|
|
+{
|
|
|
|
|
|
int max_prio=starpu_sched_get_max_priority();
|
|
|
|
|
@@ -441,35 +458,38 @@ static PyMethodDef starpupyMethods[] =
|
|
|
};
|
|
|
|
|
|
|
|
|
-static void starpupyFree(void* self){
|
|
|
+static void starpupyFree(void *self)
|
|
|
+{
|
|
|
starpu_shutdown();
|
|
|
- Py_DECREF(asyncio_module);
|
|
|
-
|
|
|
+ Py_DECREF(asyncio_module);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
-static struct PyModuleDef starpupymodule={
|
|
|
- PyModuleDef_HEAD_INIT,
|
|
|
- "starpupy",
|
|
|
- NULL,
|
|
|
- -1,
|
|
|
- starpupyMethods,
|
|
|
- NULL,
|
|
|
- NULL,
|
|
|
- NULL,
|
|
|
- starpupyFree
|
|
|
+static struct PyModuleDef starpupymodule =
|
|
|
+{
|
|
|
+ PyModuleDef_HEAD_INIT,
|
|
|
+ "starpupy",
|
|
|
+ NULL,
|
|
|
+ -1,
|
|
|
+ starpupyMethods,
|
|
|
+ NULL,
|
|
|
+ NULL,
|
|
|
+ NULL,
|
|
|
+ starpupyFree
|
|
|
};
|
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
|
PyInit_starpupy(void)
|
|
|
{
|
|
|
- PyEval_InitThreads();
|
|
|
-
|
|
|
- starpu_init(NULL);
|
|
|
-
|
|
|
- asyncio_module = PyImport_ImportModule("asyncio");
|
|
|
-
|
|
|
- return PyModule_Create(&starpupymodule);
|
|
|
+ PyEval_InitThreads();
|
|
|
+
|
|
|
+ int ret = starpu_init(NULL);
|
|
|
+ assert(ret==0);
|
|
|
+
|
|
|
+ asyncio_module = PyImport_ImportModule("asyncio");
|
|
|
+
|
|
|
+ return PyModule_Create(&starpupymodule);
|
|
|
}
|
|
|
|