Procházet zdrojové kódy

Multiformat : if a handle is used twice by a kernel, make sure it is only converted once.

Cyril Roelandt před 14 roky
rodič
revize
e7f5fd7334

+ 4 - 7
src/core/sched_policy.c

@@ -447,20 +447,17 @@ pick:
 		handle = task->buffers[i].handle;
 		if (!_starpu_handle_needs_conversion_task(handle, node))
 			continue;
-
 		conversion_task = _starpu_create_conversion_task(handle, node);
 		conversion_task->mf_skip = 1;
 		conversion_task->execute_on_a_specific_worker = 1;
 		conversion_task->workerid = worker_id;
+		/*
+		 * Next tasks will need to know where these handles have gone.
+		 */
+		handle->mf_node = node;
 		_starpu_task_submit_conversion_task(conversion_task, worker_id);
 	}
 
-	/*
-	 * Next tasks will need to know where these handles have gone.
-	 */
-	for (i = 0; i < task->cl->nbuffers; i++)
-		task->buffers[i].handle->mf_node = node;
-
 	task->mf_skip = 1;
 	starpu_task_list_push_front(&worker->local_tasks, task);
 	goto pick;

+ 6 - 0
tests/Makefile.am

@@ -170,6 +170,7 @@ noinst_PROGRAMS =				\
 	datawizard/interfaces/matrix/matrix_interface \
 	datawizard/interfaces/multiformat/multiformat_interface \
 	datawizard/interfaces/multiformat/advanced/multiformat_cuda_opencl \
+	datawizard/interfaces/multiformat/advanced/same_handle \
 	datawizard/interfaces/variable/variable_interface    \
 	datawizard/interfaces/vector/test_vector_interface   \
 	errorcheck/starpu_init_noworker		\
@@ -380,6 +381,11 @@ datawizard_interfaces_multiformat_advanced_multiformat_cuda_opencl_SOURCES=\
 	datawizard/interfaces/multiformat/advanced/generic.c               \
 	datawizard/interfaces/multiformat/advanced/multiformat_cuda_opencl.c
 
+datawizard_interfaces_multiformat_advanced_same_handle_SOURCES= \
+	datawizard/interfaces/multiformat/advanced/generic.c               \
+	datawizard/interfaces/multiformat/advanced/same_handle.c
+
+
 datawizard_interfaces_variable_variable_interface_SOURCES=   \
 	datawizard/interfaces/test_interfaces.c              \
 	datawizard/interfaces/variable/variable_interface.c

+ 126 - 0
tests/datawizard/interfaces/multiformat/advanced/same_handle.c

@@ -0,0 +1,126 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2011 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 <starpu.h>
+
+#include "generic.h"
+#include "../../../../helper.h"
+
+/*
+ * A single handle can be given twice to a given kernel. In this case, it
+ * should only be converted once.
+ */
+extern struct stats global_stats;
+static int vector[NX]; static starpu_data_handle_t handle;
+
+static struct starpu_codelet cl =
+{
+#ifdef STARPU_USE_CUDA
+	.cuda_funcs = { cuda_func, NULL },
+#endif
+#ifdef STARPU_USE_OPENCL
+	.opencl_funcs = { opencl_func, NULL },
+#endif
+	.nbuffers = 2,
+};
+
+static void
+register_handle(void)
+{
+	int i;
+	for (i = 0; i < NX; i++)
+		vector[i] = i;
+	starpu_multiformat_data_register(&handle, 0, vector, NX, &ops);
+}
+
+static void
+unregister_handle(void)
+{
+	starpu_data_unregister(handle);
+}
+
+static int
+create_and_submit_tasks(void)
+{
+	int ret;
+	struct starpu_task *task;
+
+	cl.where = 0;
+#ifdef STARPU_USE_CUDA
+	cl.where |= STARPU_CUDA;
+#endif
+#ifdef STARPU_USE_OPENCL
+	cl.where |= STARPU_OPENCL;
+#endif
+
+	task = starpu_task_create();
+	task->cl = &cl;
+	task->buffers[0].handle = handle;
+	task->buffers[0].mode = STARPU_RW;
+	task->buffers[1].handle = handle;
+	task->buffers[1].mode = STARPU_RW;
+
+	ret = starpu_task_submit(task);
+	if (ret == -ENODEV)
+		return -ENODEV;
+
+	return 0;
+}
+
+int
+main(void)
+{
+#if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
+	int err;
+	err = starpu_init(NULL);
+	if (err == -ENODEV)
+		goto enodev;
+
+	reset_stats(&global_stats);
+	register_handle();
+	err = create_and_submit_tasks();
+	unregister_handle();
+	starpu_shutdown();
+
+	if (err == -ENODEV)
+		goto enodev;
+
+	if (global_stats.cuda == 1)
+	{
+		if (global_stats.cpu_to_cuda == 1 &&
+		    global_stats.cuda_to_cpu == 1)
+			return EXIT_SUCCESS;
+		else
+			return EXIT_FAILURE;
+	}
+	else if (global_stats.opencl == 1)
+	{
+		if (global_stats.cpu_to_opencl == 1 &&
+		    global_stats.opencl_to_cpu == 1)
+			return EXIT_SUCCESS;
+		else
+			return EXIT_FAILURE;
+
+	}
+	else
+	{
+		/* We should not get here */
+		return EXIT_FAILURE;
+	}
+
+enodev:
+#endif
+	return STARPU_TEST_SKIPPED;
+}