coo_interface.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2012,2013,2015,2017,2019 CNRS
  5. * Copyright (C) 2013 Université de Bordeaux
  6. * Copyright (C) 2013 Thibaut Lambert
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include <starpu.h>
  20. #include "../test_interfaces.h"
  21. #define NX 2
  22. #define NY 2
  23. #define MATRIX_SIZE (NX*NY)
  24. #if defined(STARPU_USE_CPU) || defined(STAPRU_USE_MIC)
  25. void test_coo_cpu_func(void *buffers[], void *args);
  26. #endif
  27. #ifdef STARPU_USE_CUDA
  28. extern void test_coo_cuda_func(void *buffers[], void *args);
  29. #endif
  30. #ifdef STARPU_USE_OPENCL
  31. extern void test_coo_opencl_func(void *buffers[], void *args);
  32. #endif
  33. static starpu_data_handle_t coo_handle, coo2_handle;
  34. struct test_config coo_config =
  35. {
  36. #ifdef STARPU_USE_CPU
  37. .cpu_func = test_coo_cpu_func,
  38. #endif /* ! STARPU_USE_CPU */
  39. #ifdef STARPU_USE_CUDA
  40. .cuda_func = test_coo_cuda_func,
  41. #endif /* !STARPU_USE_CUDA */
  42. #ifdef STARPU_USE_OPENCL
  43. .opencl_func = test_coo_opencl_func,
  44. #endif /* !STARPU_USE_OPENCL */
  45. #ifdef STARPU_USE_MIC
  46. .cpu_func_name = "test_coo_cpu_func",
  47. #endif
  48. .handle = &coo_handle,
  49. .dummy_handle = &coo2_handle,
  50. .copy_failed = SUCCESS,
  51. .name = "coo_interface"
  52. };
  53. void
  54. test_coo_cpu_func(void *buffers[], void *args)
  55. {
  56. int factor = *(int *) args;
  57. int *values = (int *) STARPU_COO_GET_VALUES(buffers[0]);
  58. unsigned size = STARPU_COO_GET_NVALUES(buffers[0]);
  59. int i;
  60. for (i = 0; i < (int)size; i++)
  61. {
  62. if (values[i] != i * factor)
  63. {
  64. coo_config.copy_failed = FAILURE;
  65. return;
  66. }
  67. values[i] *= -1;
  68. }
  69. }
  70. static uint32_t columns[MATRIX_SIZE];
  71. static uint32_t rows[MATRIX_SIZE];
  72. static int values[MATRIX_SIZE];
  73. static uint32_t columns2[MATRIX_SIZE];
  74. static uint32_t rows2[MATRIX_SIZE];
  75. static int values2[MATRIX_SIZE];
  76. static void
  77. register_data(void)
  78. {
  79. /*
  80. We use the following matrix :
  81. +---+---+
  82. | 0 | 1 |
  83. +---+---+
  84. | 2 | 3 |
  85. +---+---+
  86. Of course, we're not supposed to register the zeros, but it does not
  87. matter for this test.
  88. */
  89. columns[0] = 0;
  90. rows[0] = 0;
  91. values[0] = 0;
  92. columns[1] = 1;
  93. rows[1] = 0;
  94. values[1] = 1;
  95. columns[2] = 0;
  96. rows[2] = 1;
  97. values[2] = 2;
  98. columns[3] = 1;
  99. rows[3] = 1;
  100. values[3] = 3;
  101. int i;
  102. for (i = 0; i < MATRIX_SIZE; i++)
  103. {
  104. columns2[i] = -1;
  105. rows2[i] = -1;
  106. values2[i] = -1;
  107. }
  108. starpu_coo_data_register(&coo_handle,
  109. STARPU_MAIN_RAM,
  110. NX,
  111. NY,
  112. MATRIX_SIZE,
  113. columns,
  114. rows,
  115. (uintptr_t) values,
  116. sizeof(values[0]));
  117. starpu_coo_data_register(&coo2_handle,
  118. STARPU_MAIN_RAM,
  119. NX,
  120. NY,
  121. MATRIX_SIZE,
  122. columns2,
  123. rows2,
  124. (uintptr_t) values2,
  125. sizeof(values2[0]));
  126. }
  127. static void
  128. unregister_data(void)
  129. {
  130. starpu_data_unregister(coo_handle);
  131. starpu_data_unregister(coo2_handle);
  132. }
  133. int
  134. main(int argc, char **argv)
  135. {
  136. struct starpu_conf conf;
  137. struct data_interface_test_summary summary;
  138. starpu_conf_init(&conf);
  139. conf.ncuda = 2;
  140. conf.nopencl = 1;
  141. conf.nmic = -1;
  142. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  143. goto enodev;
  144. register_data();
  145. run_tests(&coo_config, &summary);
  146. unregister_data();
  147. data_interface_test_summary_print(stderr, &summary);
  148. starpu_shutdown();
  149. return data_interface_test_summary_success(&summary);
  150. enodev:
  151. return STARPU_TEST_SKIPPED;
  152. }