coo_interface.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 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)
  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. .handle = &coo_handle,
  44. .dummy_handle = &coo2_handle,
  45. .copy_failed = SUCCESS,
  46. .name = "coo_interface"
  47. };
  48. void
  49. test_coo_cpu_func(void *buffers[], void *args)
  50. {
  51. int factor = *(int *) args;
  52. int *values = (int *) STARPU_COO_GET_VALUES(buffers[0]);
  53. unsigned size = STARPU_COO_GET_NVALUES(buffers[0]);
  54. int i;
  55. for (i = 0; i < (int)size; i++)
  56. {
  57. if (values[i] != i * factor)
  58. {
  59. coo_config.copy_failed = FAILURE;
  60. return;
  61. }
  62. values[i] *= -1;
  63. }
  64. }
  65. static uint32_t columns[MATRIX_SIZE];
  66. static uint32_t rows[MATRIX_SIZE];
  67. static int values[MATRIX_SIZE];
  68. static uint32_t columns2[MATRIX_SIZE];
  69. static uint32_t rows2[MATRIX_SIZE];
  70. static int values2[MATRIX_SIZE];
  71. static void
  72. register_data(void)
  73. {
  74. /*
  75. We use the following matrix :
  76. +---+---+
  77. | 0 | 1 |
  78. +---+---+
  79. | 2 | 3 |
  80. +---+---+
  81. Of course, we're not supposed to register the zeros, but it does not
  82. matter for this test.
  83. */
  84. columns[0] = 0;
  85. rows[0] = 0;
  86. values[0] = 0;
  87. columns[1] = 1;
  88. rows[1] = 0;
  89. values[1] = 1;
  90. columns[2] = 0;
  91. rows[2] = 1;
  92. values[2] = 2;
  93. columns[3] = 1;
  94. rows[3] = 1;
  95. values[3] = 3;
  96. int i;
  97. for (i = 0; i < MATRIX_SIZE; i++)
  98. {
  99. columns2[i] = -1;
  100. rows2[i] = -1;
  101. values2[i] = -1;
  102. }
  103. starpu_coo_data_register(&coo_handle,
  104. STARPU_MAIN_RAM,
  105. NX,
  106. NY,
  107. MATRIX_SIZE,
  108. columns,
  109. rows,
  110. (uintptr_t) values,
  111. sizeof(values[0]));
  112. starpu_coo_data_register(&coo2_handle,
  113. STARPU_MAIN_RAM,
  114. NX,
  115. NY,
  116. MATRIX_SIZE,
  117. columns2,
  118. rows2,
  119. (uintptr_t) values2,
  120. sizeof(values2[0]));
  121. }
  122. static void
  123. unregister_data(void)
  124. {
  125. starpu_data_unregister(coo_handle);
  126. starpu_data_unregister(coo2_handle);
  127. }
  128. int
  129. main(int argc, char **argv)
  130. {
  131. struct starpu_conf conf;
  132. struct data_interface_test_summary summary;
  133. starpu_conf_init(&conf);
  134. conf.ncuda = 2;
  135. conf.nopencl = 1;
  136. int ret = starpu_initialize(&conf, &argc, &argv);
  137. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  138. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  139. if(starpu_cpu_worker_get_count() == 0)
  140. {
  141. starpu_shutdown();
  142. return STARPU_TEST_SKIPPED;
  143. }
  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. }