Browse Source

Actually liberate all the resources allocated to execute a task, the
starpu_task_deinit function therefore deinitializes a task that is statically
allocated (it is also called automatically by the starpu_task_destroy
function).

Cédric Augonnet 15 years ago
parent
commit
386ec71a8d

+ 11 - 5
include/starpu-task.h

@@ -180,6 +180,12 @@ void starpu_tag_remove(starpu_tag_t id);
 /* Initialize a task structure with default values. */
 void starpu_task_init(struct starpu_task *task);
 
+/* Release all the structures automatically allocated to execute the task. This
+ * is called implicitely by starpu_task_destroy, but the task structure itself
+ * is not liberated. This should be used for statically allocated tasks for
+ * instance. */
+void starpu_task_deinit(struct starpu_task *task);
+
 /* Allocate a task structure and initialize it with default values. Tasks
  * allocated dynamically with starpu_task_create are automatically liberated
  * when the task is terminated. If the destroy flag is explicitely unset, the
@@ -187,11 +193,11 @@ void starpu_task_init(struct starpu_task *task);
  * */
 struct starpu_task *starpu_task_create(void);
 
-/* Liberate the ressource allocated during starpu_task_create. This function
- * can be called automatically after the execution of a task by setting the
- * "destroy" flag of the starpu_task structure (default behaviour). Calling
- * this function on a statically allocated task results in an undefined
- * behaviour. */
+/* Liberate the ressource allocated during the execution of the task and
+ * deallocate the task structure itself. This function can be called
+ * automatically after the execution of a task by setting the "destroy" flag of
+ * the starpu_task structure (default behaviour). Calling this function on a
+ * statically allocated task results in an undefined behaviour. */
 void starpu_task_destroy(struct starpu_task *task);
 int starpu_submit_task(struct starpu_task *task);
 

+ 5 - 0
src/core/dependencies/cg.c

@@ -34,6 +34,11 @@ void _starpu_cg_list_init(struct starpu_cg_list_s *list)
 #endif
 }
 
+void _starpu_cg_list_deinit(struct starpu_cg_list_s *list)
+{
+	free(list->succ);
+}
+
 void _starpu_add_successor_to_cg_list(struct starpu_cg_list_s *successors, starpu_cg_t *cg)
 {
 	/* where should that cg should be put in the array ? */

+ 1 - 0
src/core/dependencies/cg.h

@@ -74,6 +74,7 @@ typedef struct starpu_cg_s {
 } starpu_cg_t;
 
 void _starpu_cg_list_init(struct starpu_cg_list_s *list);
+void _starpu_cg_list_deinit(struct starpu_cg_list_s *list);
 void _starpu_add_successor_to_cg_list(struct starpu_cg_list_s *successors, starpu_cg_t *cg);
 void _starpu_notify_cg(starpu_cg_t *cg);
 void _starpu_notify_cg_list(struct starpu_cg_list_s *successors);

+ 8 - 0
src/core/jobs.c

@@ -63,6 +63,14 @@ starpu_job_t __attribute__((malloc)) _starpu_job_create(struct starpu_task *task
 	return job;
 }
 
+void _starpu_job_destroy(starpu_job_t j)
+{
+	pthread_cond_destroy(&j->sync_cond);
+	pthread_mutex_destroy(&j->sync_mutex);
+
+	_starpu_cg_list_deinit(&j->job_successors);
+}
+
 void _starpu_wait_job(starpu_job_t j)
 {
 	STARPU_ASSERT(j->task);

+ 1 - 0
src/core/jobs.h

@@ -71,6 +71,7 @@ LIST_TYPE(starpu_job,
 );
 
 starpu_job_t __attribute__((malloc)) _starpu_job_create(struct starpu_task *task);
+void _starpu_job_destroy(starpu_job_t j);
 void _starpu_wait_job(starpu_job_t j);
 
 /* try to submit job j, enqueue it if it's not schedulable yet */

+ 14 - 0
src/core/task.c

@@ -56,6 +56,18 @@ void starpu_task_init(struct starpu_task *task)
 	task->starpu_private = NULL;
 }
 
+/* Liberate all the ressources allocated for a task, without deallocating the
+ * task structure itself (this is required for statically allocated tasks). */
+void starpu_task_deinit(struct starpu_task *task)
+{
+	STARPU_ASSERT(task);
+
+	starpu_job_t j = (struct starpu_job_s *)task->starpu_private;
+
+	if (j)
+		_starpu_job_destroy(j);
+}
+
 struct starpu_task * __attribute__((malloc)) starpu_task_create(void)
 {
 	struct starpu_task *task;
@@ -80,6 +92,8 @@ void starpu_task_destroy(struct starpu_task *task)
 {
 	STARPU_ASSERT(task);
 
+	starpu_task_deinit(task);
+
 	/* TODO handle the case of task with detach = 1 and destroy = 1 */
 	/* TODO handle the case of non terminated tasks -> return -EINVAL */
 	

+ 7 - 0
tests/core/subgraph_repeat.c

@@ -119,6 +119,13 @@ int main(int argc, char **argv)
 	pthread_mutex_unlock(&mutex);
 
 	STARPU_ASSERT(check_cnt == (4*loop_cnt));
+	
+	/* Cleanup the statically allocated tasks */
+	starpu_task_deinit(&taskA);
+	starpu_task_deinit(&taskB);
+	starpu_task_deinit(&taskC);
+	starpu_task_deinit(&taskD);
+
 
 	starpu_shutdown();
 

+ 6 - 0
tests/core/subgraph_repeat_regenerate.c

@@ -120,6 +120,12 @@ int main(int argc, char **argv)
 	pthread_mutex_unlock(&mutex);
 
 	STARPU_ASSERT(check_cnt == (4*loop_cnt));
+	
+	/* Cleanup the statically allocated tasks */
+	starpu_task_deinit(&taskA);
+	starpu_task_deinit(&taskB);
+	starpu_task_deinit(&taskC);
+	starpu_task_deinit(&taskD);
 
 	starpu_shutdown();