Browse Source

starpupy: "starpu.task_submit" returns void

HE Kun 4 years ago
parent
commit
80ed709392

+ 1 - 1
starpupy/wrapper/starpu/delay.py

@@ -1,5 +1,5 @@
 from starpu import task
 from starpu import task
 def delayed(f):
 def delayed(f):
 	def submit():
 	def submit():
-		task.submit(f)
+		task.task_submit(f)
 	return submit
 	return submit

+ 17 - 81
starpupy/wrapper/starpu/starpu_task_wrapper.c

@@ -6,8 +6,6 @@
 #define PY_SSIZE_T_CLEAN
 #define PY_SSIZE_T_CLEAN
 #include <Python.h>
 #include <Python.h>
 
 
-static PyObject* asyncio_module;
-static PyObject* loop;
 /********************preparation of calling python function*************************/
 /********************preparation of calling python function*************************/
 //static PyObject* func_py;
 //static PyObject* func_py;
 /*call python function no input no output*/
 /*call python function no input no output*/
@@ -16,7 +14,7 @@ static void py_callback(PyObject * func_py){
 
 
     // make sure we own the GIL
     // make sure we own the GIL
     PyGILState_STATE state = PyGILState_Ensure();
     PyGILState_STATE state = PyGILState_Ensure();
-    printf("func_py in py_callback is %p\n", func_py);
+    //printf("func_py in py_callback is %p\n", func_py);
     // verify that func is a proper callable
     // verify that func is a proper callable
     if (!PyCallable_Check(func_py)) {
     if (!PyCallable_Check(func_py)) {
 
 
@@ -36,7 +34,7 @@ static void py_callback(PyObject * func_py){
     }
     }
 	Py_DECREF(pRetVal);
 	Py_DECREF(pRetVal);
 
 
-	printf("finish callback\n");
+	//printf("finish callback\n");
     // restore previous GIL state and return 
     // restore previous GIL state and return 
     PyGILState_Release(state);
     PyGILState_Release(state);
 }
 }
@@ -52,62 +50,26 @@ typedef struct codelet_struct codelet_st;
 
 
 /*cpu_func*/
 /*cpu_func*/
 void codelet_func(void *buffers[], void *cl_arg){
 void codelet_func(void *buffers[], void *cl_arg){
-    printf("begin to print in codelet_func\n");
+    //printf("begin to print in codelet_func\n");
     codelet_st* cst = (codelet_st*) cl_arg;
     codelet_st* cst = (codelet_st*) cl_arg;
     py_callback(cst->f);
     py_callback(cst->f);
-    printf("finish to print in codelet_func\n");
+    //printf("finish to print in codelet_func\n");
 }
 }
 
 
 /*call back function to deallocate task*/
 /*call back function to deallocate task*/
 void cb_func(void*f){
 void cb_func(void*f){
 	struct starpu_task *task=starpu_task_get_current();
 	struct starpu_task *task=starpu_task_get_current();
 	free(task->cl);
 	free(task->cl);
-    PyGILState_STATE state = PyGILState_Ensure();
-    //set_result
-    //Py_DECREF(pRetVal);
-    PyGILState_Release(state);
 	free(task->cl_arg);
 	free(task->cl_arg);
 }
 }
 
 
-/*submit method*/
-/*void starpu_submit(PyObject*func){
-
-	//allocate a task structure and initialize it with default values 
-    struct starpu_task *task=starpu_task_create();
-
-    //allocate a codelet structure
-    struct starpu_codelet *func_cl=(struct starpu_codelet*)malloc(sizeof(struct starpu_codelet));
-    //initialize func_cl with default values
-    starpu_codelet_init(func_cl);
-    func_cl->cpu_func=&codelet_func;
-
-    //allocate a new structure to pass the function python
-    codelet_st *cst;
-    cst = (codelet_st*)malloc(sizeof(codelet_st));
-    cst->f = func;
-    Py_INCREF(func);
-
-    task->cl=func_cl;
-    task->cl_arg=cst;
-
-    int result=starpu_task_submit(task);
-    printf("finish to submit task, result is %d\n", result);
-
-    //free(func_cl);
-    //free(task);
-    //free(cst);
-    task->callback_func=&cb_func;
-}*/
-
 /*wrapper submit method*/
 /*wrapper submit method*/
