multiformat_interface.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 "multiformat_types.h"
  18. #include "../test_interfaces.h"
  19. #include "../../../helper.h"
  20. static void test_multiformat_cpu_func(void *buffers[], void *args);
  21. #ifdef STARPU_USE_CUDA
  22. extern void test_multiformat_cuda_func(void *buffers[], void *args);
  23. #endif
  24. #ifdef STARPU_USE_OPENCL
  25. extern void test_multiformat_opencl_func(void *buffers[], void *args);
  26. #endif
  27. void test_multiformat_mic_func(void *buffers[], void *args);
  28. static struct point array_of_structs[N_ELEMENTS];
  29. static struct point array_of_structs_dummy[N_ELEMENTS];
  30. static starpu_data_handle_t multiformat_handle;
  31. static starpu_data_handle_t multiformat_dummy_handle;
  32. struct test_config multiformat_config =
  33. {
  34. .cpu_func = test_multiformat_cpu_func,
  35. #ifdef STARPU_USE_CUDA
  36. .cuda_func = test_multiformat_cuda_func,
  37. #endif
  38. #ifdef STARPU_USE_OPENCL
  39. .opencl_func = test_multiformat_opencl_func,
  40. #endif
  41. .cpu_func_name = "test_multiformat_mic_func",
  42. .handle = &multiformat_handle,
  43. .dummy_handle = &multiformat_dummy_handle,
  44. .copy_failed = SUCCESS,
  45. .name = "multiformat_interface"
  46. };
  47. static void
  48. test_multiformat_cpu_func(void *buffers[], void *args)
  49. {
  50. STARPU_SKIP_IF_VALGRIND;
  51. struct point *aos;
  52. int n, i;
  53. int factor;
  54. aos = (struct point *) STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  55. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  56. factor = *(int *) args;
  57. for (i = 0; i < n; i++)
  58. {
  59. FPRINTF(stderr, "(%d %d) [%d]", aos[i].x, aos[i].y, factor);
  60. if (aos[i].x != i * factor || aos[i].y != i * factor)
  61. {
  62. multiformat_config.copy_failed = FAILURE;
  63. }
  64. aos[i].x = -aos[i].x;
  65. aos[i].y = -aos[i].y;
  66. }
  67. FPRINTF(stderr, "\n");
  68. }
  69. void test_multiformat_mic_func(void *buffers[], void *args)
  70. {
  71. STARPU_SKIP_IF_VALGRIND;
  72. printf("MIC\n");
  73. struct struct_of_arrays *soa;
  74. int n, i;
  75. int factor;
  76. soa = (struct struct_of_arrays *) STARPU_MULTIFORMAT_GET_MIC_PTR(buffers[0]);
  77. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  78. factor = *(int *) args;
  79. for (i = 0; i < n; i++)
  80. {
  81. FPRINTF(stderr, "(%d %d) [%d]", soa->x[i], soa->y[i], factor);
  82. if (soa->x[i] != i * factor || soa->y[i] != i * factor)
  83. {
  84. multiformat_config.copy_failed = 1;
  85. }
  86. soa->x[i] = -soa->x[i];
  87. soa->y[i] = -soa->y[i];
  88. }
  89. FPRINTF(stderr, "\n");
  90. }
  91. #ifdef STARPU_USE_CUDA
  92. extern struct starpu_codelet cpu_to_cuda_cl;
  93. extern struct starpu_codelet cuda_to_cpu_cl;
  94. #endif
  95. #ifdef STARPU_USE_OPENCL
  96. extern struct starpu_codelet cpu_to_opencl_cl;
  97. extern struct starpu_codelet opencl_to_cpu_cl;
  98. #endif
  99. #ifdef STARPU_USE_MIC
  100. extern struct starpu_codelet cpu_to_mic_cl;
  101. extern struct starpu_codelet mic_to_cpu_cl;
  102. #endif
  103. struct starpu_multiformat_data_interface_ops format_ops =
  104. {
  105. #ifdef STARPU_USE_CUDA
  106. .cuda_elemsize = 2* sizeof(float),
  107. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  108. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  109. #endif
  110. #ifdef STARPU_USE_OPENCL
  111. .opencl_elemsize = 2 * sizeof(float),
  112. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  113. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  114. #endif
  115. #ifdef STARPU_USE_MIC
  116. .mic_elemsize = 2 * sizeof(float),
  117. .cpu_to_mic_cl = &cpu_to_mic_cl,
  118. .mic_to_cpu_cl = &mic_to_cpu_cl,
  119. #endif
  120. .cpu_elemsize = sizeof(struct point),
  121. };
  122. static void
  123. register_data(void)
  124. {
  125. int i;
  126. for (i = 0; i < N_ELEMENTS; i++)
  127. {
  128. array_of_structs[i].x = i;
  129. array_of_structs[i].y = i;
  130. }
  131. starpu_multiformat_data_register(&multiformat_handle,
  132. STARPU_MAIN_RAM,
  133. &array_of_structs,
  134. N_ELEMENTS,
  135. &format_ops);
  136. starpu_multiformat_data_register(&multiformat_dummy_handle,
  137. STARPU_MAIN_RAM,
  138. &array_of_structs_dummy,
  139. N_ELEMENTS,
  140. &format_ops);
  141. }
  142. static void
  143. unregister_data(void)
  144. {
  145. starpu_data_unregister(multiformat_handle);
  146. starpu_data_unregister(multiformat_dummy_handle);
  147. }
  148. int main(int argc, char **argv)
  149. {
  150. #ifdef STARPU_USE_CPU
  151. int ret;
  152. struct data_interface_test_summary summary;
  153. struct starpu_conf conf;
  154. starpu_conf_init(&conf);
  155. conf.ncuda = 2;
  156. conf.nopencl = 1;
  157. conf.nmic = -1;
  158. ret = starpu_initialize(&conf, &argc, &argv);
  159. if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0)
  160. return STARPU_TEST_SKIPPED;
  161. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  162. register_data();
  163. run_tests(&multiformat_config, &summary);
  164. data_interface_test_summary_print(stderr, &summary);
  165. unregister_data();
  166. starpu_shutdown();
  167. return data_interface_test_summary_success(&summary);
  168. #else
  169. /* Without the CPU, there is no point in using the multiformat
  170. * interface, so this test is pointless. */
  171. return STARPU_TEST_SKIPPED;
  172. #endif
  173. }