void_interface.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2014 Université de Bordeaux
  4. * Copyright (C) 2011, 2012, 2013, 2014 CNRS
  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, void *async_data);
  27. static const struct starpu_data_copy_methods void_copy_data_methods_s =
  28. {
  29. .any_to_any = dummy_copy,
  30. };
  31. static void register_void_handle(starpu_data_handle_t handle, unsigned home_node, void *data_interface);
  32. static starpu_ssize_t allocate_void_buffer_on_node(void *data_interface_, unsigned dst_node);
  33. static void free_void_buffer_on_node(void *data_interface, unsigned node);
  34. static size_t void_interface_get_size(starpu_data_handle_t handle);
  35. static uint32_t footprint_void_interface_crc32(starpu_data_handle_t handle);
  36. static int void_compare(void *data_interface_a, void *data_interface_b);
  37. static void display_void_interface(starpu_data_handle_t handle, FILE *f);
  38. static int pack_void_handle(starpu_data_handle_t handle, unsigned node, void **ptr, starpu_ssize_t *count);
  39. static int unpack_void_handle(starpu_data_handle_t handle, unsigned node, void *ptr, size_t count);
  40. static starpu_ssize_t describe(void *data_interface, char *buf, size_t size);
  41. struct starpu_data_interface_ops starpu_interface_void_ops =
  42. {
  43. .register_data_handle = register_void_handle,
  44. .allocate_data_on_node = allocate_void_buffer_on_node,
  45. .free_data_on_node = free_void_buffer_on_node,
  46. .copy_methods = &void_copy_data_methods_s,
  47. .get_size = void_interface_get_size,
  48. .footprint = footprint_void_interface_crc32,
  49. .compare = void_compare,
  50. .interfaceid = STARPU_VOID_INTERFACE_ID,
  51. .interface_size = 0,
  52. .display = display_void_interface,
  53. .pack_data = pack_void_handle,
  54. .unpack_data = unpack_void_handle,
  55. .describe = describe
  56. };
  57. static void register_void_handle(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED,
  58. unsigned home_node STARPU_ATTRIBUTE_UNUSED,
  59. void *data_interface STARPU_ATTRIBUTE_UNUSED)
  60. {
  61. /* Since there is no real data to register, we don't do anything */
  62. }
  63. /* declare a new data with the void interface */
  64. void starpu_void_data_register(starpu_data_handle_t *handleptr)
  65. {
  66. int node = STARPU_MAIN_RAM;
  67. #ifdef STARPU_USE_NUMA
  68. node = (*handleptr)->home_node;
  69. if (node < 0 || (starpu_node_get_kind(node) != STARPU_CPU_RAM))
  70. node = STARPU_MAIN_RAM;
  71. #endif /* STARPU_USE_NUMA */
  72. starpu_data_register(handleptr, node, NULL, &starpu_interface_void_ops);
  73. }
  74. static uint32_t footprint_void_interface_crc32(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  75. {
  76. return 0;
  77. }
  78. static int void_compare(void *data_interface_a STARPU_ATTRIBUTE_UNUSED,
  79. void *data_interface_b STARPU_ATTRIBUTE_UNUSED)
  80. {
  81. /* There is no allocation required, and therefore nothing to cache
  82. * anyway. */
  83. return 1;
  84. }
  85. static void display_void_interface(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, FILE *f)
  86. {
  87. fprintf(f, "void\t");
  88. }
  89. static int pack_void_handle(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED,
  90. unsigned node STARPU_ATTRIBUTE_UNUSED,
  91. void **ptr,
  92. starpu_ssize_t *count)
  93. {
  94. *count = 0;
  95. *ptr = NULL;
  96. return 0;
  97. }
  98. static int unpack_void_handle(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED,
  99. unsigned node STARPU_ATTRIBUTE_UNUSED,
  100. void *ptr STARPU_ATTRIBUTE_UNUSED,
  101. size_t count STARPU_ATTRIBUTE_UNUSED)
  102. {
  103. return 0;
  104. }
  105. static size_t void_interface_get_size(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  106. {
  107. return 0;
  108. }
  109. /* memory allocation/deallocation primitives for the void interface */
  110. /* returns the size of the allocated area */
  111. static starpu_ssize_t allocate_void_buffer_on_node(void *data_interface STARPU_ATTRIBUTE_UNUSED,
  112. unsigned dst_node STARPU_ATTRIBUTE_UNUSED)
  113. {
  114. /* Successfuly allocated 0 bytes */
  115. return 0;
  116. }
  117. static void free_void_buffer_on_node(void *data_interface STARPU_ATTRIBUTE_UNUSED ,
  118. unsigned node STARPU_ATTRIBUTE_UNUSED)
  119. {
  120. /* There is no buffer actually */
  121. }
  122. static int dummy_copy(void *src_interface STARPU_ATTRIBUTE_UNUSED,
  123. unsigned src_node STARPU_ATTRIBUTE_UNUSED,
  124. void *dst_interface STARPU_ATTRIBUTE_UNUSED,
  125. unsigned dst_node STARPU_ATTRIBUTE_UNUSED,
  126. void *async_data STARPU_ATTRIBUTE_UNUSED)
  127. {
  128. return 0;
  129. }
  130. static starpu_ssize_t describe(void *data_interface STARPU_ATTRIBUTE_UNUSED, char *buf, size_t size)
  131. {
  132. return snprintf(buf, size, "0");
  133. }