Browse Source

Make readonly dups know what handle they are dup for

so we can reset readonly_dup when unregistering the readonly dup.
Samuel Thibault 4 years ago
parent
commit
3db3e9d862

+ 6 - 1
src/core/dependencies/implicit_data_deps.c

@@ -232,7 +232,12 @@ struct starpu_task *_starpu_detect_implicit_data_deps_with_handle(struct starpu_
 
 			handle->initialized = 1;
 			/* We will change our value, disconnect from our readonly duplicates */
-			handle->readonly_dup = NULL;
+			if (handle->readonly_dup)
+			{
+				STARPU_ASSERT(handle->readonly_dup->readonly_dup_of == handle);
+				handle->readonly_dup->readonly_dup_of = NULL;
+				handle->readonly_dup = NULL;
+			}
 			if (write_hook)
 				write_hook(handle);
 		}

+ 3 - 0
src/datawizard/coherency.h

@@ -197,6 +197,9 @@ struct _starpu_data_state
 	/** for a non-readonly handle, a readonly-only duplicate, that we can
 	    return from starpu_data_dup_ro */
 	starpu_data_handle_t readonly_dup;
+	/** for a readonly handle, the non-readonly handle that is referencing
+	    is in its readonly_dup field. */
+	starpu_data_handle_t readonly_dup_of;
 
 	/** in some case, the application may explicitly tell StarPU that a
  	 * piece of data is not likely to be used soon again */

+ 2 - 0
src/datawizard/filters.c

@@ -251,6 +251,8 @@ static void _starpu_data_partition(starpu_data_handle_t initial_handle, starpu_d
 		child->wt_mask = initial_handle->wt_mask;
 
 		child->aliases = initial_handle->aliases;
+		//child->readonly_dup = NULL;
+		//child->readonly_dup_of = NULL;
 
 		child->is_not_important = initial_handle->is_not_important;
 

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

@@ -280,6 +280,8 @@ static void _starpu_register_new_data(starpu_data_handle_t handle,
 	handle->wt_mask = wt_mask;
 
 	//handle->aliases = 0;
+	//handle->readonly_dup = NULL;
+	//handle->readonly_dup_of = NULL;
 
 	//handle->is_not_important = 0;
 
@@ -802,6 +804,18 @@ static void _starpu_data_unregister(starpu_data_handle_t handle, unsigned cohere
 		_starpu_spin_unlock(&handle->header_lock);
 		return;
 	}
+	if (handle->readonly_dup)
+	{
+		STARPU_ASSERT(handle->readonly_dup->readonly_dup_of == handle);
+		handle->readonly_dup->readonly_dup_of = NULL;
+		handle->readonly_dup = NULL;
+	}
+	if (handle->readonly_dup_of)
+	{
+		STARPU_ASSERT(handle->readonly_dup_of->readonly_dup == handle);
+		handle->readonly_dup_of->readonly_dup = NULL;
+		handle->readonly_dup_of = NULL;
+	}
         _starpu_spin_unlock(&handle->header_lock);
 
 	int sequential_consistency = handle->sequential_consistency;

+ 1 - 0
src/util/starpu_data_cpy.c

@@ -208,6 +208,7 @@ int starpu_data_dup_ro(starpu_data_handle_t *dst_handle, starpu_data_handle_t sr
 
 	_starpu_spin_lock(&src_handle->header_lock);
 	src_handle->readonly_dup = (*dst_handle);
+	(*dst_handle)->readonly_dup_of = src_handle;
 	_starpu_spin_unlock(&src_handle->header_lock);
 
 	return 0;

+ 7 - 0
tests/helper/starpu_data_dup_ro.c

@@ -40,6 +40,13 @@ int main(int argc, char **argv)
 	ret = starpu_data_dup_ro(&var2_handle, var1_handle, 1, NULL, NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_dup_ro");
 
+	/* Free it */
+	starpu_data_unregister(var2_handle);
+
+	/* Make another duplicate of the original data */
+	ret = starpu_data_dup_ro(&var2_handle, var1_handle, 1, NULL, NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_dup_ro");
+
 	/* Make a second duplicate of the original data */
 	ret = starpu_data_dup_ro(&var3_handle, var1_handle, 1, NULL, NULL);
 	STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_dup_ro");