Explorar el Código

The starpu_data_set_reduction_methods function defines the per-handle methods
to reduce two interfaces and to initialize a new interface during a reduction
phase.

Cédric Augonnet hace 14 años
padre
commit
8eb64e98ea

+ 4 - 0
include/starpu_data.h

@@ -79,6 +79,10 @@ void starpu_data_set_default_sequential_consistency_flag(unsigned flag);
 /* Query the status of the handle on the specified memory node. */
 void starpu_data_query_status(starpu_data_handle handle, int memory_node, int *is_allocated, int *is_valid, int *is_requested);
 
+void starpu_data_set_reduction_methods(starpu_data_handle handle,
+					void (*redux_func)(void *, void *),
+					void (*init_func)(void *));
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 0
src/Makefile.am

@@ -149,6 +149,7 @@ libstarpu_la_SOURCES = 						\
 	datawizard/footprint.c					\
 	datawizard/datastats.c					\
 	datawizard/user_interactions.c				\
+	datawizard/reduction.c					\
 	datawizard/interfaces/data_interface.c			\
 	datawizard/interfaces/bcsr_interface.c			\
 	datawizard/interfaces/csr_interface.c			\

+ 7 - 0
src/datawizard/coherency.h

@@ -156,6 +156,13 @@ struct starpu_data_state_t {
 	
 	struct starpu_task_wrapper_list *post_sync_tasks;
 	unsigned post_sync_tasks_cnt;
+
+	/* During reduction we need some specific methods: redux_func performs
+	 * the reduction of an interface into another one (eg. "+="), and init_func
+	 * initializes the data interface to a default value that is stable by
+	 * reduction (eg. 0 for +=). */
+	void (*redux_func)(void *dst_interface, void *src_interface);
+	void (*init_func)(void *interface);
 };
 
 void _starpu_display_msi_stats(void);

+ 5 - 0
src/datawizard/filters.c

@@ -140,6 +140,11 @@ void starpu_data_partition(starpu_data_handle initial_handle, struct starpu_data
 
 		child->sequential_consistency = initial_handle->sequential_consistency;
 
+		/* The methods used for reduction are propagated to the
+		 * children. */
+		child->redux_func = initial_handle->redux_func;
+		child->init_func = initial_handle->init_func;
+
 		unsigned node;
 		for (node = 0; node < STARPU_MAXNODES; node++)
 		{

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

@@ -53,6 +53,10 @@ static void _starpu_register_new_data(starpu_data_handle handle,
 	handle->post_sync_tasks = NULL;
 	handle->post_sync_tasks_cnt = 0;
 
+	/* By default, there are no methods available to perform a reduction */
+	handle->redux_func = NULL;
+	handle->init_func = NULL;
+
 #ifdef STARPU_USE_FXT
 	handle->last_submitted_ghost_writer_id_is_valid = 0;
 	handle->last_submitted_ghost_writer_id = 0;

+ 42 - 0
src/datawizard/reduction.c

@@ -0,0 +1,42 @@
+/*
+ * StarPU
+ * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
+ *
+ * This program 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.
+ *
+ * This program 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 <starpu.h>
+#include <common/utils.h>
+#include <datawizard/datawizard.h>
+
+void starpu_data_set_reduction_methods(starpu_data_handle handle,
+					void (*redux_func)(void *, void *),
+					void (*init_func)(void *))
+{
+	_starpu_spin_lock(&handle->header_lock);
+
+	unsigned child;
+	for (child = 0; child < handle->nchildren; child++)
+	{
+		/* make sure that the flags are applied to the children as well */
+		struct starpu_data_state_t *child_handle = &handle->children[child];
+		if (child_handle->nchildren > 0)
+			starpu_data_set_reduction_methods(child_handle, redux_func, init_func);
+	}
+
+	handle->redux_func = redux_func;
+	handle->init_func = init_func;
+
+	_starpu_spin_unlock(&handle->header_lock);
+}
+
+