Browse Source

Make more checks

Samuel Thibault 13 years ago
parent
commit
021892beba

+ 1 - 1
src/core/dependencies/cg.c

@@ -203,7 +203,7 @@ void _starpu_notify_cg_list(struct _starpu_cg_list *successors)
 			_STARPU_PTHREAD_MUTEX_UNLOCK(&j->sync_mutex);
 
 			if (must_destroy_task)
-				starpu_task_destroy(task);
+				_starpu_task_destroy(task);
 		}
 
 		if (cg_type == STARPU_CG_APPS)

+ 4 - 4
src/core/dependencies/implicit_data_deps.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -42,7 +42,7 @@ static void _starpu_add_reader_after_writer(starpu_data_handle_t handle, struct
 		_STARPU_DEP_DEBUG("RAW %p\n", handle);
 		struct starpu_task *task_array[1] = {handle->last_submitted_writer};
 		_STARPU_DEP_DEBUG("dep %p -> %p\n", handle->last_submitted_writer, pre_sync_task);
-		starpu_task_declare_deps_array(pre_sync_task, 1, task_array);
+		_starpu_task_declare_deps_array(pre_sync_task, 1, task_array, 0);
 	}
         else
         {
@@ -98,7 +98,7 @@ static void _starpu_add_writer_after_readers(starpu_data_handle_t handle, struct
 			l = l->next;
 			free(prev);
 		}
-		starpu_task_declare_deps_array(pre_sync_task, nreaders, task_array);
+		_starpu_task_declare_deps_array(pre_sync_task, nreaders, task_array, 0);
 	}
 #ifndef STARPU_USE_FXT
 	if (_starpu_bound_recording)
@@ -134,7 +134,7 @@ static void _starpu_add_writer_after_writer(starpu_data_handle_t handle, struct
 	if (handle->last_submitted_writer && handle->last_submitted_writer != post_sync_task)
 	{
 		struct starpu_task *task_array[1] = {handle->last_submitted_writer};
-		starpu_task_declare_deps_array(pre_sync_task, 1, task_array);
+		_starpu_task_declare_deps_array(pre_sync_task, 1, task_array, 0);
 		_STARPU_DEP_DEBUG("dep %p -> %p\n", handle->last_submitted_writer, pre_sync_task);
 	}
         else

+ 1 - 1
src/core/dependencies/tags.c

@@ -183,7 +183,7 @@ void _starpu_tag_set_ready(struct _starpu_tag *tag)
 	/* If the task terminated immediately (cl == NULL), we have to destroy it ourself */
 
 	if (must_destroy)
-		starpu_task_destroy(j->task);
+		_starpu_task_destroy(j->task);
 
 	_starpu_spin_lock(&tag->lock);
 }

+ 13 - 2
src/core/dependencies/task_deps.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2010-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -61,7 +61,7 @@ void _starpu_notify_task_dependencies(struct _starpu_job *j)
 }
 
 /* task depends on the tasks in task array */
-void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[])
+void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[], int check)
 {
 	if (ndeps == 0)
 		return;
@@ -70,6 +70,9 @@ void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, st
 
 	job = _starpu_get_job_associated_to_task(task);
 
+	if (check)
+		STARPU_ASSERT_MSG(!job->submitted || !task->destroy || task->detach, "Task dependencies have to be set before submission");
+
 	_STARPU_PTHREAD_MUTEX_LOCK(&job->sync_mutex);
 
 	struct _starpu_cg *cg = create_cg_task(ndeps, job);
@@ -81,7 +84,10 @@ void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, st
 
 		struct _starpu_job *dep_job;
 		dep_job = _starpu_get_job_associated_to_task(dep_task);
+
 		STARPU_ASSERT_MSG(dep_job != job, "A task must not depend on itself.");
+		if (check)
+			STARPU_ASSERT_MSG(!dep_job->submitted || !dep_job->task->destroy || dep_job->task->detach, "Task dependencies have to be set before submission");
 
 		_STARPU_TRACE_TASK_DEPS(dep_job, job);
 		_starpu_bound_task_dep(job, dep_job);
@@ -93,3 +99,8 @@ void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, st
 
 	_STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
 }
+
+void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[])
+{
+	_starpu_task_declare_deps_array(task, ndeps, task_array, 1);
+}

+ 1 - 1
src/core/jobs.c

@@ -229,7 +229,7 @@ void _starpu_handle_job_termination(struct _starpu_job *j, unsigned job_is_alrea
 		 * by the caller, it is its responsability to destroy the task.
 		 * */
 		if (!job_is_already_locked && destroy)
-			starpu_task_destroy(task);
+			_starpu_task_destroy(task);
 	}
 
 	if (regenerate)

+ 14 - 8
src/core/task.c

@@ -126,9 +126,8 @@ struct starpu_task * __attribute__((malloc)) starpu_task_create(void)
  * 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)
+void _starpu_task_destroy(struct starpu_task *task)
 {
-	STARPU_ASSERT(task);
 
    /* If starpu_task_destroy is called in a callback, we just set the destroy
       flag. The task will be destroyed after the callback returns */
@@ -148,11 +147,20 @@ void starpu_task_destroy(struct starpu_task *task)
    }
 }
 
