Przeglądaj źródła

Merge 2 functions starpu_insert_task and starpu_insert_task_array.

We only keep the former one and extend it by adding a new parameter STARPU_DATA_ARRAY to define a array of data handles.
This is much better than introducing a new functionality and less error-prone.
Nathalie Furmento 12 lat temu
rodzic
commit
d6416329c9

+ 9 - 45
doc/chapters/advanced-examples.texi

@@ -478,17 +478,8 @@ transfers, which are assumed to be completely overlapped.
 @node Insert Task Utility
 @section Insert Task Utility
 
-StarPU provides wrapper functions @code{starpu_insert_task} and
-@code{starpu_insert_task_array} to ease the creation and submission of tasks.
-
-@menu
-* With a defined number of handles::  
-* With an undefined number of handles::  
-* Task insertion depending on some earlier computation::  
-@end menu
-
-@node With a defined number of handles
-@subsection With a defined number of handles
+StarPU provides the wrapper function @code{starpu_insert_task} to ease
+the creation and submission of tasks.
 
 @deftypefun int starpu_insert_task (struct starpu_codelet *@var{cl}, ...)
 Create and submit a task corresponding to @var{cl} with the following
@@ -500,12 +491,17 @@ The arguments following the codelets can be of the following types:
 @item
 @code{STARPU_R}, @code{STARPU_W}, @code{STARPU_RW}, @code{STARPU_SCRATCH}, @code{STARPU_REDUX} an access mode followed by a data handle;
 @item
+@code{STARPU_DATA_ARRAY} followed by an array of data handles and its number of elements;
+@item
 the specific values @code{STARPU_VALUE}, @code{STARPU_CALLBACK},
 @code{STARPU_CALLBACK_ARG}, @code{STARPU_CALLBACK_WITH_ARG},
 @code{STARPU_PRIORITY}, followed by the appropriated objects as
 defined below.
 @end itemize
 
+When using @code{STARPU_DATA_ARRAY}, the access mode of the data
+handles is not defined.
+
 Parameters to be passed to the codelet implementation are defined
 through the type @code{STARPU_VALUE}. The function
 @code{starpu_codelet_unpack_args} must be called within the codelet
@@ -605,48 +601,16 @@ task->cl_arg_size = arg_buffer_size;
 int ret = starpu_task_submit(task);
 @end smallexample
 
-@node With an undefined number of handles
-@subsection With an undefined number of handles
-
-@deftypefun int starpu_insert_task_array (struct starpu_codelet *@var{cl}, {starpu_data_handle_t *}@var{handles}, unsigned @var{nb_handles}, ...)
-Create and submit a task corresponding to @var{cl} with the given
-number @var{nb_handles} of @var{handles}, and the following
-arguments.  The argument list must be zero-terminated.
-
-The arguments following the codelets can be of the following types:
-
-@itemize
-@item
-the specific values @code{STARPU_VALUE}, @code{STARPU_CALLBACK},
-@code{STARPU_CALLBACK_ARG}, @code{STARPU_CALLBACK_WITH_ARG},
-@code{STARPU_PRIORITY}, followed by the appropriated objects as
-defined above.
-@end itemize
-
-The number of data handles @var{nb_handles} must be equal to the
-number of data handles expected by the codelet @var{cl}. The access
-modes will be the ones defined by @var{cl}.
-
-Parameters to be passed to the codelet implementation are defined
-through the type @code{STARPU_VALUE}. The function
-@code{starpu_codelet_unpack_args} must be called within the codelet
-implementation to retrieve them.
-@end deftypefun
-
-Here a call to the @code{starpu_insert_task_array} wrapper equivalent
-to the example above.
+Here a similar call using @code{STARPU_DATA_ARRAY}.
 
 @smallexample
 starpu_insert_task(&mycodelet,
-                   data_handles, 2,
+                   STARPU_DATA_ARRAY, data_handles, 2,
                    STARPU_VALUE, &ifactor, sizeof(ifactor),
                    STARPU_VALUE, &ffactor, sizeof(ffactor),
                    0);
 @end smallexample
 
-@node Task insertion depending on some earlier computation
-@subsection Task insertion depending on some earlier computation
-
 If some part of the task insertion depends on the value of some computation,
 the @code{STARPU_DATA_ACQUIRE_CB} macro can be very convenient. For
 instance, assuming that the index variable @code{i} was registered as handle

+ 1 - 1
include/starpu_util.h

