소스 검색

The starpu_data_cpy function copies the content of a handle into another handle.

Cédric Augonnet 14 년 전
부모
커밋
3fb818e36e
5개의 변경된 파일145개의 추가작업 그리고 0개의 파일을 삭제
  1. 7 0
      include/starpu_util.h
  2. 1 0
      src/Makefile.am
  3. 90 0
      src/util/starpu_data_cpy.c
  4. 6 0
      tests/Makefile.am
  5. 41 0
      tests/helper/starpu_data_cpy.c

+ 7 - 0
include/starpu_util.h

@@ -159,6 +159,13 @@ void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t whe
 void starpu_create_sync_task(starpu_tag_t sync_tag, unsigned ndeps, starpu_tag_t *deps,
 				void (*callback)(void *), void *callback_arg);
 
+/* Copy the content of a handle into another handle. The last parameter
+ * indicates whether the function should be blocking or not. In the case of an
+ * asynchronous call, it is possible to synchronize with the termination of
+ * this operation either by the means of implicit dependencies (if enabled) or
+ * by calling starpu_task_wait_for_all(). */
+int starpu_data_cpy(starpu_data_handle dst_handle, starpu_data_handle src_handle, int asynchronous);
+
 /* Constants used by the starpu_insert_task helper to determine the different types of argument */
 #define STARPU_VALUE		(1<<3)	/* Pointer to a constant value */
 #define STARPU_CALLBACK		(1<<4)	/* Callback function */

+ 1 - 0
src/Makefile.am

@@ -168,6 +168,7 @@ libstarpu_la_SOURCES = 						\
 	util/starpu_create_sync_task.c				\
 	util/starpu_cublas.c					\
 	util/file.c						\
+	util/starpu_data_cpy.c					\
 	util/starpu_insert_task.c				\
 	util/starpu_task_list.c					\
 	debug/latency.c						\

+ 90 - 0
src/util/starpu_data_cpy.c

@@ -0,0 +1,90 @@
+/*
+ * 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/config.h>
+#include <datawizard/datawizard.h>
+
+static void data_cpy_func(void *descr[], void *cl_arg)
+{
+	const struct starpu_data_copy_methods *copy_methods = cl_arg;
+
+	int workerid = starpu_worker_get_id();
+	enum starpu_archtype type = starpu_worker_get_type(workerid);
+	unsigned memory_node = starpu_worker_get_memory_node(workerid);
+
+	void *dst_interface = descr[0];
+	void *src_interface = descr[1];
+
+	switch (type) {
+		case STARPU_CPU_WORKER:
+			STARPU_ASSERT(copy_methods->ram_to_ram);
+			fprintf(stderr, "PROUT CPU\n");
+			copy_methods->ram_to_ram(src_interface, memory_node, dst_interface, memory_node);
+			break;
+		case STARPU_CUDA_WORKER:
+			STARPU_ASSERT(copy_methods->cuda_to_cuda);
+			fprintf(stderr, "PROUT CUDA\n");
+			copy_methods->cuda_to_cuda(src_interface, memory_node, dst_interface, memory_node);
+			break;
+		case STARPU_OPENCL_WORKER:
+			STARPU_ASSERT(copy_methods->opencl_to_opencl);
+			fprintf(stderr, "PROUT OPENCL\n");
+			copy_methods->opencl_to_opencl(src_interface, memory_node, dst_interface, memory_node);
+			break;
+		default:
+			/* unknown architecture */
+			STARPU_ABORT();
+	}
+
+}
+
+struct starpu_perfmodel_t copy_model = {
+	.type = STARPU_HISTORY_BASED,
+	.symbol = "starpu_data_cpy"
+};
+
+static starpu_codelet copy_cl = {
+	.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
+	.cpu_func = data_cpy_func,
+	.cuda_func = data_cpy_func,
+	.opencl_func = data_cpy_func,
+	.nbuffers = 2,
+	.model = &copy_model
+};
+
+int starpu_data_cpy(starpu_data_handle dst_handle, starpu_data_handle src_handle, int asynchronous)
+{
+	const struct starpu_data_copy_methods *copy_methods = dst_handle->ops->copy_methods;
+
+	struct starpu_task *task = starpu_task_create();
+	STARPU_ASSERT(task);
+
+	task->cl = &copy_cl;
+	task->cl_arg = (void *)copy_methods;
+
+	task->buffers[0].handle = dst_handle;
+	task->buffers[0].mode = STARPU_RW;
+	task->buffers[1].handle = src_handle;
+	task->buffers[1].mode = STARPU_R;
+
+	task->synchronous = !asynchronous;
+
+	int ret = starpu_task_submit(task);
+	STARPU_ASSERT(!ret);
+
+	return 0;
+}

+ 6 - 0
tests/Makefile.am

@@ -129,6 +129,7 @@ check_PROGRAMS += 				\
 	errorcheck/invalid_blocking_calls	\
 	errorcheck/invalid_tasks		\
 	helper/cublas_init			\
+	helper/starpu_data_cpy			\
 	helper/pinned_memory			\
 	helper/execute_on_all			\
 	helper/starpu_create_sync_task		\
@@ -401,6 +402,11 @@ helper_cublas_init_SOURCES =			\
 	helper/cublas_init.c
 
 testbin_PROGRAMS +=				\
+	helper/starpu_data_cpy
+helper_starpu_data_cpy_SOURCES =		\
+	helper/starpu_data_cpy.c	
+
+testbin_PROGRAMS +=				\
 	helper/pinned_memory
 helper_pinned_memory_SOURCES =			\
 	helper/pinned_memory.c

+ 41 - 0
tests/helper/starpu_data_cpy.c

@@ -0,0 +1,41 @@
+/*
+ * 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>
+
+int var1, var2;
+starpu_data_handle var1_handle, var2_handle;
+
+int main(int argc, char **argv)
+{
+	starpu_init(NULL);
+
+	var1 = 42;
+	var2 = 0;
+
+	starpu_variable_data_register(&var1_handle, 0, (uintptr_t)&var1, sizeof(var1));
+	starpu_variable_data_register(&var2_handle, 0, (uintptr_t)&var2, sizeof(var2));
+
+	starpu_data_cpy(var2_handle, var1_handle, 0);
+
+	starpu_data_acquire(var2_handle, STARPU_R);
+	STARPU_ASSERT(var2 == 42);
+	starpu_data_release(var2_handle);
+
+	starpu_shutdown();
+
+	return 0;
+}