Browse Source

starpu_data_release_to: also accept not changing the mode

Samuel Thibault 4 years ago
parent
commit
04f2344a83

+ 3 - 3
include/starpu_data.h

@@ -360,9 +360,9 @@ void starpu_data_release_on_node(starpu_data_handle_t handle, int node);
    Partly release the piece of data acquired by the application either by
    Partly release the piece of data acquired by the application either by
    starpu_data_acquire() or by starpu_data_acquire_cb(), switching the
    starpu_data_acquire() or by starpu_data_acquire_cb(), switching the
    acquisition down to \p down_to_mode. For now, only releasing from STARPU_RW
    acquisition down to \p down_to_mode. For now, only releasing from STARPU_RW
-   or STARPU_W acquisition down to STARPU_R is supported.  STARPU_NONE can also
-   be passed as \p down_to_mode, in which case this is equivalent to calling
-   starpu_data_release().
+   or STARPU_W acquisition down to STARPU_R is supported, or down to the same
+   acquisition.  STARPU_NONE can also be passed as \p down_to_mode, in which
+   case this is equivalent to calling starpu_data_release().
 */
 */
 void starpu_data_release_to(starpu_data_handle_t handle, enum starpu_data_access_mode down_to_mode);
 void starpu_data_release_to(starpu_data_handle_t handle, enum starpu_data_access_mode down_to_mode);
 
 

+ 2 - 4
src/core/dependencies/data_arbiter_concurrency.c

@@ -558,8 +558,7 @@ void _starpu_notify_arbitered_dependencies(starpu_data_handle_t handle, enum sta
 			/* Downgrade from W or RW down to R, keeping the same reference,
 			/* Downgrade from W or RW down to R, keeping the same reference,
 			 * but thus allowing other readers without allowing writers.  */
 			 * but thus allowing other readers without allowing writers.  */
 			STARPU_ASSERT(down_to_mode == STARPU_R &&
 			STARPU_ASSERT(down_to_mode == STARPU_R &&
-					(handle->current_mode == STARPU_RW ||
-					 handle->current_mode == STARPU_W));
+				      handle->current_mode == STARPU_W);
 			handle->current_mode = down_to_mode;
 			handle->current_mode = down_to_mode;
 		}
 		}
 #ifndef LOCK_OR_DELEGATE
 #ifndef LOCK_OR_DELEGATE
@@ -586,8 +585,7 @@ void _starpu_notify_arbitered_dependencies(starpu_data_handle_t handle, enum sta
 		/* Downgrade from W or RW down to R, keeping the same reference,
 		/* Downgrade from W or RW down to R, keeping the same reference,
 		 * but thus allowing other readers without allowing writers.  */
 		 * but thus allowing other readers without allowing writers.  */
 		STARPU_ASSERT(down_to_mode == STARPU_R &&
 		STARPU_ASSERT(down_to_mode == STARPU_R &&
-				(handle->current_mode == STARPU_RW ||
-				 handle->current_mode == STARPU_W));
+			      handle->current_mode == STARPU_W);
 		handle->current_mode = down_to_mode;
 		handle->current_mode = down_to_mode;
 	}
 	}
 	/* There should be at least one busy_count reference for the waiter
 	/* There should be at least one busy_count reference for the waiter

+ 6 - 0
src/core/dependencies/data_concurrency.c

@@ -513,6 +513,12 @@ int _starpu_notify_data_dependencies(starpu_data_handle_t handle, enum starpu_da
 {
 {
 	_starpu_spin_checklocked(&handle->header_lock);
 	_starpu_spin_checklocked(&handle->header_lock);
 
 
+	if (down_to_mode != STARPU_NONE && handle->current_mode == down_to_mode)
+	{
+		/* No change, nothing to do */
+		return 0;
+	}
+
 	if (handle->arbiter)
 	if (handle->arbiter)
 	{
 	{
 		/* Keep our reference for now, _starpu_notify_arbitered_dependencies
 		/* Keep our reference for now, _starpu_notify_arbitered_dependencies

+ 7 - 3
src/datawizard/user_interactions.c

@@ -489,11 +489,15 @@ void starpu_data_release_to_on_node(starpu_data_handle_t handle, enum starpu_dat
 {
 {
 	STARPU_ASSERT(handle);
 	STARPU_ASSERT(handle);
 
 
+	if (mode == STARPU_RW)
+		/* They are equivalent here, and current_mode is never STARPU_RW */
+		mode = STARPU_W;
+
 	STARPU_ASSERT_MSG(mode == STARPU_NONE ||
 	STARPU_ASSERT_MSG(mode == STARPU_NONE ||
+			  mode == handle->current_mode ||
 			  (mode == STARPU_R &&
 			  (mode == STARPU_R &&
-			    (handle->current_mode == STARPU_RW ||
-			     handle->current_mode == STARPU_W)),
-		"We only support releasing from W or RW to R");
+			     handle->current_mode == STARPU_W),
+		"We only support releasing from W to R");
 
 
 	/* In case there are some implicit dependencies, unlock the "post sync" tasks */
 	/* In case there are some implicit dependencies, unlock the "post sync" tasks */
 	_starpu_unlock_post_sync_tasks(handle);
 	_starpu_unlock_post_sync_tasks(handle);

+ 5 - 0
tests/datawizard/acquire_release_to.c

@@ -109,6 +109,8 @@ void callback(void *arg)
 {
 {
 	(void)arg;
 	(void)arg;
 	token++;
 	token++;
+	starpu_data_release_to(token_handle, STARPU_W);
+	starpu_sleep(0.001);
 	starpu_data_release_to(token_handle, STARPU_R);
 	starpu_data_release_to(token_handle, STARPU_R);
 	starpu_sleep(0.001);
 	starpu_sleep(0.001);
 	starpu_data_release(token_handle);
 	starpu_data_release(token_handle);
@@ -156,6 +158,9 @@ int main(int argc, char **argv)
 		STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
 		STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
 
 
 		starpu_sleep(0.001);
 		starpu_sleep(0.001);
+		starpu_data_release_to(token_handle, STARPU_W);
+
+		starpu_sleep(0.001);
 		starpu_data_release_to(token_handle, STARPU_R);
 		starpu_data_release_to(token_handle, STARPU_R);
 
 
 		starpu_sleep(0.001);
 		starpu_sleep(0.001);