-static PyObject* starpu_submit_wrapper(PyObject *self, PyObject *args){
+static PyObject* starpu_task_submit_wrapper(PyObject *self, PyObject *args){
 	PyObject* func_py;
 	PyObject* func_py;
-    PyObject* fut;
-
 
 
 	if (!PyArg_ParseTuple(args, "O", &func_py))
 	if (!PyArg_ParseTuple(args, "O", &func_py))
 		return NULL;
 		return NULL;
-	printf("func_py in wrapper is %p\n", func_py);
+	//printf("func_py in wrapper is %p\n", func_py);
 
 
 	//call submit method
 	//call submit method
 	//allocate a task structure and initialize it with default values 
 	//allocate a task structure and initialize it with default values 
@@ -131,40 +93,18 @@ static PyObject* starpu_submit_wrapper(PyObject *self, PyObject *args){
     int retval=starpu_task_submit(task);
     int retval=starpu_task_submit(task);
     printf("finish to submit task, result is %d\n", retval);
     printf("finish to submit task, result is %d\n", retval);
 
 
-    // create a asyncio.Future object
-    
-    fut = PyObject_CallMethod(loop, create_future());
-    PyObject *set_result = PyObject_GetAttrString(fut, "set_result");
-    
-
-    //free(func_cl);
-    //free(task);
-    //free(cst);
-
     task->callback_func=&cb_func;
     task->callback_func=&cb_func;
 
 
-    return fut;
-
     //return type is void
     //return type is void
-    //Py_INCREF(Py_None);
-    //return Py_None;
+    Py_INCREF(Py_None);
+    return Py_None;
 	
 	
 }
 }
 
 
-/*wait for all method*/
-/*void starpu_wait_for_all(){
-	printf("begin to wait for all\n");
-	Py_BEGIN_ALLOW_THREADS
-	starpu_task_wait_for_all();
-	Py_END_ALLOW_THREADS
-	printf("finish to wait for all\n");
-
-}*/
 /*wrapper wait for all method*/
 /*wrapper wait for all method*/
-static PyObject* starpu_wait_for_all_wrapper(PyObject *self, PyObject *args){
+static PyObject* starpu_task_wait_for_all_wrapper(PyObject *self, PyObject *args){
 
 
 	//call wait for all method
 	//call wait for all method
-	//starpu_wait_for_all();
 	Py_BEGIN_ALLOW_THREADS
 	Py_BEGIN_ALLOW_THREADS
 	starpu_task_wait_for_all();
 	starpu_task_wait_for_all();
 	Py_END_ALLOW_THREADS
 	Py_END_ALLOW_THREADS
@@ -174,7 +114,7 @@ static PyObject* starpu_wait_for_all_wrapper(PyObject *self, PyObject *args){
     return Py_None;
     return Py_None;
 }
 }
 
 
-/*pause*/
+/*wrapper pause method*/
 static PyObject* starpu_pause_wrapper(PyObject *self, PyObject *args){
 static PyObject* starpu_pause_wrapper(PyObject *self, PyObject *args){
 
 
 	//call pause method
 	//call pause method
@@ -185,7 +125,7 @@ static PyObject* starpu_pause_wrapper(PyObject *self, PyObject *args){
     return Py_None;
     return Py_None;
 }
 }
 
 
-/*resume*/
+/*wrapper resume method*/
 static PyObject* starpu_resume_wrapper(PyObject *self, PyObject *args){
 static PyObject* starpu_resume_wrapper(PyObject *self, PyObject *args){
 
 
 	//call resume method
 	//call resume method
@@ -202,18 +142,16 @@ static PyObject* starpu_resume_wrapper(PyObject *self, PyObject *args){
 /*method table*/
 /*method table*/
 static PyMethodDef taskMethods[] = 
 static PyMethodDef taskMethods[] = 
 { 
 { 
-  {"submit", starpu_submit_wrapper, METH_VARARGS, "submit the task"}, //submit method
-  {"wait_for_all", starpu_wait_for_all_wrapper, METH_VARARGS, "wait the task"}, //wait method
-  {"pause", starpu_pause_wrapper, METH_VARARGS, "suspend the processing of new tasks by workers"}, //submit method
-  {"resume", starpu_resume_wrapper, METH_VARARGS, "resume the workers polling for new tasks"}, //submit method
+  {"task_submit", starpu_task_submit_wrapper, METH_VARARGS, "submit the task"}, //submit method
+  {"task_wait_for_all", starpu_task_wait_for_all_wrapper, METH_VARARGS, "wait the task"}, //wait for all method
+  {"pause", starpu_pause_wrapper, METH_VARARGS, "suspend the processing of new tasks by workers"}, //pause method
+  {"resume", starpu_resume_wrapper, METH_VARARGS, "resume the workers polling for new tasks"}, //resume method
   {NULL, NULL}
   {NULL, NULL}
 };
 };
 
 
 /*deallocation function*/
 /*deallocation function*/
 static void taskFree(void* f){
 static void taskFree(void* f){
 	starpu_shutdown();
 	starpu_shutdown();
-    Py_DECREF(asyncio_module);
-    Py_DECREF(loop);
 }
 }
 
 
 /*the method table must be referenced in the module definition structure*/
 /*the method table must be referenced in the module definition structure*/
@@ -237,10 +175,8 @@ PyInit_task(void)
     //starpu initialization
     //starpu initialization
     printf("begin initialization\n");
     printf("begin initialization\n");
 	int ret = starpu_init(NULL);
 	int ret = starpu_init(NULL);
-	printf("finish initialization result is %d\n",ret);
-    asyncio_module = PyImport_ImportModule("asyncio");
-    //fut = PyObject_CallMethod(asyncio_module, "Future", NULL);
-    loop = PyObject_CallMethod(asyncio_module, "get_running_loop", NULL);
+	printf("finish initialization, result is %d\n",ret);
+
     //python import initialization
     //python import initialization
     return PyModule_Create(&taskmodule);
     return PyModule_Create(&taskmodule);
 }
 }

+ 5 - 9
starpupy/wrapper/starpu_py.py

@@ -12,21 +12,17 @@ def hello():
 	print ("Hello, world!")
 	print ("Hello, world!")
 
 
 starpu.pause()
 starpu.pause()
-#starpu.runfunc(hello)
-#hello()
+
 print("begin to submit task in python")
 print("begin to submit task in python")
-fut=starpu.submit(hello)
+fut=starpu.task_submit(hello)
 salut()
 salut()
-#starpu.submit(salut)
-#starpu.submit(hello)
-#starpu.submit(salut)
-#starpu.submit(hello)
+#starpu.task_submit(hello)
+#starpu.task_submit(hello)
 print("finish to submit task in python")
 print("finish to submit task in python")
 starpu.resume()
 starpu.resume()
 
 
-#starpu.wait(t)
 #print("begin to sleep")
 #print("begin to sleep")
 #time.sleep(1)
 #time.sleep(1)
 #print("finish to sleep")
 #print("finish to sleep")
 
 
-starpu.wait_for_all()
+starpu.task_wait_for_all()