Pārlūkot izejas kodu

insert task: put into some external functions the code which is also used by MPI (and potentially other parts of StarPU)

Nathalie Furmento 14 gadi atpakaļ
vecāks
revīzija
6bc92bcbbe

+ 1 - 0
src/Makefile.am

@@ -178,6 +178,7 @@ libstarpu_la_SOURCES = 						\
 	util/file.c						\
 	util/file.c						\
 	util/starpu_data_cpy.c					\
 	util/starpu_data_cpy.c					\
 	util/starpu_insert_task.c				\
 	util/starpu_insert_task.c				\
+	util/starpu_insert_task_utils.c				\
 	util/starpu_task_list.c					\
 	util/starpu_task_list.c					\
 	debug/latency.c						\
 	debug/latency.c						\
 	debug/structures_size.c					\
 	debug/structures_size.c					\

+ 5 - 100
src/util/starpu_insert_task.c

@@ -20,6 +20,7 @@
 #include <starpu.h>
 #include <starpu.h>
 #include <common/config.h>
 #include <common/config.h>
 #include <stdarg.h>
 #include <stdarg.h>
+#include <util/starpu_insert_task_utils.h>
 
 
 void starpu_unpack_cl_args(void *_cl_arg, ...)
 void starpu_unpack_cl_args(void *_cl_arg, ...)
 {
 {
@@ -53,115 +54,19 @@ void starpu_unpack_cl_args(void *_cl_arg, ...)
 
 
 void starpu_insert_task(starpu_codelet *cl, ...)
 void starpu_insert_task(starpu_codelet *cl, ...)
 {
 {
-	struct starpu_task *task = starpu_task_create();
-	int arg_type;
 	va_list varg_list;
 	va_list varg_list;
 
 
 	/* The buffer will contain : nargs, {size, content} (x nargs)*/
 	/* The buffer will contain : nargs, {size, content} (x nargs)*/
 
 
 	/* Compute the size */
 	/* Compute the size */
 	size_t arg_buffer_size = 0;
 	size_t arg_buffer_size = 0;
-
-	arg_buffer_size += sizeof(char);
+        int nb_buffers;
 
 
 	va_start(varg_list, cl);
 	va_start(varg_list, cl);
-
-	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) {
-			va_arg(varg_list, starpu_data_handle);
-		}
-		else if (arg_type==STARPU_VALUE) {
-			va_arg(varg_list, void *);
-			size_t cst_size = va_arg(varg_list, size_t);
-
-			arg_buffer_size += sizeof(size_t);
-			arg_buffer_size += cst_size;
-		}
-		else if (arg_type==STARPU_CALLBACK) {
-			va_arg(varg_list, void (*)(void *));
-		}
-		else if (arg_type==STARPU_CALLBACK_ARG) {
-			va_arg(varg_list, void *);
-		}
-		else if (arg_type==STARPU_PRIORITY) {
-			va_arg(varg_list, int);
-		}
-	}
-
-	va_end(varg_list);
-
-	char *arg_buffer = malloc(arg_buffer_size);
-	unsigned current_arg_offset = 0;
-
-	/* We will begin the buffer with the number of args (which is stored as a char) */
-	current_arg_offset += sizeof(char);
-	unsigned current_buffer = 0;
-	unsigned char nargs = 0;
+        starpu_insert_task_get_sizes(&arg_buffer_size, &nb_buffers, varg_list);
 
 
 	va_start(varg_list, cl);
 	va_start(varg_list, cl);
+        struct starpu_task *task = starpu_task_create();
+        starpu_insert_task_create_and_submit(arg_buffer_size, cl, &task, varg_list);
 
 
-	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)
-		{
-			/* We have an access mode : we expect to find a handle */
-			starpu_data_handle handle = va_arg(varg_list, starpu_data_handle);
-
-			starpu_access_mode mode = arg_type;
-
-			task->buffers[current_buffer].handle = handle;
-			task->buffers[current_buffer].mode = mode;
-
-			current_buffer++;
-		}
-		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 */
-			void *ptr = va_arg(varg_list, void *);
-			size_t cst_size = va_arg(varg_list, size_t);
-
-			*(size_t *)(&arg_buffer[current_arg_offset]) = cst_size;
-			current_arg_offset += sizeof(size_t);
-
-			memcpy(&arg_buffer[current_arg_offset], ptr, cst_size);
-			current_arg_offset += cst_size;
-
-			nargs++;
-			STARPU_ASSERT(current_arg_offset <= arg_buffer_size);
-		}
-		else if (arg_type==STARPU_CALLBACK)
-		{
-			void (*callback_func)(void *);
-			callback_func = va_arg(varg_list, void (*)(void *));
-			task->callback_func = callback_func;
-		}
-		else if (arg_type==STARPU_CALLBACK_ARG) {
-			void *callback_arg;
-			callback_arg = va_arg(varg_list, void *);
-			task->callback_arg = callback_arg;
-		}
-		else if (arg_type==STARPU_PRIORITY)
-		{
-			/* Followed by a priority level */
-			int prio = va_arg(varg_list, int); 
-			task->priority = prio;
-		}
-	}
-
-	va_end(varg_list);
-
-	arg_buffer[0] = nargs;
-
-	STARPU_ASSERT(current_buffer == cl->nbuffers);
-
-	task->cl = cl;
-	task->cl_arg = arg_buffer;
-
-	int ret = starpu_task_submit(task);
-
-	if (STARPU_UNLIKELY(ret == -ENODEV))
-		fprintf(stderr, "No one can execute task %p wih cl %p (symbol %s)\n", task, task->cl, (task->cl->model && task->cl->model->symbol)?task->cl->model->symbol:"none");
-
-	STARPU_ASSERT(!ret);
 }
 }