@@ -246,10 +246,10 @@ int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_ha
 #define STARPU_PRIORITY		(1<<8)	/* Priority associated to the task */
 #define STARPU_EXECUTE_ON_NODE	(1<<9)	/* Used by MPI to define which task is going to execute the codelet */
 #define STARPU_EXECUTE_ON_DATA	(1<<10)	/* Used by MPI to define which task is going to execute the codelet */
+#define STARPU_DATA_ARRAY       (1<<11) /* Array of data handles */
 
 /* Wrapper to create a task. */
 int starpu_insert_task(struct starpu_codelet *cl, ...);
-int starpu_insert_task_array(struct starpu_codelet *cl, starpu_data_handle_t *handles, unsigned nb_handles, ...);
 
 /* Retrieve the arguments of type STARPU_VALUE associated to a task
  * automatically created using starpu_insert_task. */

+ 0 - 25
src/util/starpu_insert_task.c

@@ -88,28 +88,3 @@ int starpu_insert_task(struct starpu_codelet *cl, ...)
         return ret;
 }
 
-int starpu_insert_task_array(struct starpu_codelet *cl, starpu_data_handle_t *handles, unsigned nb_handles, ...)
-{
-	va_list varg_list;
-
-	/* Compute the size */
-	size_t arg_buffer_size = 0;
-	va_start(varg_list, nb_handles);
-        arg_buffer_size = _starpu_insert_task_get_arg_size(varg_list);
-
-	va_start(varg_list, nb_handles);
-	char *arg_buffer;
-	_starpu_codelet_pack_args(arg_buffer_size, &arg_buffer, varg_list);
-
-	va_start(varg_list, nb_handles);
-        struct starpu_task *task = starpu_task_create();
-	int ret = _starpu_insert_task_create_and_submit_array(arg_buffer, arg_buffer_size, cl, &task, handles, nb_handles, varg_list);
-
-	if (ret == -ENODEV)
-	{
-		task->destroy = 0;
-		starpu_task_destroy(task);
-	}
-        return ret;
-
-}

+ 22 - 91
src/util/starpu_insert_task_utils.c

@@ -57,6 +57,11 @@ size_t _starpu_insert_task_get_arg_size(va_list varg_list)
 		{
 			(void)va_arg(varg_list, starpu_data_handle_t);
 		}
