void_interface.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2013 Université de Bordeaux 1
  4. * Copyright (C) 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <common/config.h>
  19. #include <datawizard/coherency.h>
  20. #include <datawizard/copy_driver.h>
  21. #include <datawizard/filters.h>
  22. #include <starpu_hash.h>
  23. #include <starpu_cuda.h>
  24. #include <starpu_opencl.h>
  25. #include <drivers/opencl/driver_opencl.h>
  26. static int dummy_copy(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node);
  27. #ifdef STARPU_USE_CUDA
  28. static int dummy_cuda_copy_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cudaStream_t stream);
  29. #endif
  30. #ifdef STARPU_USE_OPENCL
  31. static int dummy_opencl_copy_async(void *src_interface, unsigned src_node, void *dst_interface, unsigned dst_node, cl_event *event);
  32. #endif
  33. static struct starpu_data_copy_methods void_copy_data_methods_s =
  34. {
  35. .ram_to_ram = dummy_copy,
  36. #ifdef STARPU_USE_CUDA
  37. .ram_to_cuda = dummy_copy,
  38. .cuda_to_ram = dummy_copy,
  39. .cuda_to_cuda = dummy_copy,
  40. .ram_to_cuda_async = dummy_cuda_copy_async,
  41. .cuda_to_ram_async = dummy_cuda_copy_async,
  42. .cuda_to_cuda_async = dummy_cuda_copy_async,
  43. #else
  44. #ifdef STARPU_SIMGRID
  45. /* Enable GPU-GPU transfers in simgrid */
  46. .cuda_to_cuda_async = 1,
  47. #endif
  48. #endif
  49. #ifdef STARPU_USE_OPENCL
  50. .ram_to_opencl = dummy_copy,
  51. .opencl_to_ram = dummy_copy,
  52. .ram_to_opencl_async = dummy_opencl_copy_async,
  53. .opencl_to_ram_async = dummy_opencl_copy_async,
  54. #endif
  55. };
  56. static void register_void_handle(starpu_data_handle_t handle, uint32_t home_node, void *data_interface);
  57. static ssize_t allocate_void_buffer_on_node(void *data_interface_, uint32_t dst_node);
  58. static void free_void_buffer_on_node(void *data_interface, uint32_t node);
  59. static size_t void_interface_get_size(starpu_data_handle_t handle);
  60. static uint32_t footprint_void_interface_crc32(starpu_data_handle_t handle);
  61. static int void_compare(void *data_interface_a, void *data_interface_b);
  62. static void display_void_interface(starpu_data_handle_t handle, FILE *f);
  63. static struct starpu_data_interface_ops interface_void_ops =
  64. {
  65. .register_data_handle = register_void_handle,
  66. .allocate_data_on_node = allocate_void_buffer_on_node,
  67. .free_data_on_node = free_void_buffer_on_node,
  68. .copy_methods = &void_copy_data_methods_s,
  69. .get_size = void_interface_get_size,
  70. .footprint = footprint_void_interface_crc32,
  71. .compare = void_compare,
  72. .interfaceid = STARPU_VOID_INTERFACE_ID,
  73. .interface_size = 0,
  74. .display = display_void_interface
  75. };
  76. static void register_void_handle(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED,
  77. uint32_t home_node STARPU_ATTRIBUTE_UNUSED,
  78. void *data_interface STARPU_ATTRIBUTE_UNUSED)
  79. {
  80. /* Since there is no real data to register, we don't do anything */
  81. }
  82. /* declare a new data with the void interface */
  83. void starpu_void_data_register(starpu_data_handle_t *handleptr)
  84. {
  85. starpu_data_register(handleptr, 0, NULL, &interface_void_ops);
  86. }
  87. static uint32_t footprint_void_interface_crc32(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  88. {
  89. return 0;
  90. }
  91. static int void_compare(void *data_interface_a STARPU_ATTRIBUTE_UNUSED,
  92. void *data_interface_b STARPU_ATTRIBUTE_UNUSED)
  93. {
  94. /* There is no allocation required, and therefore nothing to cache
  95. * anyway. */
  96. return 1;
  97. }
  98. static void display_void_interface(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, FILE *f)
  99. {
  100. fprintf(f, "void\t");
  101. }
  102. static size_t void_interface_get_size(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  103. {
  104. return 0;
  105. }
  106. /* memory allocation/deallocation primitives for the void interface */
  107. /* returns the size of the allocated area */
  108. static ssize_t allocate_void_buffer_on_node(void *data_interface STARPU_ATTRIBUTE_UNUSED,
  109. uint32_t dst_node STARPU_ATTRIBUTE_UNUSED)
  110. {
  111. /* Successfuly allocated 0 bytes */
  112. return 0;
  113. }
  114. static void free_void_buffer_on_node(void *data_interface STARPU_ATTRIBUTE_UNUSED ,
  115. uint32_t node STARPU_ATTRIBUTE_UNUSED)
  116. {
  117. /* There is no buffer actually */
  118. }
  119. static int dummy_copy(void *src_interface STARPU_ATTRIBUTE_UNUSED,
  120. unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  121. void *dst_interface STARPU_ATTRIBUTE_UNUSED,
  122. unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  123. {
  124. return 0;
  125. }
  126. #ifdef STARPU_USE_CUDA
  127. static int dummy_cuda_copy_async(void *src_interface STARPU_ATTRIBUTE_UNUSED,
  128. unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  129. void *dst_interface STARPU_ATTRIBUTE_UNUSED,
  130. unsigned dst_node STARPU_ATTRIBUTE_UNUSED,
  131. cudaStream_t stream __attribute__ ((unused)))
  132. {
  133. return 0;
  134. }
  135. #endif // STARPU_USE_CUDA
  136. #ifdef STARPU_USE_OPENCL
  137. static int dummy_opencl_copy_async(void *src_interface STARPU_ATTRIBUTE_UNUSED,
  138. unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  139. void *dst_interface STARPU_ATTRIBUTE_UNUSED,
  140. unsigned dst_node STARPU_ATTRIBUTE_UNUSED,
  141. cl_event *event STARPU_ATTRIBUTE_UNUSED)
  142. {
  143. return 0;
  144. }
  145. #endif // STARPU_USE_OPENCL