+ 137 - 0
src/util/starpu_insert_task_utils.c

@@ -0,0 +1,137 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <util/starpu_insert_task_utils.h>
+#include <common/config.h>
+#include <common/utils.h>
+
+void starpu_insert_task_get_sizes(size_t *arg_buffer_size, int *nb_buffers, va_list varg_list)
+{
+	int arg_type;
+
+        *arg_buffer_size = 0;
+        *nb_buffers = 0;
+
+	*arg_buffer_size += sizeof(char);
+
+	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) {
+			va_arg(varg_list, starpu_data_handle);
+                        *nb_buffers ++;
+		}
+		else if (arg_type==STARPU_VALUE) {
+			va_arg(varg_list, void *);
+			size_t cst_size = va_arg(varg_list, size_t);
+
+			*arg_buffer_size += sizeof(size_t);
+			*arg_buffer_size += cst_size;
+		}
+		else if (arg_type==STARPU_CALLBACK) {
+			va_arg(varg_list, void (*)(void *));
+		}
+		else if (arg_type==STARPU_CALLBACK_ARG) {
+			va_arg(varg_list, void *);
+		}
+		else if (arg_type==STARPU_PRIORITY) {
+			va_arg(varg_list, int);
+		}
+	}
+
+	va_end(varg_list);
+
+}
+
+int starpu_insert_task_create_and_submit(size_t arg_buffer_size, starpu_codelet *cl, struct starpu_task **task, va_list varg_list) {
+        int arg_type;
+	unsigned current_buffer = 0;
+	unsigned char nargs = 0;
+	char *arg_buffer = malloc(arg_buffer_size);
+	unsigned current_arg_offset = 0;
+
+
+        _STARPU_DEBUG("cl->nbuffers: %d\n", cl->nbuffers);
+
+	/* We will begin the buffer with the number of args (which is stored as a char) */
+	current_arg_offset += sizeof(char);
+
+	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)
+		{
+			/* We have an access mode : we expect to find a handle */
+			starpu_data_handle handle = va_arg(varg_list, starpu_data_handle);
+
+			starpu_access_mode mode = arg_type;
+
+			(*task)->buffers[current_buffer].handle = handle;
+			(*task)->buffers[current_buffer].mode = mode;
+
+			current_buffer++;
+		}
+		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 */
+			void *ptr = va_arg(varg_list, void *);
+			size_t cst_size = va_arg(varg_list, size_t);
+
+			*(size_t *)(&arg_buffer[current_arg_offset]) = cst_size;
+			current_arg_offset += sizeof(size_t);
+
+			memcpy(&arg_buffer[current_arg_offset], ptr, cst_size);
+			current_arg_offset += cst_size;
+
+			nargs++;
+			STARPU_ASSERT(current_arg_offset <= arg_buffer_size);
+		}
+		else if (arg_type==STARPU_CALLBACK)
+		{
+			void (*callback_func)(void *);
+			callback_func = va_arg(varg_list, void (*)(void *));
+			(*task)->callback_func = callback_func;
+		}
+		else if (arg_type==STARPU_CALLBACK_ARG) {
+			void *callback_arg;
+			callback_arg = va_arg(varg_list, void *);
+			(*task)->callback_arg = callback_arg;
+		}
+		else if (arg_type==STARPU_PRIORITY)
+		{
+			/* Followed by a priority level */
+			int prio = va_arg(varg_list, int); 
+			(*task)->priority = prio;
+		}
+	}
+
+	va_end(varg_list);
+
+	arg_buffer[0] = nargs;
+
+        _STARPU_DEBUG("current_buffer: %d\n", current_buffer);
+        _STARPU_DEBUG("cl->nbuffers: %d\n", cl->nbuffers);
+	STARPU_ASSERT(current_buffer == cl->nbuffers);
+
+	(*task)->cl = cl;
+	(*task)->cl_arg = arg_buffer;
+
+	int ret = starpu_task_submit(*task);
+
+	if (STARPU_UNLIKELY(ret == -ENODEV))
+          fprintf(stderr, "No one can execute task %p wih cl %p (symbol %s)\n", *task, (*task)->cl, ((*task)->cl->model && (*task)->cl->model->symbol)?(*task)->cl->model->symbol:"none");
+
+	STARPU_ASSERT(!ret);
+        return ret;
+}
+

+ 28 - 0
src/util/starpu_insert_task_utils.h

@@ -0,0 +1,28 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#ifndef __STARPU_INSERT_TASK_UTILS_H__
+#define __STARPU_INSERT_TASK_UTILS_H__
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <starpu.h>
+
+void starpu_insert_task_get_sizes(size_t *arg_buffer_size, int *nb_buffers, va_list varg_list);
+int starpu_insert_task_create_and_submit(size_t arg_buffer_size, starpu_codelet *cl, struct starpu_task **task, va_list varg_list);
+
+#endif // __STARPU_INSERT_TASK_UTILS_H__
+