Browse Source

Bundle structure is now an opaque type (starpu_task_bundle_t).

Some functions were modified accordingly to the new bundle type and some functions were made private to StarPU.
Nicolas Collin 14 years ago
parent
commit
dda7ff2523

+ 2 - 0
include/starpu_perfmodel.h

@@ -33,6 +33,8 @@ extern "C"
 {
 {
 #endif
 #endif
 
 
+struct starpu_task;
+
 struct starpu_htbl32_node;
 struct starpu_htbl32_node;
 struct starpu_history_list;
 struct starpu_history_list;
 struct starpu_buffer_descr;
 struct starpu_buffer_descr;

+ 2 - 1
include/starpu_task.h

@@ -21,6 +21,7 @@
 
 
 #include <starpu.h>
 #include <starpu.h>
 #include <starpu_data.h>
 #include <starpu_data.h>
+#include <starpu_task_bundle.h>
 #include <errno.h>
 #include <errno.h>
 
 
 #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
 #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
@@ -149,7 +150,7 @@ struct starpu_task
 	unsigned workerid;
 	unsigned workerid;
 
 
 	/* Bundle including the task */
 	/* Bundle including the task */
-	struct starpu_task_bundle *bundle;
+	starpu_task_bundle_t bundle;
 
 
 	/* If this flag is set, it is not possible to synchronize with the task
 	/* If this flag is set, it is not possible to synchronize with the task
 	 * by the means of starpu_task_wait later on. Internal data structures
 	 * by the means of starpu_task_wait later on. Internal data structures

+ 21 - 39
include/starpu_task_bundle.h

@@ -2,6 +2,7 @@
  *
  *
  * Copyright (C) 2010, 2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Université de Bordeaux 1
  * Copyright (C) 2011  Télécom-SudParis
  * Copyright (C) 2011  Télécom-SudParis
+ * Copyright (C) 2012  Inria
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * it under the terms of the GNU Lesser General Public License as published by
@@ -18,71 +19,52 @@
 #ifndef __STARPU_TASK_BUNDLE_H__
 #ifndef __STARPU_TASK_BUNDLE_H__
 #define __STARPU_TASK_BUNDLE_H__
 #define __STARPU_TASK_BUNDLE_H__
 
 
-#include <starpu.h>
-
-#if ! defined(_MSC_VER)
-#  include <pthread.h>
-#endif
+#include <starpu_perfmodel.h>
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C"
 extern "C"
 {
 {
 #endif
 #endif
 
 
-struct starpu_task_bundle_entry
-{
-	struct starpu_task *task;
-	struct starpu_task_bundle_entry *next;
-};
+struct starpu_task;
 
 
-/* The task bundle structure describes a list of tasks that should be scheduled
- * together whenever possible. */
-struct starpu_task_bundle
-{
-	/* Mutex protecting the bundle */
-#if defined(_MSC_VER)
-	void *mutex;
-#else
-	pthread_mutex_t mutex;
-#endif
-	/* last worker previously assigned a task from the bundle (-1 if none) .*/
-	int previous_workerid;
-	/* list of tasks */
-	struct starpu_task_bundle_entry *list;
-	/* If this flag is set, the bundle structure is automatically free'd
-	 * when the bundle is deinitialized. */
-	int destroy;
-	/* Is the bundle closed ? */
-	int closed;
-	/* TODO retain bundle (do not schedule until closed) */
-};
+/* starpu_task_bundle_t
+ * ==================
+ * Purpose
+ * =======
+ * Opaque structure describing a list of tasks that should be scheduled
+ * on the same worker whenever it's possible.
+ * It must be considered as a hint given to the scheduler as there is no guarantee that
+ * they will be executed on the same worker.
+ */
+typedef struct _starpu_task_bundle *starpu_task_bundle_t;
 
 
 /* Initialize a task bundle */
 /* Initialize a task bundle */
-void starpu_task_bundle_init(struct starpu_task_bundle *bundle);
+void starpu_task_bundle_init(starpu_task_bundle_t *bundle);
 
 
 /* Deinitialize a bundle. In case the destroy flag is set, the bundle structure
 /* Deinitialize a bundle. In case the destroy flag is set, the bundle structure
  * is freed too. */
  * is freed too. */
-void starpu_task_bundle_deinit(struct starpu_task_bundle *bundle);
+void starpu_task_bundle_deinit(starpu_task_bundle_t bundle);
 
 
 /* Insert a task into a bundle. */
 /* Insert a task into a bundle. */
-int starpu_task_bundle_insert(struct starpu_task_bundle *bundle, struct starpu_task *task);
+int starpu_task_bundle_insert(starpu_task_bundle_t bundle, struct starpu_task *task);
 
 
 /* Remove a task from a bundle. This method must be called with bundle->mutex
 /* Remove a task from a bundle. This method must be called with bundle->mutex
  * hold. This function returns 0 if the task was found, -ENOENT if the element
  * hold. This function returns 0 if the task was found, -ENOENT if the element
  * was not found, 1 if the element is found and if the list was deinitialized
  * was not found, 1 if the element is found and if the list was deinitialized
  * because it became empty. */
  * because it became empty. */
-int starpu_task_bundle_remove(struct starpu_task_bundle *bundle, struct starpu_task *task);
+int starpu_task_bundle_remove(starpu_task_bundle_t bundle, struct starpu_task *task);
 
 
 /* Close a bundle. No task can be added to a closed bundle. A closed bundle
 /* Close a bundle. No task can be added to a closed bundle. A closed bundle
  * automatically gets deinitialized when it becomes empty. */
  * automatically gets deinitialized when it becomes empty. */
-void starpu_task_bundle_close(struct starpu_task_bundle *bundle);
+void starpu_task_bundle_close(starpu_task_bundle_t bundle);
 
 
 /* Return the expected duration of the entire task bundle in µs. */
 /* Return the expected duration of the entire task bundle in µs. */
-double starpu_task_bundle_expected_length(struct starpu_task_bundle *bundle, enum starpu_perf_archtype arch, unsigned nimpl);
+double starpu_task_bundle_expected_length(starpu_task_bundle_t bundle, enum starpu_perf_archtype arch, unsigned nimpl);
 /* Return the time (in µs) expected to transfer all data used within the bundle */
 /* Return the time (in µs) expected to transfer all data used within the bundle */
-double starpu_task_bundle_expected_data_transfer_time(struct starpu_task_bundle *bundle, unsigned memory_node);
+double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundle, unsigned memory_node);
 /* Return the expected power consumption of the entire task bundle in J. */
 /* Return the expected power consumption of the entire task bundle in J. */
-double starpu_task_bundle_expected_power(struct starpu_task_bundle *bundle,  enum starpu_perf_archtype arch, unsigned nimpl);
+double starpu_task_bundle_expected_power(starpu_task_bundle_t bundle, enum starpu_perf_archtype arch, unsigned nimpl);
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }

