starpu_data_cpy.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012 Université de Bordeaux 1
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include <common/config.h>
  18. #include <core/task.h>
  19. #include <datawizard/datawizard.h>
  20. #include <util/starpu_data_cpy.h>
  21. static void data_cpy_func(void *descr[], void *cl_arg)
  22. {
  23. const struct starpu_data_copy_methods *copy_methods = (const struct starpu_data_copy_methods *) cl_arg;
  24. int workerid = starpu_worker_get_id();
  25. enum starpu_archtype type = starpu_worker_get_type(workerid);
  26. unsigned memory_node = starpu_worker_get_memory_node(workerid);
  27. void *dst_interface = descr[0];
  28. void *src_interface = descr[1];
  29. switch (type)
  30. {
  31. case STARPU_CPU_WORKER:
  32. STARPU_ASSERT(copy_methods->ram_to_ram);
  33. copy_methods->ram_to_ram(src_interface, memory_node, dst_interface, memory_node);
  34. break;
  35. case STARPU_CUDA_WORKER:
  36. STARPU_ASSERT(copy_methods->cuda_to_cuda);
  37. copy_methods->cuda_to_cuda(src_interface, memory_node, dst_interface, memory_node);
  38. break;
  39. case STARPU_OPENCL_WORKER:
  40. STARPU_ASSERT(copy_methods->opencl_to_opencl);
  41. copy_methods->opencl_to_opencl(src_interface, memory_node, dst_interface, memory_node);
  42. break;
  43. default:
  44. /* unknown architecture */
  45. STARPU_ABORT();
  46. }
  47. }
  48. struct starpu_perfmodel copy_model =
  49. {
  50. .type = STARPU_HISTORY_BASED,
  51. .symbol = "starpu_data_cpy"
  52. };
  53. static struct starpu_codelet copy_cl =
  54. {
  55. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  56. .cpu_funcs = {data_cpy_func, NULL},
  57. .cuda_funcs = {data_cpy_func, NULL},
  58. .opencl_funcs = {data_cpy_func, NULL},
  59. .nbuffers = 2,
  60. .modes = {STARPU_W, STARPU_R},
  61. .model = &copy_model
  62. };
  63. int _starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle,
  64. int asynchronous, void (*callback_func)(void*), void *callback_arg,
  65. int reduction, struct starpu_task *reduction_dep_task)
  66. {
  67. const struct starpu_data_copy_methods *copy_methods = dst_handle->ops->copy_methods;
  68. struct starpu_task *task = starpu_task_create();
  69. STARPU_ASSERT(task);
  70. struct _starpu_job *j = _starpu_get_job_associated_to_task(task);
  71. if (reduction) {
  72. j->reduction_task = reduction;
  73. if (reduction_dep_task)
  74. starpu_task_declare_deps_array(task, 1, &reduction_dep_task);
  75. }
  76. task->cl = &copy_cl;
  77. task->cl_arg = (void *)copy_methods;
  78. task->callback_func = callback_func;
  79. task->callback_arg = callback_arg;
  80. task->handles[0] = dst_handle;
  81. task->handles[1] = src_handle;
  82. task->synchronous = !asynchronous;
  83. int ret = starpu_task_submit(task);
  84. STARPU_ASSERT(!ret);
  85. return 0;
  86. }
  87. int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle,
  88. int asynchronous, void (*callback_func)(void*), void *callback_arg)
  89. {
  90. return _starpu_data_cpy(dst_handle, src_handle, asynchronous, callback_func, callback_arg, 0, NULL);
  91. }