starpu_data_cpy.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 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 <datawizard/datawizard.h>
  19. static void data_cpy_func(void *descr[], void *cl_arg)
  20. {
  21. const struct starpu_data_copy_methods *copy_methods = (const struct starpu_data_copy_methods *) cl_arg;
  22. int workerid = starpu_worker_get_id();
  23. enum starpu_archtype type = starpu_worker_get_type(workerid);
  24. unsigned memory_node = starpu_worker_get_memory_node(workerid);
  25. void *dst_interface = descr[0];
  26. void *src_interface = descr[1];
  27. switch (type) {
  28. case STARPU_CPU_WORKER:
  29. STARPU_ASSERT(copy_methods->ram_to_ram);
  30. copy_methods->ram_to_ram(src_interface, memory_node, dst_interface, memory_node);
  31. break;
  32. case STARPU_CUDA_WORKER:
  33. STARPU_ASSERT(copy_methods->cuda_to_cuda);
  34. copy_methods->cuda_to_cuda(src_interface, memory_node, dst_interface, memory_node);
  35. break;
  36. case STARPU_OPENCL_WORKER:
  37. STARPU_ASSERT(copy_methods->opencl_to_opencl);
  38. copy_methods->opencl_to_opencl(src_interface, memory_node, dst_interface, memory_node);
  39. break;
  40. default:
  41. /* unknown architecture */
  42. STARPU_ABORT();
  43. }
  44. }
  45. struct starpu_perfmodel copy_model = {
  46. .type = STARPU_HISTORY_BASED,
  47. .symbol = "starpu_data_cpy"
  48. };
  49. static starpu_codelet copy_cl = {
  50. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  51. .cpu_func = data_cpy_func,
  52. .cuda_func = data_cpy_func,
  53. .opencl_func = data_cpy_func,
  54. .nbuffers = 2,
  55. .model = &copy_model
  56. };
  57. int starpu_data_cpy(starpu_data_handle dst_handle, starpu_data_handle src_handle,
  58. int asynchronous, void (*callback_func)(void*), void *callback_arg)
  59. {
  60. const struct starpu_data_copy_methods *copy_methods = dst_handle->ops->copy_methods;
  61. struct starpu_task *task = starpu_task_create();
  62. STARPU_ASSERT(task);
  63. task->cl = &copy_cl;
  64. task->cl_arg = (void *)copy_methods;
  65. task->callback_func = callback_func;
  66. task->callback_arg = callback_arg;
  67. task->buffers[0].handle = dst_handle;
  68. task->buffers[0].mode = STARPU_RW;
  69. task->buffers[1].handle = src_handle;
  70. task->buffers[1].mode = STARPU_R;
  71. task->synchronous = !asynchronous;
  72. int ret = starpu_task_submit(task);
  73. STARPU_ASSERT(!ret);
  74. return 0;
  75. }