multiformat_interface.c 5.0 KB

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