multiformat_interface.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  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. #if STARPU_HAVE_VALGRIND_H
  18. #include <valgrind/valgrind.h>
  19. #endif
  20. #include <starpu.h>
  21. #include "multiformat_types.h"
  22. #include "../test_interfaces.h"
  23. #include "../../../helper.h"
  24. static void test_multiformat_cpu_func(void *buffers[], void *args);
  25. #ifdef STARPU_USE_CUDA
  26. extern void test_multiformat_cuda_func(void *buffers[], void *args);
  27. #endif
  28. #ifdef STARPU_USE_OPENCL
  29. extern void test_multiformat_opencl_func(void *buffers[], void *args);
  30. #endif
  31. static struct point array_of_structs[N_ELEMENTS];
  32. static struct point array_of_structs_dummy[N_ELEMENTS];
  33. static starpu_data_handle_t multiformat_handle;
  34. static starpu_data_handle_t multiformat_dummy_handle;
  35. struct test_config multiformat_config =
  36. {
  37. .cpu_func = test_multiformat_cpu_func,
  38. #ifdef STARPU_USE_CUDA
  39. .cuda_func = test_multiformat_cuda_func,
  40. #endif
  41. #ifdef STARPU_USE_OPENCL
  42. .opencl_func = test_multiformat_opencl_func,
  43. #endif
  44. .handle = &multiformat_handle,
  45. .dummy_handle = &multiformat_dummy_handle,
  46. .copy_failed = 0,
  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. unsigned int n, i;
  55. int factor;
  56. aos = (struct point *) STARPU_MULTIFORMAT_GET_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 = 1;
  65. }
  66. aos[i].x = -aos[i].x;
  67. aos[i].y = -aos[i].y;
  68. }
  69. FPRINTF(stderr, "\n");
  70. }
  71. #ifdef STARPU_USE_CUDA
  72. extern struct starpu_codelet cpu_to_cuda_cl;
  73. extern struct starpu_codelet cuda_to_cpu_cl;
  74. #endif
  75. #ifdef STARPU_USE_OPENCL
  76. extern struct starpu_codelet cpu_to_opencl_cl;
  77. extern struct starpu_codelet opencl_to_cpu_cl;
  78. #endif
  79. struct starpu_multiformat_data_interface_ops format_ops =
  80. {
  81. #ifdef STARPU_USE_CUDA
  82. .cuda_elemsize = 2* sizeof(float),
  83. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  84. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  85. #endif
  86. #ifdef STARPU_USE_OPENCL
  87. .opencl_elemsize = 2 * sizeof(float),
  88. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  89. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  90. #endif
  91. .cpu_elemsize = sizeof(struct point),
  92. };
  93. static void
  94. register_data(void)
  95. {
  96. int i;
  97. for (i = 0; i < N_ELEMENTS; i++)
  98. {
  99. array_of_structs[i].x = i;
  100. array_of_structs[i].y = i;
  101. }
  102. starpu_multiformat_data_register(&multiformat_handle,
  103. 0,
  104. &array_of_structs,
  105. N_ELEMENTS,
  106. &format_ops);
  107. starpu_multiformat_data_register(&multiformat_dummy_handle,
  108. 0,
  109. &array_of_structs_dummy,
  110. N_ELEMENTS,
  111. &format_ops);
  112. }
  113. static void
  114. unregister_data(void)
  115. {
  116. starpu_data_unregister(multiformat_handle);
  117. starpu_data_unregister(multiformat_dummy_handle);
  118. }
  119. int
  120. main(void)
  121. {
  122. #ifdef STARPU_USE_CPU
  123. int ret;
  124. data_interface_test_summary *summary;
  125. struct starpu_conf conf =
  126. {
  127. .ncpus = -1,
  128. .ncuda = 2,
  129. .nopencl = 1
  130. };
  131. ret = starpu_init(&conf);
  132. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  133. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  134. register_data();
  135. summary = run_tests(&multiformat_config);
  136. if (!summary)
  137. exit(EXIT_FAILURE);
  138. data_interface_test_summary_print(stderr, summary);
  139. unregister_data();
  140. starpu_shutdown();
  141. return data_interface_test_summary_success(summary);
  142. #else
  143. /* Without the CPU, there is no point in using the multiformat
  144. * interface, so this test is pointless. */
  145. return STARPU_TEST_SKIPPED;
  146. #endif
  147. }