+void starpu_task_destroy(struct starpu_task *task)
+{
+	STARPU_ASSERT(task);
+	STARPU_ASSERT_MSG(!task->destroy || !task->detach, "starpu_task_destroy must not be called for task with destroy = 1 and detach = 1");
+	_starpu_task_destroy(task);
+}
+
 int starpu_task_wait(struct starpu_task *task)
 {
         _STARPU_LOG_IN();
 	STARPU_ASSERT(task);
 
+	STARPU_ASSERT_MSG(!task->detach, "starpu_task_wait can only be called on tasks with detach = 0");
+
 	if (task->detach || task->synchronous)
 	{
 		_STARPU_DEBUG("Task is detached or asynchronous. Waiting returns immediately\n");
@@ -172,10 +180,8 @@ int starpu_task_wait(struct starpu_task *task)
 
 	/* as this is a synchronous task, the liberation of the job
 	   structure was deferred */
-	if (task->destroy) {
-		_starpu_job_destroy(j);
-		free(task);
-	}
+	if (task->destroy)
+		_starpu_task_destroy(task);
 
         _STARPU_LOG_OUT();
 	return 0;
@@ -217,7 +223,7 @@ int _starpu_submit_job(struct _starpu_job *j)
 	/* If the task terminated immediately (cl == NULL), we have to destroy it ourself */
 
 	if (must_destroy)
-		starpu_task_destroy(j->task);
+		_starpu_task_destroy(j->task);
 
         _STARPU_LOG_OUT();
         return ret;
@@ -470,7 +476,7 @@ int _starpu_task_submit_nodeps(struct starpu_task *task)
 	/* If the task terminated immediately (cl == NULL), we have to destroy it ourself */
 
 	if (must_destroy)
-		starpu_task_destroy(j->task);
+		_starpu_task_destroy(j->task);
 
 	return ret;
 }

+ 6 - 1
src/core/task.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010-2011  Université de Bordeaux 1
+ * Copyright (C) 2009-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -22,6 +22,9 @@
 #include <common/config.h>
 #include <core/jobs.h>
 
+/* Internal version of starpu_task_destroy: don't check task->destroy flag */
+void _starpu_task_destroy(struct starpu_task *task);
+
 /* In order to implement starpu_task_wait_for_all, we keep track of the number of
  * task currently submitted */
 void _starpu_decrement_nsubmitted_tasks(void);
@@ -42,6 +45,8 @@ int _starpu_submit_job(struct _starpu_job *j);
 
 int _starpu_task_submit_nodeps(struct starpu_task *task);
 
+void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[], int check);
+
 /* Returns the job structure (which is the internal data structure associated
  * to a task). */
 struct _starpu_job *_starpu_get_job_associated_to_task(struct starpu_task *task);

+ 3 - 2
src/datawizard/filters.c

@@ -119,8 +119,7 @@ void starpu_data_partition(starpu_data_handle_t initial_handle, struct starpu_da
 	/* first take care to properly lock the data header */
 	_starpu_spin_lock(&initial_handle->header_lock);
 
-	/* there should not be mutiple filters applied on the same data */
-	STARPU_ASSERT(initial_handle->nchildren == 0);
+	STARPU_ASSERT_MSG(initial_handle->nchildren == 0, "there should not be mutiple filters applied on the same data");
 
 	/* how many parts ? */
 	if (f->get_nchildren)
@@ -274,6 +273,8 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 	_starpu_spin_lock(&root_handle->header_lock);
 
+	STARPU_ASSERT_MSG(root_handle->nchildren != 0, "data is not partitioned");
+
 	/* first take all the children lock (in order !) */
 	for (child = 0; child < root_handle->nchildren; child++)
 	{

+ 3 - 1
src/datawizard/user_interactions.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009-2011  Université de Bordeaux 1
+ * Copyright (C) 2009-2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -114,6 +114,7 @@ int starpu_data_acquire_cb(starpu_data_handle_t handle,
 			   enum starpu_access_mode mode, void (*callback)(void *), void *arg)
 {
 	STARPU_ASSERT(handle);
+	STARPU_ASSERT_MSG(handle->nchildren == 0, "Acquiring a partitioned data is not possible");
         _STARPU_LOG_IN();
 
 	struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) malloc(sizeof(struct user_interaction_wrapper));
@@ -198,6 +199,7 @@ static inline void _starpu_data_acquire_continuation(void *arg)
 int starpu_data_acquire(starpu_data_handle_t handle, enum starpu_access_mode mode)
 {
 	STARPU_ASSERT(handle);
+	STARPU_ASSERT_MSG(handle->nchildren == 0, "Acquiring a partitioned data is not possible");
         _STARPU_LOG_IN();
 
 	/* unless asynchronous, it is forbidden to call this function from a callback or a codelet */

+ 1 - 0
tests/core/starpu_worker_exists.c

@@ -66,6 +66,7 @@ main(void)
 
 	task = starpu_task_create();
 	task->cl = &cl;
+	task->destroy = 0;
 
 	cl.can_execute = NULL;
 	ret = _starpu_worker_exists(task);

+ 2 - 1
tests/perfmodels/regression_based.c

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2011  Université de Bordeaux 1
+ * Copyright (C) 2011-2012  Université de Bordeaux 1
  * Copyright (C) 2011  Télécom-SudParis
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -155,6 +155,7 @@ int main(int argc, char **argv)
 	struct starpu_task *task = starpu_task_create();
 	task->cl = &memset_cl;
 	task->handles[0] = handle;
+	task->destroy = 0;
 
 	show_task_perfs(size, task);