Procházet zdrojové kódy

Use big fat abortions when one tries to make a task or callback sleep, instead of just returning EDEADLCK which few people will test

Samuel Thibault před 11 roky
rodič
revize
2f62b5cd10

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

@@ -432,11 +432,7 @@ int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id)
 	_STARPU_LOG_IN();
 
 	/* It is forbidden to block within callbacks or codelets */
-	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-	{
-		_STARPU_LOG_OUT_TAG("edeadlk");
-		return -EDEADLK;
-	}
+	STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_tag_wait must not be called from a task or callback");
 
 	STARPU_PTHREAD_RWLOCK_WRLOCK(&tag_global_rwlock);
 	/* only wait the tags that are not done yet */

+ 1 - 2
src/core/sched_ctx.c

@@ -808,8 +808,7 @@ int _starpu_wait_for_all_tasks_of_sched_ctx(unsigned sched_ctx_id)
 {
 	struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
 
-	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-	  return -EDEADLK;
+	STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait_for_all must not be called from a task or callback");
 
 	return _starpu_barrier_counter_wait_for_empty_counter(&sched_ctx->tasks_barrier);
 }

+ 4 - 15
src/core/task.c

@@ -196,11 +196,7 @@ int starpu_task_wait(struct starpu_task *task)
 		return -EINVAL;
 	}
 
-	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-	{
-		_STARPU_LOG_OUT_TAG("edeadlk");
-		return -EDEADLK;
-	}
+	STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait must not be called from a task or callback");
 
 	struct _starpu_job *j = (struct _starpu_job *)task->starpu_private;
 
@@ -436,12 +432,7 @@ int starpu_task_submit(struct starpu_task *task)
 	{
 		/* Perhaps it is not possible to submit a synchronous
 		 * (blocking) task */
-		if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-		{
-			_STARPU_LOG_OUT_TAG("EDEADLK");
-			return -EDEADLK;
-		}
-
+		STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "submitting a synchronous task must not be done from a task or a callback");
 		task->detach = 0;
 	}
 
@@ -735,8 +726,7 @@ int starpu_task_wait_for_all(void)
 	if (sched_ctx_id == STARPU_NMAX_SCHED_CTXS)
 	{
 		_STARPU_DEBUG("Waiting for all tasks\n");
-		if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-			return -EDEADLK;
+		STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait_for_all must not be called from a task or callback");
 
 #ifdef HAVE_AYUDAME_H
 		if (AYU_event) AYU_event(AYU_BARRIER, 0, NULL);
@@ -780,8 +770,7 @@ int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx)
  */
 int starpu_task_wait_for_no_ready(void)
 {
-	if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-		return -EDEADLK;
+	STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_task_wait_for_no_ready must not be called from a task or callback");
 
 	struct _starpu_machine_config *config = (struct _starpu_machine_config *)_starpu_get_machine_config();
 	if(config->topology.nsched_ctxs == 1)

+ 2 - 0
src/datawizard/interfaces/data_interface.c

@@ -572,6 +572,8 @@ static void _starpu_data_unregister(starpu_data_handle_t handle, unsigned cohere
 
 	if (coherent)
 	{
+		STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "starpu_data_unregister must not be called from a task or callback, perhaps you can use starpu_data_unregister_submit instead");
+
 		/* If sequential consistency is enabled, wait until data is available */
 		_starpu_data_wait_until_available(handle, STARPU_RW);
 

+ 4 - 8
src/datawizard/malloc.c

@@ -130,8 +130,7 @@ int starpu_malloc_flags(void **A, size_t dim, int flags)
 #else
 			int push_res;
 
-			if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-				return -EDEADLK;
+			STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "without CUDA peer allocation support, pinned allocation must not be done from task or callback");
 
 			struct malloc_pinned_codelet_struct s =
 			{
@@ -161,8 +160,7 @@ int starpu_malloc_flags(void **A, size_t dim, int flags)
 //#ifdef STARPU_USE_OPENCL
 //			int push_res;
 //
-//			if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-//				return -EDEADLK;
+//			STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "pinned OpenCL allocation must not be done from task or callback");
 //
 //			struct malloc_pinned_codelet_struct s =
 //				{
@@ -292,8 +290,7 @@ int starpu_free_flags(void *A, size_t dim, int flags)
 			{
 				int push_res;
 
-				if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-					return -EDEADLK;
+				STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "without CUDA peer allocation support, pinned deallocation must not be done from task or callback");
 
 				free_pinned_cl.where = STARPU_CUDA;
 				struct starpu_task *task = starpu_task_create();
@@ -317,8 +314,7 @@ int starpu_free_flags(void *A, size_t dim, int flags)
 //#ifdef STARPU_USE_OPENCL
 //		int push_res;
 //
-//		if (STARPU_UNLIKELY(!_starpu_worker_may_perform_blocking_calls()))
-//			return -EDEADLK;
+//		STARPU_ASSERT_MSG(_starpu_worker_may_perform_blocking_calls(), "pinned OpenCL deallocation must not be done from task or callback");
 //
 //                free_pinned_cl.where = STARPU_OPENCL;
 //		struct starpu_task *task = starpu_task_create();

+ 1 - 2
src/datawizard/user_interactions.c

@@ -369,8 +369,7 @@ int _starpu_prefetch_data_on_node_with_mode(starpu_data_handle_t handle, unsigne
 	STARPU_ASSERT(handle);
 
 	/* it is forbidden to call this function from a callback or a codelet */
-	if (STARPU_UNLIKELY(!async && !_starpu_worker_may_perform_blocking_calls()))
-		return -EDEADLK;
+	STARPU_ASSERT_MSG(async || _starpu_worker_may_perform_blocking_calls(), "Synchronous prefetch is not possible from a task or a callback");
 
 	struct user_interaction_wrapper *wrapper = (struct user_interaction_wrapper *) malloc(sizeof(*wrapper));