bcsr_interface.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 "../test_interfaces.h"
  18. #include "../../../helper.h"
  19. /*
  20. * In this test, we use the following matrix:
  21. *
  22. * +----------------+
  23. * | 0 1 0 0 |
  24. * | 2 3 0 0 |
  25. * | 4 5 8 9 |
  26. * | 6 7 10 11 |
  27. * +----------------+
  28. *
  29. * nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11]
  30. * colind = [0, 0, 1]
  31. * rowptr = [0, 1, 3 ]
  32. * r = c = 2
  33. */
  34. /* Size of the blocks */
  35. #define R 2
  36. #define C 2
  37. #define NNZ_BLOCKS 3 /* out of 4 */
  38. #define NZVAL_SIZE (R*C*NNZ_BLOCKS)
  39. #define NROWS 2
  40. #ifdef STARPU_USE_CPU
  41. void test_bcsr_cpu_func(void *buffers[], void *args);
  42. #endif /* !STARPU_USE_CPU */
  43. #ifdef STARPU_USE_CUDA
  44. extern void test_bcsr_cuda_func(void *buffers[], void *_args);
  45. #endif /* !STARPU_USE_CUDA */
  46. #ifdef STARPU_USE_OPENCL
  47. extern void test_bcsr_opencl_func(void *buffers[], void *args);
  48. #endif /* !STARPU_USE_OPENCL */
  49. static int nzval[NZVAL_SIZE] =
  50. {
  51. 0, 1, 2, 3, /* First block */
  52. 4, 5, 6, 7, /* Second block */
  53. 8, 9, 10, 11 /* Third block */
  54. };
  55. static int nzval2[NZVAL_SIZE];
  56. static uint32_t colind[NNZ_BLOCKS] = { 0, 0, 1 };
  57. static uint32_t colind2[NNZ_BLOCKS];
  58. static uint32_t rowptr[NROWS+1] = { 0, 1, NNZ_BLOCKS };
  59. static uint32_t rowptr2[NROWS+1] = { 0, 0, NNZ_BLOCKS };
  60. static starpu_data_handle_t bcsr_handle;
  61. static starpu_data_handle_t bcsr2_handle;
  62. struct test_config bcsr_config =
  63. {
  64. #ifdef STARPU_USE_CPU
  65. .cpu_func = test_bcsr_cpu_func,
  66. #endif /* !STARPU_USE_CPU */
  67. #ifdef STARPU_USE_CUDA
  68. .cuda_func = test_bcsr_cuda_func,
  69. #endif /* !STARPU_USE_CUDA */
  70. #ifdef STARPU_USE_OPENCL
  71. .opencl_func = test_bcsr_opencl_func,
  72. #endif /* !STARPU_USE_OPENCL */
  73. .handle = &bcsr_handle,
  74. .dummy_handle = &bcsr2_handle,
  75. .copy_failed = SUCCESS,
  76. .name = "bcsr_interface"
  77. };
  78. static void
  79. register_data(void)
  80. {
  81. starpu_bcsr_data_register(&bcsr_handle,
  82. STARPU_MAIN_RAM,
  83. NNZ_BLOCKS,
  84. NROWS,
  85. (uintptr_t) nzval,
  86. colind,
  87. rowptr,
  88. 0, /* firstentry */
  89. R,
  90. C,
  91. sizeof(nzval[0]));
  92. starpu_bcsr_data_register(&bcsr2_handle,
  93. STARPU_MAIN_RAM,
  94. NNZ_BLOCKS,
  95. NROWS,
  96. (uintptr_t) nzval2,
  97. colind2,
  98. rowptr2,
  99. 0, /* firstentry */
  100. R,
  101. C,
  102. sizeof(nzval2[0]));
  103. }
  104. static void
  105. unregister_data(void)
  106. {
  107. starpu_data_unregister(bcsr_handle);
  108. starpu_data_unregister(bcsr2_handle);
  109. }
  110. void
  111. test_bcsr_cpu_func(void *buffers[], void *args)
  112. {
  113. STARPU_SKIP_IF_VALGRIND;
  114. int *val;
  115. int factor;
  116. int i;
  117. uint32_t nnz = STARPU_BCSR_GET_NNZ(buffers[0]);
  118. uint32_t r = ((struct starpu_bcsr_interface *)buffers[0])->r;
  119. uint32_t c = ((struct starpu_bcsr_interface *)buffers[0])->c;
  120. if (r != R || c != C)
  121. {
  122. bcsr_config.copy_failed = FAILURE;
  123. return;
  124. }
  125. nnz *= (r*c);
  126. val = (int *) STARPU_BCSR_GET_NZVAL(buffers[0]);
  127. factor = *(int *) args;
  128. for (i = 0; i < (int)nnz; i++)
  129. {
  130. if (val[i] != i * factor)
  131. {
  132. bcsr_config.copy_failed = FAILURE;
  133. return;
  134. }
  135. val[i] *= -1;
  136. }
  137. #if 0
  138. /* TODO */
  139. /* Check colind */
  140. uint32_t *col = STARPU_BCSR_GET_COLIND(buffers[0]);
  141. for (i = 0; i < NNZ_BLOCKS; i++)
  142. if (col[i] != colind[i])
  143. bcsr_config.copy_failed = FAILURE;
  144. /* Check rowptr */
  145. uint32_t *row = STARPU_BCSR_GET_ROWPTR(buffers[0]);
  146. for (i = 0; i < 1 + WIDTH/R; i++)
  147. if (row[i] != rowptr[i])
  148. bcsr_config.copy_failed = FAILURE;
  149. #endif
  150. }
  151. int
  152. main(int argc, char **argv)
  153. {
  154. struct data_interface_test_summary summary;
  155. struct starpu_conf conf;
  156. starpu_conf_init(&conf);
  157. conf.ncuda = 2;
  158. conf.nopencl = 1;
  159. int ret = starpu_initialize(&conf, &argc, &argv);
  160. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  161. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  162. if(starpu_cpu_worker_get_count() == 0)
  163. {
  164. starpu_shutdown();
  165. return STARPU_TEST_SKIPPED;
  166. }
  167. register_data();
  168. run_tests(&bcsr_config, &summary);
  169. unregister_data();
  170. starpu_shutdown();
  171. data_interface_test_summary_print(stderr, &summary);
  172. return data_interface_test_summary_success(&summary);
  173. }