bcsr_interface.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011, 2012, 2013, 2015 Centre National de la Recherche Scientifique
  4. * Copyright (C) 2011, 2012 inria
  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 <config.h>
  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 ]
  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. #ifdef STARPU_USE_CPU
  42. void test_bcsr_cpu_func(void *buffers[], void *args);
  43. #endif /* !STARPU_USE_CPU */
  44. #ifdef STARPU_USE_CUDA
  45. extern void test_bcsr_cuda_func(void *buffers[], void *_args);
  46. #endif /* !STARPU_USE_CUDA */
  47. #ifdef STARPU_USE_OPENCL
  48. extern void test_bcsr_opencl_func(void *buffers[], void *args);
  49. #endif /* !STARPU_USE_OPENCL */
  50. static int nzval[NZVAL_SIZE] =
  51. {
  52. 0, 1, 2, 3, /* Fisrt block */
  53. 4, 5, 6, 7, /* Second block */
  54. 8, 9, 10, 11 /* Third block */
  55. };
  56. static int nzval2[NZVAL_SIZE];
  57. static uint32_t colind[NNZ_BLOCKS] = { 0, 0, 2 };
  58. static uint32_t colind2[NNZ_BLOCKS];
  59. static uint32_t rowptr[2] = { 0, 1 };
  60. static uint32_t rowptr2[2];
  61. static starpu_data_handle_t bcsr_handle;
  62. static starpu_data_handle_t bcsr2_handle;
  63. struct test_config bcsr_config =
  64. {
  65. #ifdef STARPU_USE_CPU
  66. .cpu_func = test_bcsr_cpu_func,
  67. #endif /* !STARPU_USE_CPU */
  68. #ifdef STARPU_USE_CUDA
  69. .cuda_func = test_bcsr_cuda_func,
  70. #endif /* !STARPU_USE_CUDA */
  71. #ifdef STARPU_USE_OPENCL
  72. .opencl_func = test_bcsr_opencl_func,
  73. #endif /* !STARPU_USE_OPENCL */
  74. #ifdef STARPU_USE_MIC
  75. .cpu_func_name = "test_bcsr_cpu_func",
  76. #endif
  77. .handle = &bcsr_handle,
  78. .dummy_handle = &bcsr2_handle,
  79. .copy_failed = SUCCESS,
  80. .name = "bcsr_interface"
  81. };
  82. static void
  83. register_data(void)
  84. {
  85. starpu_bcsr_data_register(&bcsr_handle,
  86. STARPU_MAIN_RAM,
  87. NNZ_BLOCKS,
  88. 1, /* nrow */
  89. (uintptr_t) nzval,
  90. colind,
  91. rowptr,
  92. 0, /* firstentry */
  93. R,
  94. C,
  95. sizeof(nzval[0]));
  96. starpu_bcsr_data_register(&bcsr2_handle,
  97. STARPU_MAIN_RAM,
  98. NNZ_BLOCKS,
  99. 1, /* nrow */
  100. (uintptr_t) nzval2,
  101. colind2,
  102. rowptr2,
  103. 0, /* firstentry */
  104. R,
  105. C,
  106. sizeof(nzval2[0]));
  107. }
  108. static void
  109. unregister_data(void)
  110. {
  111. starpu_data_unregister(bcsr_handle);
  112. starpu_data_unregister(bcsr2_handle);
  113. }
  114. void
  115. test_bcsr_cpu_func(void *buffers[], void *args)
  116. {
  117. STARPU_SKIP_IF_VALGRIND;
  118. int *val;
  119. int factor;
  120. int i;
  121. uint32_t nnz = STARPU_BCSR_GET_NNZ(buffers[0]);
  122. uint32_t r = ((struct starpu_bcsr_interface *)buffers[0])->r;
  123. uint32_t c = ((struct starpu_bcsr_interface *)buffers[0])->c;
  124. if (r != R || c != C)
  125. {
  126. bcsr_config.copy_failed = FAILURE;
  127. return;
  128. }
  129. nnz *= (r*c);
  130. val = (int *) STARPU_BCSR_GET_NZVAL(buffers[0]);
  131. factor = *(int *) args;
  132. for (i = 0; i < (int)nnz; i++)
  133. {
  134. if (val[i] != i * factor)
  135. {
  136. bcsr_config.copy_failed = FAILURE;
  137. return;
  138. }
  139. val[i] *= -1;
  140. }
  141. #if 0
  142. /* TODO */
  143. /* Check colind */
  144. uint32_t *col = STARPU_BCSR_GET_COLIND(buffers[0]);
  145. for (i = 0; i < NNZ_BLOCKS; i++)
  146. if (col[i] != colind[i])
  147. bcsr_config.copy_failed = FAILURE;
  148. /* Check rowptr */
  149. uint32_t *row = STARPU_BCSR_GET_ROWPTR(buffers[0]);
  150. for (i = 0; i < 1 + WIDTH/R; i++)
  151. if (row[i] != rowptr[i])
  152. bcsr_config.copy_failed = FAILURE;
  153. #endif
  154. }
  155. int
  156. main(int argc, char **argv)
  157. {
  158. data_interface_test_summary *summary;
  159. struct starpu_conf conf;
  160. starpu_conf_init(&conf);
  161. conf.ncuda = 2;
  162. conf.nopencl = 1;
  163. conf.nmic = -1;
  164. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  165. return STARPU_TEST_SKIPPED;
  166. register_data();
  167. summary = run_tests(&bcsr_config);
  168. if (!summary)
  169. exit(EXIT_FAILURE);
  170. unregister_data();
  171. starpu_shutdown();
  172. data_interface_test_summary_print(stderr, summary);
  173. return data_interface_test_summary_success(summary);
  174. }