Explorar o código

When using implicit_dep_handle to add a handle dependency for a non-cl task, we still need to keep a reference on the handle to be sure the handle still exists while calling _starpu_release_data_enforce_sequential_consistency at job termination

Samuel Thibault %!s(int64=12) %!d(string=hai) anos
pai
achega
915a330da7
Modificáronse 2 ficheiros con 27 adicións e 5 borrados
  1. 18 3
      src/core/dependencies/implicit_data_deps.c
  2. 9 2
      src/core/jobs.c

+ 18 - 3
src/core/dependencies/implicit_data_deps.c

@@ -90,8 +90,13 @@ static void _starpu_add_reader_after_writer(starpu_data_handle_t handle, struct
 		_STARPU_DEP_DEBUG("dep ID%lu -> %p\n", handle->last_submitted_ghost_writer_id, pre_sync_task);
 	}
 
-	if (!pre_sync_task->cl)
+	if (!pre_sync_task->cl) {
+		/* Add a reference to be released in _starpu_handle_job_termination */
+		_starpu_spin_lock(&handle->header_lock);
+		handle->busy_count++;
+		_starpu_spin_unlock(&handle->header_lock);
 		_starpu_get_job_associated_to_task(pre_sync_task)->implicit_dep_handle = handle;
+	}
 }
 
 /* Write after Read (WAR) */
@@ -155,8 +160,13 @@ static void _starpu_add_writer_after_readers(starpu_data_handle_t handle, struct
 	handle->last_submitted_readers = NULL;
 	handle->last_submitted_writer = post_sync_task;
 
-	if (!post_sync_task->cl)
+	if (!post_sync_task->cl) {
+		/* Add a reference to be released in _starpu_handle_job_termination */
+		_starpu_spin_lock(&handle->header_lock);
+		handle->busy_count++;
+		_starpu_spin_unlock(&handle->header_lock);
 		_starpu_get_job_associated_to_task(post_sync_task)->implicit_dep_handle = handle;
+	}
 }
 
 /* Write after Write (WAW) */
@@ -199,8 +209,13 @@ static void _starpu_add_writer_after_writer(starpu_data_handle_t handle, struct
 
 	handle->last_submitted_writer = post_sync_task;
 
-	if (!post_sync_task->cl)
+	if (!post_sync_task->cl) {
+		/* Add a reference to be released in _starpu_handle_job_termination */
+		_starpu_spin_lock(&handle->header_lock);
+		handle->busy_count++;
+		_starpu_spin_unlock(&handle->header_lock);
 		_starpu_get_job_associated_to_task(post_sync_task)->implicit_dep_handle = handle;
+	}
 }
 
 /* This function adds the implicit task dependencies introduced by data

+ 9 - 2
src/core/jobs.c

@@ -173,8 +173,15 @@ void _starpu_handle_job_termination(struct _starpu_job *j)
 	/* Task does not have a cl, but has explicit data dependencies, we need
 	 * to tell them that we will not exist any more before notifying the
 	 * tasks waiting for us */
-	if (j->implicit_dep_handle)
-		_starpu_release_data_enforce_sequential_consistency(j->task, j->implicit_dep_handle);
+	if (j->implicit_dep_handle) {
+		starpu_data_handle_t handle = j->implicit_dep_handle;
+		_starpu_release_data_enforce_sequential_consistency(j->task, handle);
+		/* Release reference taken while setting implicit_dep_handle */
+		_starpu_spin_lock(&handle->header_lock);
+		handle->busy_count--;
+		if (!_starpu_data_check_not_busy(handle))
+			_starpu_spin_unlock(&handle->header_lock);
+	}
 
 	/* in case there are dependencies, wake up the proper tasks */
 	_starpu_notify_dependencies(j);