+		else if (arg_type==STARPU_DATA_ARRAY)
+		{
+			(void)va_arg(varg_list, starpu_data_handle_t*);
+			(void)va_arg(varg_list, int);
+		}
 		else if (arg_type==STARPU_VALUE)
 		{
 			(void)va_arg(varg_list, void *);
@@ -115,6 +120,11 @@ int _starpu_codelet_pack_args(size_t arg_buffer_size, char **arg_buffer, va_list
 		{
 			(void)va_arg(varg_list, starpu_data_handle_t);
 		}
+		else if (arg_type==STARPU_DATA_ARRAY)
+		{
+			(void)va_arg(varg_list, starpu_data_handle_t*);
+			(void)va_arg(varg_list, int);
+		}
 		else if (arg_type==STARPU_VALUE)
 		{
 			/* We have a constant value: this should be followed by a pointer to the cst value and the size of the constant */
@@ -202,100 +212,19 @@ int _starpu_insert_task_create_and_submit(char *arg_buffer, size_t arg_buffer_si
 
 			current_buffer++;
 		}
-		else if (arg_type==STARPU_VALUE)
-		{
-			(void)va_arg(varg_list, void *);
-			(void)va_arg(varg_list, size_t);
-		}
-		else if (arg_type==STARPU_CALLBACK)
-		{
-			void (*callback_func)(void *);
-			callback_func = va_arg(varg_list, _starpu_callback_func_t);
-			cl_arg_wrapper->callback_func = callback_func;
-		}
-		else if (arg_type==STARPU_CALLBACK_WITH_ARG)
-		{
-			void (*callback_func)(void *);
-			void *callback_arg;
-			callback_func = va_arg(varg_list, _starpu_callback_func_t);
-			callback_arg = va_arg(varg_list, void *);
-			cl_arg_wrapper->callback_func = callback_func;
-			cl_arg_wrapper->callback_arg = callback_arg;
-		}
-		else if (arg_type==STARPU_CALLBACK_ARG)
-		{
-			void *callback_arg = va_arg(varg_list, void *);
-			cl_arg_wrapper->callback_arg = callback_arg;
-		}
-		else if (arg_type==STARPU_PRIORITY)
+		else if (arg_type == STARPU_DATA_ARRAY)
 		{
-			/* Followed by a priority level */
-			int prio = va_arg(varg_list, int);
-			(*task)->priority = prio;
-		}
-		else if (arg_type==STARPU_EXECUTE_ON_NODE)
-		{
-			(void)va_arg(varg_list, int);
-		}
-		else if (arg_type==STARPU_EXECUTE_ON_DATA)
-		{
-			(void)va_arg(varg_list, starpu_data_handle_t);
-		}
-	}
-
-	va_end(varg_list);
-
-	STARPU_ASSERT(current_buffer == cl->nbuffers);
-
-	(*task)->cl = cl;
-	(*task)->cl_arg = arg_buffer;
-	(*task)->cl_arg_size = arg_buffer_size;
-
-	/* The callback will free the argument stack and execute the
-	 * application's callback, if any. */
-	(*task)->callback_func = starpu_task_insert_callback_wrapper;
-	(*task)->callback_arg = cl_arg_wrapper;
-
-	int ret = starpu_task_submit(*task);
-
-	if (STARPU_UNLIKELY(ret == -ENODEV))
-	{
-		fprintf(stderr, "submission of task %p wih codelet %p failed (symbol `%s') (err: ENODEV)\n",
-			*task, (*task)->cl,
-			(*task)->cl->name ? (*task)->cl->name :
-			((*task)->cl->model && (*task)->cl->model->symbol)?(*task)->cl->model->symbol:"none");
-		free(cl_arg_wrapper->arg_stack);
-		free(cl_arg_wrapper);
-	}
-
-        return ret;
-}
-
-int _starpu_insert_task_create_and_submit_array(char *arg_buffer, size_t arg_buffer_size, struct starpu_codelet *cl, struct starpu_task **task, starpu_data_handle_t *handles, unsigned nb_handles, va_list varg_list)
-{
-	unsigned current_buffer = 0;
-	unsigned i;
-        int arg_type;
+			// Expect to find a array of handles and its size
+			starpu_data_handle_t *handles = va_arg(varg_list, starpu_data_handle_t *);
+			int nb_handles = va_arg(varg_list, int);
 
-	struct insert_task_cb_wrapper *cl_arg_wrapper = (struct insert_task_cb_wrapper *) malloc(sizeof(struct insert_task_cb_wrapper));
-	STARPU_ASSERT(cl_arg_wrapper);
+			int i;
+			for(i=0 ; i<nb_handles ; i++)
+			{
+				(*task)->handles[current_buffer] = handles[i];
+				current_buffer++;
+			}
 
-	cl_arg_wrapper->callback_func = NULL;
-	cl_arg_wrapper->arg_stack = arg_buffer;
-
-	for(i=0 ; i<nb_handles ; i++)
-	{
-		(*task)->handles[i] = handles[i];
-	}
-	STARPU_ASSERT(nb_handles == cl->nbuffers);
-
-	while((arg_type = va_arg(varg_list, int)) != 0)
-	{
-		if (arg_type==STARPU_R || arg_type==STARPU_W || arg_type==STARPU_RW || arg_type == STARPU_SCRATCH || arg_type == STARPU_REDUX)
-		{
-			/* We have an access mode : we expect to find a handle */
-			(void) va_arg(varg_list, starpu_data_handle_t);
-			return -EINVAL;
 		}
 		else if (arg_type==STARPU_VALUE)
 		{
@@ -340,6 +269,8 @@ int _starpu_insert_task_create_and_submit_array(char *arg_buffer, size_t arg_buf
 
 	va_end(varg_list);
 
+	STARPU_ASSERT(current_buffer == cl->nbuffers);
+
 	(*task)->cl = cl;
 	(*task)->cl_arg = arg_buffer;
 	(*task)->cl_arg_size = arg_buffer_size;

+ 5 - 4
tests/main/insert_task_array.c

@@ -54,10 +54,11 @@ int main(int argc, char **argv)
 	f = 2.0;
 	starpu_variable_data_register(&data_handles[1], 0, (uintptr_t)&f, sizeof(f));
 
-        ret = starpu_insert_task_array(&mycodelet, data_handles, 2,
-				       STARPU_VALUE, &factor, sizeof(factor),
-				       STARPU_PRIORITY, 1,
-				       0);
+        ret = starpu_insert_task(&mycodelet,
+				 STARPU_DATA_ARRAY, data_handles, 2,
+				 STARPU_VALUE, &factor, sizeof(factor),
+				 STARPU_PRIORITY, 1,
+				 0);
 	if (ret == -ENODEV) goto enodev;
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_insert_task");