bcsr_interface.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2010-2013,2015,2017,2019 CNRS
  5. * Copyright (C) 2012,2013,2017 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../test_interfaces.h"
  20. #include "../../../helper.h"
  21. /*
  22. * In this test, we use the following matrix:
  23. *
  24. * +----------------+
  25. * | 0 1 0 0 |
  26. * | 2 3 0 0 |
  27. * | 4 5 8 9 |
  28. * | 6 7 10 11 |
  29. * +----------------+
  30. *
  31. * nzval = [0, 1, 2, 3] ++ [4, 5, 6, 7] ++ [8, 9, 10, 11]
  32. * colind = [0, 0, 1]
  33. * rowptr = [0, 1, 3 ]
  34. * r = c = 2
  35. */
  36. /* Size of the blocks */
  37. #define R 2
  38. #define C 2
  39. #define NNZ_BLOCKS 3 /* out of 4 */
  40. #define NZVAL_SIZE (R*C*NNZ_BLOCKS)
  41. #define NROWS 2
  42. #ifdef STARPU_USE_CPU
  43. void test_bcsr_cpu_func(void *buffers[], void *args);
  44. #endif /* !STARPU_USE_CPU */
  45. #ifdef STARPU_USE_CUDA
  46. extern void test_bcsr_cuda_func(void *buffers[], void *_args);
  47. #endif /* !STARPU_USE_CUDA */
  48. #ifdef STARPU_USE_OPENCL
  49. extern void test_bcsr_opencl_func(void *buffers[], void *args);
  50. #endif /* !STARPU_USE_OPENCL */
  51. static int nzval[NZVAL_SIZE] =
  52. {
  53. 0, 1, 2, 3, /* First block */
  54. 4, 5, 6, 7, /* Second block */
  55. 8, 9, 10, 11 /* Third block */
  56. };
  57. static int nzval2[NZVAL_SIZE];
  58. static uint32_t colind[NNZ_BLOCKS] = { 0, 0, 1 };
  59. static uint32_t colind2[NNZ_BLOCKS];
  60. static uint32_t rowptr[NROWS+1] = { 0, 1, NNZ_BLOCKS };
  61. static uint32_t rowptr2[NROWS+1] = { 0, 0, NNZ_BLOCKS };
  62. static starpu_data_handle_t bcsr_handle;
  63. static starpu_data_handle_t bcsr2_handle;
  64. struct test_config bcsr_config =
  65. {
  66. #ifdef STARPU_USE_CPU
  67. .cpu_func = test_bcsr_cpu_func,
  68. #endif /* !STARPU_USE_CPU */
  69. #ifdef STARPU_USE_CUDA
  70. .cuda_func = test_bcsr_cuda_func,
  71. #endif /* !STARPU_USE_CUDA */
  72. #ifdef STARPU_USE_OPENCL
  73. .opencl_func = test_bcsr_opencl_func,
  74. #endif /* !STARPU_USE_OPENCL */
  75. #ifdef STARPU_USE_MIC
  76. .cpu_func_name = "test_bcsr_cpu_func",
  77. #endif
  78. .handle = &bcsr_handle,
  79. .dummy_handle = &bcsr2_handle,
  80. .copy_failed = SUCCESS,
  81. .name = "bcsr_interface"
  82. };
  83. static void
  84. register_data(void)
  85. {
  86. starpu_bcsr_data_register(&bcsr_handle,
  87. STARPU_MAIN_RAM,
  88. NNZ_BLOCKS,
  89. NROWS,
  90. (uintptr_t) nzval,
  91. colind,
  92. rowptr,
  93. 0, /* firstentry */
  94. R,
  95. C,
  96. sizeof(nzval[0]));
  97. starpu_bcsr_data_register(&bcsr2_handle,
  98. STARPU_MAIN_RAM,
  99. NNZ_BLOCKS,
  100. NROWS,
  101. (uintptr_t) nzval2,
  102. colind2,
  103. rowptr2,
  104. 0, /* firstentry */
  105. R,
  106. C,
  107. sizeof(nzval2[0]));
  108. }
  109. static void
  110. unregister_data(void)
  111. {
  112. starpu_data_unregister(bcsr_handle);
  113. starpu_data_unregister(bcsr2_handle);
  114. }
  115. void
  116. test_bcsr_cpu_func(void *buffers[], void *args)
  117. {
  118. STARPU_SKIP_IF_VALGRIND;
  119. int *val;
  120. int factor;
  121. int i;
  122. uint32_t nnz = STARPU_BCSR_GET_NNZ(buffers[0]);
  123. uint32_t r = ((struct starpu_bcsr_interface *)buffers[0])->r;
  124. uint32_t c = ((struct starpu_bcsr_interface *)buffers[0])->c;
  125. if (r != R || c != C)
  126. {
  127. bcsr_config.copy_failed = FAILURE;
  128. return;
  129. }
  130. nnz *= (r*c);
  131. val = (int *) STARPU_BCSR_GET_NZVAL(buffers[0]);
  132. factor = *(int *) args;
  133. for (i = 0; i < (int)nnz; i++)
  134. {
  135. if (val[i] != i * factor)
  136. {
  137. bcsr_config.copy_failed = FAILURE;
  138. return;
  139. }
  140. val[i] *= -1;
  141. }
  142. #if 0
  143. /* TODO */
  144. /* Check colind */
  145. uint32_t *col = STARPU_BCSR_GET_COLIND(buffers[0]);
  146. for (i = 0; i < NNZ_BLOCKS; i++)
  147. if (col[i] != colind[i])
  148. bcsr_config.copy_failed = FAILURE;
  149. /* Check rowptr */
  150. uint32_t *row = STARPU_BCSR_GET_ROWPTR(buffers[0]);
  151. for (i = 0; i < 1 + WIDTH/R; i++)
  152. if (row[i] != rowptr[i])
  153. bcsr_config.copy_failed = FAILURE;
  154. #endif
  155. }
  156. int
  157. main(int argc, char **argv)
  158. {
  159. struct data_interface_test_summary summary;
  160. struct starpu_conf conf;
  161. starpu_conf_init(&conf);
  162. conf.ncuda = 2;
  163. conf.nopencl = 1;
  164. conf.nmic = -1;
  165. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  166. return STARPU_TEST_SKIPPED;
  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. }