multiformat_interface.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 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. static struct point array_of_structs[N_ELEMENTS];
  28. static struct point array_of_structs_dummy[N_ELEMENTS];
  29. static starpu_data_handle_t multiformat_handle;
  30. static starpu_data_handle_t multiformat_dummy_handle;
  31. struct test_config multiformat_config =
  32. {
  33. .cpu_func = test_multiformat_cpu_func,
  34. #ifdef STARPU_USE_CUDA
  35. .cuda_func = test_multiformat_cuda_func,
  36. #endif
  37. #ifdef STARPU_USE_OPENCL
  38. .opencl_func = test_multiformat_opencl_func,
  39. #endif
  40. .handle = &multiformat_handle,
  41. .dummy_handle = &multiformat_dummy_handle,
  42. .copy_failed = SUCCESS,
  43. .name = "multiformat_interface"
  44. };
  45. static void
  46. test_multiformat_cpu_func(void *buffers[], void *args)
  47. {
  48. STARPU_SKIP_IF_VALGRIND;
  49. struct point *aos;
  50. int n, i;
  51. int factor;
  52. aos = (struct point *) STARPU_MULTIFORMAT_GET_CPU_PTR(buffers[0]);
  53. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  54. factor = *(int *) args;
  55. for (i = 0; i < n; i++)
  56. {
  57. FPRINTF(stderr, "(%d %d) [%d]", aos[i].x, aos[i].y, factor);
  58. if (aos[i].x != i * factor || aos[i].y != i * factor)
  59. {
  60. multiformat_config.copy_failed = FAILURE;
  61. }
  62. aos[i].x = -aos[i].x;
  63. aos[i].y = -aos[i].y;
  64. }
  65. FPRINTF(stderr, "\n");
  66. }
  67. #ifdef STARPU_USE_CUDA
  68. extern struct starpu_codelet cpu_to_cuda_cl;
  69. extern struct starpu_codelet cuda_to_cpu_cl;
  70. #endif
  71. #ifdef STARPU_USE_OPENCL
  72. extern struct starpu_codelet cpu_to_opencl_cl;
  73. extern struct starpu_codelet opencl_to_cpu_cl;
  74. #endif
  75. struct starpu_multiformat_data_interface_ops format_ops =
  76. {
  77. #ifdef STARPU_USE_CUDA
  78. .cuda_elemsize = 2* sizeof(float),
  79. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  80. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  81. #endif
  82. #ifdef STARPU_USE_OPENCL
  83. .opencl_elemsize = 2 * sizeof(float),
  84. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  85. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  86. #endif
  87. .cpu_elemsize = sizeof(struct point),
  88. };
  89. static void
  90. register_data(void)
  91. {
  92. int i;
  93. for (i = 0; i < N_ELEMENTS; i++)
  94. {
  95. array_of_structs[i].x = i;
  96. array_of_structs[i].y = i;
  97. }
  98. starpu_multiformat_data_register(&multiformat_handle,
  99. STARPU_MAIN_RAM,
  100. &array_of_structs,
  101. N_ELEMENTS,
  102. &format_ops);
  103. starpu_multiformat_data_register(&multiformat_dummy_handle,
  104. STARPU_MAIN_RAM,
  105. &array_of_structs_dummy,
  106. N_ELEMENTS,
  107. &format_ops);
  108. }
  109. static void
  110. unregister_data(void)
  111. {
  112. starpu_data_unregister(multiformat_handle);
  113. starpu_data_unregister(multiformat_dummy_handle);
  114. }
  115. int main(int argc, char **argv)
  116. {
  117. #ifdef STARPU_USE_CPU
  118. int ret;
  119. struct data_interface_test_summary summary;
  120. struct starpu_conf conf;
  121. starpu_conf_init(&conf);
  122. conf.ncuda = 2;
  123. conf.nopencl = 1;
  124. ret = starpu_initialize(&conf, &argc, &argv);
  125. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  126. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  127. if(starpu_cpu_worker_get_count() == 0)
  128. {
  129. starpu_shutdown();
  130. return STARPU_TEST_SKIPPED;
  131. }
  132. register_data();
  133. run_tests(&multiformat_config, &summary);
  134. data_interface_test_summary_print(stderr, &summary);
  135. unregister_data();
  136. starpu_shutdown();
  137. return data_interface_test_summary_success(&summary);
  138. #else
  139. /* Without the CPU, there is no point in using the multiformat
  140. * interface, so this test is pointless. */
  141. return STARPU_TEST_SKIPPED;
  142. #endif
  143. }