+ 2 - 2
src/core/task.c

@@ -18,10 +18,10 @@
 
 
 #include <starpu.h>
 #include <starpu.h>
 #include <starpu_profiling.h>
 #include <starpu_profiling.h>
-#include <starpu_task_bundle.h>
 #include <core/workers.h>
 #include <core/workers.h>
 #include <core/jobs.h>
 #include <core/jobs.h>
 #include <core/task.h>
 #include <core/task.h>
+#include <core/task_bundle.h>
 #include <common/config.h>
 #include <common/config.h>
 #include <common/utils.h>
 #include <common/utils.h>
 #include <profiling/profiling.h>
 #include <profiling/profiling.h>
@@ -95,7 +95,7 @@ void starpu_task_deinit(struct starpu_task *task)
 	}
 	}
 
 
 	/* If case the task is (still) part of a bundle */
 	/* If case the task is (still) part of a bundle */
-	struct starpu_task_bundle *bundle = task->bundle;
+	starpu_task_bundle_t bundle = task->bundle;
 	if (bundle)
 	if (bundle)
 	{
 	{
 		_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 		_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);

+ 24 - 27
src/core/task_bundle.c

@@ -17,48 +17,45 @@
 
 
 #include <starpu.h>
 #include <starpu.h>
 #include <starpu_task_bundle.h>
 #include <starpu_task_bundle.h>
+#include <core/task_bundle.h>
 #include <starpu_scheduler.h>
 #include <starpu_scheduler.h>
 #include <common/config.h>
 #include <common/config.h>
 #include <common/utils.h>
 #include <common/utils.h>
 #include <common/list.h>
 #include <common/list.h>
 
 
 /* Initialize a task bundle */
 /* Initialize a task bundle */
-void starpu_task_bundle_init(struct starpu_task_bundle *bundle)
+void starpu_task_bundle_init(starpu_task_bundle_t *bundle)
 {
 {
-	STARPU_ASSERT(bundle);
+	*bundle = (starpu_task_bundle_t) malloc(sizeof(struct _starpu_task_bundle));
+	STARPU_ASSERT(*bundle);
 
 
-	_STARPU_PTHREAD_MUTEX_INIT(&bundle->mutex, NULL);
-	bundle->closed = 0;
+	_STARPU_PTHREAD_MUTEX_INIT(&(*bundle)->mutex, NULL);
+	(*bundle)->closed = 0;
 
 
 	/* Start with an empty list */
 	/* Start with an empty list */
-	bundle->previous_workerid = -1;
-	bundle->list = NULL;
-
-	/* By default, bundle are destroyed */
-	bundle->destroy = 1;
+	(*bundle)->list = NULL;
 
 
 }
 }
 
 
 /* Deinitialize a bundle. In case the destroy flag is set, the bundle structure
 /* Deinitialize a bundle. In case the destroy flag is set, the bundle structure
  * is freed too. */
  * is freed too. */
-void starpu_task_bundle_deinit(struct starpu_task_bundle *bundle)
+void starpu_task_bundle_deinit(starpu_task_bundle_t bundle)
 {
 {
 	/* Remove all entries from the bundle (which is likely to be empty) */
 	/* Remove all entries from the bundle (which is likely to be empty) */
 	while (bundle->list)
 	while (bundle->list)
 	{
 	{
-		struct starpu_task_bundle_entry *entry = bundle->list;
+		struct _starpu_task_bundle_entry *entry = bundle->list;
 		bundle->list = bundle->list->next;
 		bundle->list = bundle->list->next;
 		free(entry);
 		free(entry);
 	}
 	}
 
 
 	_STARPU_PTHREAD_MUTEX_DESTROY(&bundle->mutex);
 	_STARPU_PTHREAD_MUTEX_DESTROY(&bundle->mutex);
 
 
-	if (bundle->destroy)
-		free(bundle);
+	free(bundle);
 }
 }
 
 
 /* Insert a task into a bundle. */
 /* Insert a task into a bundle. */
-int starpu_task_bundle_insert(struct starpu_task_bundle *bundle, struct starpu_task *task)
+int starpu_task_bundle_insert(starpu_task_bundle_t bundle, struct starpu_task *task)
 {
 {
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 
 
@@ -78,8 +75,8 @@ int starpu_task_bundle_insert(struct starpu_task_bundle *bundle, struct starpu_t
 	}
 	}
 
 
 	/* Insert a task at the end of the bundle */
 	/* Insert a task at the end of the bundle */
-	struct starpu_task_bundle_entry *entry;
-	entry = (struct starpu_task_bundle_entry *) malloc(sizeof(struct starpu_task_bundle_entry));
+	struct _starpu_task_bundle_entry *entry;
+	entry = (struct _starpu_task_bundle_entry *) malloc(sizeof(struct _starpu_task_bundle_entry));
 	STARPU_ASSERT(entry);
 	STARPU_ASSERT(entry);
 	entry->task = task;
 	entry->task = task;
 	entry->next = NULL;
 	entry->next = NULL;
@@ -90,7 +87,7 @@ int starpu_task_bundle_insert(struct starpu_task_bundle *bundle, struct starpu_t
 	}
 	}
 	else
 	else
 	{
 	{
-		struct starpu_task_bundle_entry *item;
+		struct _starpu_task_bundle_entry *item;
 		item = bundle->list;
 		item = bundle->list;
 		while (item->next)
 		while (item->next)
 			item = item->next;
 			item = item->next;
@@ -108,9 +105,9 @@ int starpu_task_bundle_insert(struct starpu_task_bundle *bundle, struct starpu_t
  * hold. This function returns 0 if the task was found, -ENOENT if the element
  * hold. This function returns 0 if the task was found, -ENOENT if the element
  * was not found, 1 if the element is found and if the list was deinitialized
  * was not found, 1 if the element is found and if the list was deinitialized
  * because it was locked and became empty. */
  * because it was locked and became empty. */
-int starpu_task_bundle_remove(struct starpu_task_bundle *bundle, struct starpu_task *task)
+int starpu_task_bundle_remove(starpu_task_bundle_t bundle, struct starpu_task *task)
 {
 {
-	struct starpu_task_bundle_entry *item;
+	struct _starpu_task_bundle_entry *item;
 
 
 	item = bundle->list;
 	item = bundle->list;
 
 
@@ -139,7 +136,7 @@ int starpu_task_bundle_remove(struct starpu_task_bundle *bundle, struct starpu_t
 
 
 	while (item->next)
 	while (item->next)
 	{
 	{
-		struct starpu_task_bundle_entry *next;
+		struct _starpu_task_bundle_entry *next;
 		next = item->next;
 		next = item->next;
 
 
 		if (next->task == task)
 		if (next->task == task)
@@ -160,7 +157,7 @@ int starpu_task_bundle_remove(struct starpu_task_bundle *bundle, struct starpu_t
 /* Close a bundle. No task can be added to a closed bundle. Tasks can still be
 /* Close a bundle. No task can be added to a closed bundle. Tasks can still be
  * removed from a closed bundle. A closed bundle automatically gets
  * removed from a closed bundle. A closed bundle automatically gets
  * deinitialized when it becomes empty. A closed bundle cannot be reopened. */
  * deinitialized when it becomes empty. A closed bundle cannot be reopened. */
-void starpu_task_bundle_close(struct starpu_task_bundle *bundle)
+void starpu_task_bundle_close(starpu_task_bundle_t bundle)
 {
 {
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 
 
@@ -180,14 +177,14 @@ void starpu_task_bundle_close(struct starpu_task_bundle *bundle)
 }
 }
 
 
 /* Return the expected duration of the entire task bundle in µs */
 /* Return the expected duration of the entire task bundle in µs */
-double starpu_task_bundle_expected_length(struct starpu_task_bundle *bundle,  enum starpu_perf_archtype arch, unsigned nimpl)
+double starpu_task_bundle_expected_length(starpu_task_bundle_t bundle, enum starpu_perf_archtype arch, unsigned nimpl)
 {
 {
 	double expected_length = 0.0;
 	double expected_length = 0.0;
 
 
 	/* We expect the length of the bundle the be the sum of the different tasks length. */
 	/* We expect the length of the bundle the be the sum of the different tasks length. */
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 
 
-	struct starpu_task_bundle_entry *entry;
+	struct _starpu_task_bundle_entry *entry;
 	entry = bundle->list;
 	entry = bundle->list;
 
 
 	while (entry)
 	while (entry)
@@ -208,14 +205,14 @@ double starpu_task_bundle_expected_length(struct starpu_task_bundle *bundle,  en
 }
 }
 
 
 /* Return the expected power consumption of the entire task bundle in J */
 /* Return the expected power consumption of the entire task bundle in J */
-double starpu_task_bundle_expected_power(struct starpu_task_bundle *bundle,  enum starpu_perf_archtype arch, unsigned nimpl)
+double starpu_task_bundle_expected_power(starpu_task_bundle_t bundle, enum starpu_perf_archtype arch, unsigned nimpl)
 {
 {
 	double expected_power = 0.0;
 	double expected_power = 0.0;
 
 
 	/* We expect total consumption of the bundle the be the sum of the different tasks consumption. */
 	/* We expect total consumption of the bundle the be the sum of the different tasks consumption. */
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 
 
-	struct starpu_task_bundle_entry *entry;
+	struct _starpu_task_bundle_entry *entry;
 	entry = bundle->list;
 	entry = bundle->list;
 
 
 	while (entry)
 	while (entry)
@@ -289,7 +286,7 @@ static void insertion_handle_sorted(struct handle_list **listp, starpu_data_hand
 }
 }
 
 
 /* Return the time (in µs) expected to transfer all data used within the bundle */
 /* Return the time (in µs) expected to transfer all data used within the bundle */
-double starpu_task_bundle_expected_data_transfer_time(struct starpu_task_bundle *bundle, unsigned memory_node)
+double starpu_task_bundle_expected_data_transfer_time(starpu_task_bundle_t bundle, unsigned memory_node)
 {
 {
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 	_STARPU_PTHREAD_MUTEX_LOCK(&bundle->mutex);
 
 
@@ -298,7 +295,7 @@ double starpu_task_bundle_expected_data_transfer_time(struct starpu_task_bundle
 	/* We list all the handle that are accessed within the bundle. */
 	/* We list all the handle that are accessed within the bundle. */
 
 
 	/* For each task in the bundle */
 	/* For each task in the bundle */
-	struct starpu_task_bundle_entry *entry = bundle->list;
+	struct _starpu_task_bundle_entry *entry = bundle->list;
 	while (entry)
 	while (entry)
 	{
 	{
 		struct starpu_task *task = entry->task;
 		struct starpu_task *task = entry->task;

+ 101 - 0
src/core/task_bundle.h

@@ -0,0 +1,101 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2009, 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2012 Inria
+ *
+ * StarPU 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.
+ *
+ * StarPU 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 __CORE_TASK_BUNDLE_H__
+#define __CORE_TASK_BUNDLE_H__
+
+#if ! defined(_MSC_VER)
+#  include <pthread.h>
+#endif
+
+/* struct _starpu_task_bundle_entry
+ * ================================
+ * Purpose
+ * =======
+ * Structure used to describe a linked list containing tasks in _starpu_task_bundle.
+ *
+ * Fields
+ * ======
+ * task			Pointer to the task structure.
+ *
+ * next			Pointer to the next element in the linked list.
+ */
+
+struct _starpu_task_bundle_entry
+{
+	struct starpu_task *task;
+	struct _starpu_task_bundle_entry *next;
+};
+
+/* struct _starpu_task_bundle
+ * ==========================
+ * Purpose
+ * =======
+ * Structure describing a list of tasks that should be scheduled on the same
+ * worker whenever it's possible.
+ * It must be considered as a hint given to the scheduler as there is no guarantee that
+ * they will be executed on the same worker.
+ *
+ * Fields
+ * ======
+ * task			Pointer to the task structure.
+ *
+ * next			Pointer to the next element in the linked list.
+ */
+
+struct _starpu_task_bundle
+{
+	/* Mutex protecting the bundle */
+#if defined(_MSC_VER)
+	void *mutex;
+#else
+	pthread_mutex_t mutex;
+#endif
+
+	/* list of tasks */
+	struct _starpu_task_bundle_entry *list;
+
+	/* Is the bundle closed ? */
+	int closed;
+};
+
+/* struct _starpu_handle_list
+ * ==========================
+ * Purpose
+ * =======
+ * Structure describing a list of handles sorted by address to speed-up
+ * when looking for an element.
+ * The list cannot containes duplicate handles.
+ *
+ * Fields
+ * ======
+ * handle		Pointer to the handle structure.
+ *
+ * access_mode		Total access mode over the whole bundle.
+ *
+ * next			Pointer to the next element in the linked list.
+ */
+
+struct _starpu_handle_list
+{
+	starpu_data_handle_t handle;
+	enum starpu_access_mode mode;
+	struct _starpu_handle_list *next;
+};
+
+#endif // __CORE_TASK_BUNDLE_H__

+ 3 - 2
src/sched_policies/heft.c

@@ -20,8 +20,9 @@
 
 
 #include <float.h>
 #include <float.h>
 
 
-#include <core/workers.h>
 #include <core/perfmodel/perfmodel.h>
 #include <core/perfmodel/perfmodel.h>
+#include <core/task_bundle.h>
+#include <core/workers.h>
 #include <starpu_parameters.h>
 #include <starpu_parameters.h>
 #include <starpu_task_bundle.h>
 #include <starpu_task_bundle.h>
 #include <starpu_top.h>
 #include <starpu_top.h>
@@ -392,7 +393,7 @@ static int _heft_push_task(struct starpu_task *task, unsigned prio)
 	 *	and detect if there is some calibration that needs to be done.
 	 *	and detect if there is some calibration that needs to be done.
 	 */
 	 */
 
 
-	struct starpu_task_bundle *bundle = task->bundle;
+	starpu_task_bundle_t bundle = task->bundle;
 
 
 	compute_all_performance_predictions(task, local_task_length, exp_end,
 	compute_all_performance_predictions(task, local_task_length, exp_end,
 					&max_exp_end, &best_exp_end,
 					&max_exp_end, &best_exp_end,