|
@@ -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 = ©_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 = ©_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;
|
|
|
+}
|