Browse Source

fix code and add test for using starpu_data_wont_use() on partitioned data

Nathalie Furmento 4 years ago
parent
commit
a9392aba29

+ 2 - 0
src/datawizard/coherency.h

@@ -145,8 +145,10 @@ struct _starpu_data_state
 	struct _starpu_data_state *root_handle; /** root of the tree */
 	struct _starpu_data_state *father_handle; /** father of the node, NULL if the current node is the root */
 	starpu_data_handle_t *active_children; /** The currently active set of read-write children */
+	unsigned active_nchildren;
 	starpu_data_handle_t **active_readonly_children; /** The currently active set of read-only children */
 	unsigned nactive_readonly_children; /** Size of active_readonly_children array */
+	unsigned *active_readonly_nchildren; /** Size of active_readonly_children[i] array */
 	/** Our siblings in the father partitioning */
 	unsigned nsiblings; /** How many siblings */
 	starpu_data_handle_t *siblings;

+ 8 - 0
src/datawizard/filters.c

@@ -651,6 +651,7 @@ void _starpu_data_partition_submit(starpu_data_handle_t initial_handle, unsigned
 	STARPU_ASSERT_MSG(initial_handle->part_readonly == 0, "One can't submit a partition planning while a readonly partitioning is active");
 	STARPU_ASSERT_MSG(nparts > 0, "One can't partition into 0 parts");
 	initial_handle->partitioned++;
+	initial_handle->active_nchildren = children[0]->nsiblings;
 	initial_handle->active_children = children[0]->siblings;
 	_starpu_spin_unlock(&initial_handle->header_lock);
 
@@ -715,9 +716,11 @@ void starpu_data_partition_readonly_submit(starpu_data_handle_t initial_handle,
 	if (initial_handle->nactive_readonly_children < initial_handle->partitioned)
 	{
 		_STARPU_REALLOC(initial_handle->active_readonly_children, initial_handle->partitioned * sizeof(initial_handle->active_readonly_children[0]));
+		_STARPU_REALLOC(initial_handle->active_readonly_nchildren, initial_handle->partitioned * sizeof(initial_handle->active_readonly_nchildren[0]));
 		initial_handle->nactive_readonly_children = initial_handle->partitioned;
 	}
 	initial_handle->active_readonly_children[initial_handle->partitioned-1] = children[0]->siblings;
+	initial_handle->active_readonly_nchildren[initial_handle->partitioned-1] = children[0]->nsiblings;
 	_starpu_spin_unlock(&initial_handle->header_lock);
 
 	for (i = 0; i < nparts; i++)
@@ -748,6 +751,7 @@ void starpu_data_partition_readwrite_upgrade_submit(starpu_data_handle_t initial
 	STARPU_ASSERT_MSG(initial_handle->part_readonly == 1, "One can only upgrade a readonly partition planning");
 	STARPU_ASSERT_MSG(nparts > 0, "One can't partition into 0 parts");
 	initial_handle->part_readonly = 0;
+	initial_handle->active_nchildren = initial_handle->active_readonly_nchildren[0];
 	initial_handle->active_children = initial_handle->active_readonly_children[0];
 	initial_handle->active_readonly_children[0] = NULL;
 	_starpu_spin_unlock(&initial_handle->header_lock);
@@ -782,18 +786,22 @@ void _starpu_data_unpartition_submit(starpu_data_handle_t initial_handle, unsign
 			if (initial_handle->active_readonly_children[i] == children[0]->siblings)
 			{
 				initial_handle->active_readonly_children[i] = initial_handle->active_readonly_children[initial_handle->partitioned-1];
+				initial_handle->active_readonly_nchildren[i] = initial_handle->active_readonly_nchildren[initial_handle->partitioned-1];
 				initial_handle->active_readonly_children[initial_handle->partitioned-1] = NULL;
+				initial_handle->active_readonly_nchildren[initial_handle->partitioned-1] = 0;
 				break;
 			}
 		}
 	}
 	else
 	{
+		initial_handle->active_nchildren = 0;
 		initial_handle->active_children = NULL;
 	}
 	initial_handle->partitioned--;
 	if (!initial_handle->partitioned)
 		initial_handle->part_readonly = 0;
+	initial_handle->active_nchildren = 0;
 	initial_handle->active_children = NULL;
 	_starpu_spin_unlock(&initial_handle->header_lock);
 

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

@@ -415,7 +415,9 @@ int _starpu_data_handle_init(starpu_data_handle_t handle, struct starpu_data_int
 	//handle->root_handle
 	//handle->father_handle
 	//handle->active_children = NULL;
+	//handle->active_nchildren = 0;
 	//handle->active_readonly_children = NULL;
+	//handle->active_readonly_nchildren = NULL;
 	//handle->nactive_readonly_children = 0;
 	//handle->nsiblings
 	//handle->siblings
@@ -1025,6 +1027,7 @@ retry_busy:
 
 	_starpu_data_clear_implicit(handle);
 	free(handle->active_readonly_children);
+	free(handle->active_readonly_nchildren);
 
 	STARPU_PTHREAD_MUTEX_DESTROY(&handle->busy_mutex);
 	STARPU_PTHREAD_COND_DESTROY(&handle->busy_cond);

+ 28 - 0
src/datawizard/user_interactions.c

@@ -689,6 +689,34 @@ void starpu_data_wont_use(starpu_data_handle_t handle)
 	if (!handle->initialized)
 		/* No value atm actually */
 		return;
+
+	if (starpu_data_get_nb_children(handle) != 0)
+	{
+		int i;
+		for(i=0 ; i<starpu_data_get_nb_children(handle) ; i++)
+			starpu_data_wont_use(starpu_data_get_child(handle, i));
+		return;
+	}
+
+	if (handle->nactive_readonly_children != 0)
+	{
+		unsigned i;
+		for(i=0 ; i<handle->nactive_readonly_children ; i++)
+		{
+			unsigned j;
+			for(j=0 ; j<handle->active_readonly_nchildren[i] ; j++)
+				starpu_data_wont_use(handle->active_readonly_children[i][j]);
+		}
+	}
+
+	if (handle->active_nchildren != 0)
+	{
+		unsigned j;
+		for(j=0 ; j<handle->active_nchildren ; j++)
+			starpu_data_wont_use(handle->active_children[j]);
+		return;
+	}
+
 	_STARPU_TRACE_DATA_WONT_USE(handle);
 	starpu_data_acquire_on_node_cb_sequential_consistency_quick(handle, STARPU_ACQUIRE_NO_NODE_LOCK_ALL, STARPU_R, _starpu_data_wont_use, handle, 1, 1);
 }

+ 1 - 0
tests/Makefile.am

@@ -325,6 +325,7 @@ myPROGRAMS +=				\
 	datawizard/partition_dep   		\
 	datawizard/partition_lazy		\
 	datawizard/partition_init		\
+	datawizard/partition_wontuse		\
 	datawizard/gpu_register   		\
 	datawizard/gpu_ptr_register   		\
 	datawizard/variable_parameters		\

+ 45 - 0
tests/datawizard/partition_wontuse.c

@@ -0,0 +1,45 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2020       Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <stdio.h>
+#include <starpu.h>
+#include "../helper.h"
+
+int main(int argc, char **argv)
+{
+	int ret = starpu_initialize(NULL, &argc, &argv);
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+	struct starpu_data_filter f =
+	{
+	 	.filter_func = starpu_vector_filter_block,
+		.nchildren = 2
+	};
+
+	int v[10];
+	starpu_data_handle_t array_handle;
+	starpu_vector_data_register(&array_handle, STARPU_MAIN_RAM, (uintptr_t)&v, 10, sizeof(int));
+
+	starpu_data_partition(array_handle, &f);
+	starpu_data_wont_use(array_handle);
+	starpu_data_unpartition(array_handle, STARPU_MAIN_RAM);
+
+	starpu_data_unregister(array_handle);
+	starpu_shutdown();
+
+	return 0;
+}