Sfoglia il codice sorgente

Make `starpu_data_lookup' handle filters.

Ludovic Courtès 14 anni fa
parent
commit
180028d163

+ 7 - 0
src/datawizard/filters.c

@@ -220,6 +220,13 @@ void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data
 		 * store it in the handle */
 		child->data_size = child->ops->get_size(child);
 		child->footprint = _starpu_compute_data_footprint(child);
+
+		void *ptr;
+		ptr = starpu_handle_to_pointer(child);
+		if (ptr != NULL)
+		{
+			_starpu_data_register_local_pointer(child, ptr);
+		}
 	}
 	/* now let the header */
 	_starpu_spin_unlock(&initial_handle->header_lock);

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

@@ -53,7 +53,8 @@ void _starpu_data_interface_shutdown()
 	registered_handles = NULL;
 }
 
-/* Register the mapping from PTR to HANDLE.  */
+/* Register the mapping from PTR to HANDLE.  If PTR is already mapped to
+ * some handle, the new mapping shadows the previous one.   */
 void _starpu_data_register_local_pointer(starpu_data_handle handle, void *ptr)
 {
 	struct handle_entry *entry;
@@ -302,7 +303,7 @@ int starpu_data_set_rank(starpu_data_handle handle, int rank)
 
 void _starpu_data_free_interfaces(starpu_data_handle handle)
 {
-	void *ptr;
+	const void *ptr;
 	unsigned node;
 	unsigned worker;
 	unsigned nworkers = starpu_worker_get_count();
@@ -317,7 +318,9 @@ void _starpu_data_free_interfaces(starpu_data_handle handle)
 
 	if (ptr != NULL)
 	{
-		/* Remove the PTR -> HANDLE mapping.  */
+		/* Remove the PTR -> HANDLE mapping.  If a mapping from PTR
+		 * to another handle existed before (e.g., when using
+		 * filters), it becomes visible again.  */
 		struct handle_entry *entry;
 
 		_starpu_spin_lock(&registered_handles_lock);

+ 53 - 0
tests/datawizard/data_lookup.c

@@ -83,6 +83,58 @@ static void test_lazy_allocation()
 
 #define VECTOR_SIZE     123
 
+static void test_filters()
+{
+#define CHILDREN_COUNT 10
+	int err, i;
+	void *ptr, *children_pointers[CHILDREN_COUNT];
+	starpu_data_handle handle;
+
+	err = starpu_malloc(&ptr, VECTOR_SIZE * sizeof(*ptr));
+	assert(err == 0);
+
+	starpu_vector_data_register(&handle, 0, (uintptr_t)ptr,
+				    VECTOR_SIZE, sizeof(*ptr));
+
+	struct starpu_data_filter f =
+	{
+		.filter_func = starpu_block_filter_func_vector,
+		.nchildren = CHILDREN_COUNT,
+		.get_nchildren = NULL,
+		.get_child_ops = NULL
+	};
+	starpu_data_partition(handle, &f);
+	assert(starpu_data_get_nb_children(handle) == CHILDREN_COUNT);
+
+	for (i = 0; i < CHILDREN_COUNT; i++)
+	{
+                starpu_data_handle child;
+
+		child = starpu_data_get_sub_data(handle, 1, i);
+		children_pointers[i] = starpu_handle_to_pointer(child);
+		assert(children_pointers[i] != NULL);
+
+		/* Make sure we have a pointer -> handle mapping for CHILD.  */
+		assert(starpu_data_lookup(children_pointers[i]) == child);
+	}
+
+	starpu_data_unpartition(handle, 0);
+
+	for (i = 0; i < CHILDREN_COUNT; i++)
+	{
+		if (children_pointers[i] != ptr)
+			/* Make sure the pointer -> handle mapping is gone.  */
+			assert(starpu_data_lookup(children_pointers[i]) == NULL);
+	}
+
+	/* Make sure the parent's mapping is back.  */
+	assert(starpu_data_lookup(ptr) == handle);
+
+	starpu_data_unregister(handle);
+
+#undef CHILDREN_COUNT
+}
+
 int main(int argc, char *argv[])
 {
 	int err;
@@ -164,6 +216,7 @@ int main(int argc, char *argv[])
 	}
 
 	test_lazy_allocation();
+	test_filters();
 
 	starpu_shutdown();