coo_interface.c 3.7 KB

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