multiformat_interface.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2011-2015,2017,2019 CNRS
  5. * Copyright (C) 2012,2013 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "multiformat_types.h"
  20. #include "../test_interfaces.h"
  21. #include "../../../helper.h"
  22. static void test_multiformat_cpu_func(void *buffers[], void *args);
  23. #ifdef STARPU_USE_CUDA
  24. extern void test_multiformat_cuda_func(void *buffers[], void *args);
  25. #endif
  26. #ifdef STARPU_USE_OPENCL
  27. extern void test_multiformat_opencl_func(void *buffers[], void *args);
  28. #endif
  29. void test_multiformat_mic_func(void *buffers[], void *args);
  30. static struct point array_of_structs[N_ELEMENTS];
  31. static struct point array_of_structs_dummy[N_ELEMENTS];
  32. static starpu_data_handle_t multiformat_handle;
  33. static starpu_data_handle_t multiformat_dummy_handle;
  34. struct test_config multiformat_config =
  35. {
  36. .cpu_func = test_multiformat_cpu_func,
  37. #ifdef STARPU_USE_CUDA
  38. .cuda_func = test_multiformat_cuda_func,
  39. #endif
  40. #ifdef STARPU_USE_OPENCL
  41. .opencl_func = test_multiformat_opencl_func,
  42. #endif
  43. .cpu_func_name = "test_multiformat_mic_func",
  44. .handle = &multiformat_handle,
  45. .dummy_handle = &multiformat_dummy_handle,
  46. .copy_failed = SUCCESS,
  47. .name = "multiformat_interface"
  48. };
  49. static void
  50. test_multiformat_cpu_func(void *buffers[], void *args)
  51. {
  52. STARPU_SKIP_IF_VALGRIND;
  53. struct point *aos;
  54. int n, i;
  55. int factor;
  56. aos = (struct point *) STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  57. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  58. factor = *(int *) args;
  59. for (i = 0; i < n; i++)
  60. {
  61. FPRINTF(stderr, "(%d %d) [%d]", aos[i].x, aos[i].y, factor);
  62. if (aos[i].x != i * factor || aos[i].y != i * factor)
  63. {
  64. multiformat_config.copy_failed = FAILURE;
  65. }
  66. aos[i].x = -aos[i].x;
  67. aos[i].y = -aos[i].y;
  68. }
  69. FPRINTF(stderr, "\n");
  70. }
  71. void test_multiformat_mic_func(void *buffers[], void *args)
  72. {
  73. STARPU_SKIP_IF_VALGRIND;
  74. printf("MIC\n");
  75. struct struct_of_arrays *soa;
  76. int n, i;
  77. int factor;
  78. soa = (struct struct_of_arrays *) STARPU_MULTIFORMAT_GET_MIC_PTR(buffers[0]);
  79. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  80. factor = *(int *) args;
  81. for (i = 0; i < n; i++)
  82. {
  83. FPRINTF(stderr, "(%d %d) [%d]", soa->x[i], soa->y[i], factor);
  84. if (soa->x[i] != i * factor || soa->y[i] != i * factor)
  85. {
  86. multiformat_config.copy_failed = 1;
  87. }
  88. soa->x[i] = -soa->x[i];
  89. soa->y[i] = -soa->y[i];
  90. }
  91. FPRINTF(stderr, "\n");
  92. }
  93. #ifdef STARPU_USE_CUDA
  94. extern struct starpu_codelet cpu_to_cuda_cl;
  95. extern struct starpu_codelet cuda_to_cpu_cl;
  96. #endif
  97. #ifdef STARPU_USE_OPENCL
  98. extern struct starpu_codelet cpu_to_opencl_cl;
  99. extern struct starpu_codelet opencl_to_cpu_cl;
  100. #endif
  101. #ifdef STARPU_USE_MIC
  102. extern struct starpu_codelet cpu_to_mic_cl;
  103. extern struct starpu_codelet mic_to_cpu_cl;
  104. #endif
  105. struct starpu_multiformat_data_interface_ops format_ops =
  106. {
  107. #ifdef STARPU_USE_CUDA
  108. .cuda_elemsize = 2* sizeof(float),
  109. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  110. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  111. #endif
  112. #ifdef STARPU_USE_OPENCL
  113. .opencl_elemsize = 2 * sizeof(float),
  114. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  115. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  116. #endif
  117. #ifdef STARPU_USE_MIC
  118. .mic_elemsize = 2 * sizeof(float),
  119. .cpu_to_mic_cl = &cpu_to_mic_cl,
  120. .mic_to_cpu_cl = &mic_to_cpu_cl,
  121. #endif
  122. .cpu_elemsize = sizeof(struct point),
  123. };
  124. static void
  125. register_data(void)
  126. {
  127. int i;
  128. for (i = 0; i < N_ELEMENTS; i++)
  129. {
  130. array_of_structs[i].x = i;
  131. array_of_structs[i].y = i;
  132. }
  133. starpu_multiformat_data_register(&multiformat_handle,
  134. STARPU_MAIN_RAM,
  135. &array_of_structs,
  136. N_ELEMENTS,
  137. &format_ops);
  138. starpu_multiformat_data_register(&multiformat_dummy_handle,
  139. STARPU_MAIN_RAM,
  140. &array_of_structs_dummy,
  141. N_ELEMENTS,
  142. &format_ops);
  143. }
  144. static void
  145. unregister_data(void)
  146. {
  147. starpu_data_unregister(multiformat_handle);
  148. starpu_data_unregister(multiformat_dummy_handle);
  149. }
  150. int main(int argc, char **argv)
  151. {
  152. #ifdef STARPU_USE_CPU
  153. int ret;
  154. struct data_interface_test_summary summary;
  155. struct starpu_conf conf;
  156. starpu_conf_init(&conf);
  157. conf.ncuda = 2;
  158. conf.nopencl = 1;
  159. conf.nmic = -1;
  160. ret = starpu_initialize(&conf, &argc, &argv);
  161. if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)
  162. return STARPU_TEST_SKIPPED;
  163. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  164. register_data();
  165. run_tests(&multiformat_config, &summary);
  166. data_interface_test_summary_print(stderr, &summary);
  167. unregister_data();
  168. starpu_shutdown();
  169. return data_interface_test_summary_success(&summary);
  170. #else
  171. /* Without the CPU, there is no point in using the multiformat
  172. * interface, so this test is pointless. */
  173. return STARPU_TEST_SKIPPED;
  174. #endif
  175. }