multiformat_interface.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 <starpu.h>
  17. #include "multiformat_types.h"
  18. #include "../test_interfaces.h"
  19. #include "../../../common/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 starpu_data_handle_t multiformat_handle;
  29. struct test_config multiformat_config = {
  30. .cpu_func = test_multiformat_cpu_func,
  31. #ifdef STARPU_USE_CUDA
  32. .cuda_func = test_multiformat_cuda_func,
  33. #endif
  34. #ifdef STARPU_USE_OPENCL
  35. .opencl_func = test_multiformat_opencl_func,
  36. #endif
  37. .handle = &multiformat_handle,
  38. .copy_failed = 0,
  39. .name = "multiformat_interface"
  40. };
  41. static void
  42. test_multiformat_cpu_func(void *buffers[], void *args)
  43. {
  44. struct point *aos;
  45. unsigned int n, i;
  46. int factor;
  47. aos = STARPU_MULTIFORMAT_GET_PTR(buffers[0]);
  48. n = STARPU_MULTIFORMAT_GET_NX(buffers[0]);
  49. factor = *(int *) args;
  50. for (i = 0; i < n; i++)
  51. {
  52. FPRINTF(stderr, "(%d %d) [%d]", aos[i].x, aos[i].y, factor);
  53. if (aos[i].x != i * factor || aos[i].y != i * factor)
  54. {
  55. multiformat_config.copy_failed = 1;
  56. }
  57. aos[i].x = -aos[i].x;
  58. aos[i].y = -aos[i].y;
  59. }
  60. FPRINTF(stderr, "\n");
  61. }
  62. #ifdef STARPU_USE_CUDA
  63. extern struct starpu_codelet cpu_to_cuda_cl;
  64. extern struct starpu_codelet cuda_to_cpu_cl;
  65. #endif
  66. #ifdef STARPU_USE_OPENCL
  67. extern struct starpu_codelet cpu_to_opencl_cl;
  68. extern struct starpu_codelet opencl_to_cpu_cl;
  69. #endif
  70. struct starpu_multiformat_data_interface_ops format_ops = {
  71. #ifdef STARPU_USE_CUDA
  72. .cuda_elemsize = 2* sizeof(float),
  73. .cpu_to_cuda_cl = &cpu_to_cuda_cl,
  74. .cuda_to_cpu_cl = &cuda_to_cpu_cl,
  75. #endif
  76. #ifdef STARPU_USE_OPENCL
  77. .opencl_elemsize = 2 * sizeof(float),
  78. .cpu_to_opencl_cl = &cpu_to_opencl_cl,
  79. .opencl_to_cpu_cl = &opencl_to_cpu_cl,
  80. #endif
  81. .cpu_elemsize = sizeof(struct point),
  82. };
  83. static void
  84. register_data(void)
  85. {
  86. int i;
  87. for (i = 0; i < N_ELEMENTS; i++)
  88. {
  89. array_of_structs[i].x = i;
  90. array_of_structs[i].y = i;
  91. }
  92. starpu_multiformat_data_register(&multiformat_handle,
  93. 0,
  94. &array_of_structs,
  95. N_ELEMENTS,
  96. &format_ops);
  97. }
  98. static void
  99. unregister_data(void)
  100. {
  101. starpu_data_unregister(multiformat_handle);
  102. }
  103. int
  104. main(void)
  105. {
  106. #ifdef STARPU_USE_CPU
  107. int ret;
  108. data_interface_test_summary *summary;
  109. struct starpu_conf conf = {
  110. .ncpus = -1,
  111. .ncuda = 2,
  112. .nopencl = 1
  113. };
  114. ret = starpu_init(&conf);
  115. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  116. register_data();
  117. summary = run_tests(&multiformat_config);
  118. if (!summary)
  119. exit(EXIT_FAILURE);
  120. data_interface_test_summary_print(stderr, summary);
  121. unregister_data();
  122. starpu_shutdown();
  123. return data_interface_test_summary_success(summary);
  124. #else
  125. /* Without the CPU, there is no point in using the multiformat
  126. * interface, so this test is pointless. */
  127. return STARPU_TEST_SKIPPED;
  128. #endif
  129. }