csr_interface.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-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. #define WIDTH 8
  20. #define HEIGHT 4
  21. #define SIZE (WIDTH * HEIGHT)
  22. #define NNZ (SIZE-1)
  23. #ifdef STARPU_USE_CPU
  24. void test_csr_cpu_func(void *buffers[], void *args);
  25. #endif /* !STARPU_USE_CPU */
  26. #ifdef STARPU_USE_CUDA
  27. extern void test_csr_cuda_func(void *buffers[], void *_args);
  28. #endif
  29. #ifdef STARPU_USE_OPENCL
  30. extern void test_csr_opencl_func(void *buffers[], void *args);
  31. #endif
  32. static int nzval[NNZ];
  33. static int nzval2[NNZ];
  34. static uint32_t colind[NNZ];
  35. static uint32_t colind2[NNZ];
  36. static uint32_t rowptr[HEIGHT+1];
  37. static uint32_t rowptr2[HEIGHT+1];
  38. static starpu_data_handle_t csr_handle;
  39. static starpu_data_handle_t csr2_handle;
  40. struct test_config csr_config =
  41. {
  42. #ifdef STARPU_USE_CPU
  43. .cpu_func = test_csr_cpu_func,
  44. #endif /* ! STARPU_USE_CPU */
  45. #ifdef STARPU_USE_CUDA
  46. .cuda_func = test_csr_cuda_func,
  47. #endif
  48. #ifdef STARPU_USE_OPENCL
  49. .opencl_func = test_csr_opencl_func,
  50. #endif
  51. #ifdef STARPU_USE_MIC
  52. .cpu_func_name = "test_csr_cpu_func",
  53. #endif
  54. .handle = &csr_handle,
  55. .dummy_handle = &csr2_handle,
  56. .copy_failed = SUCCESS,
  57. .name = "csr_interface"
  58. };
  59. static void
  60. register_data(void)
  61. {
  62. int i;
  63. for (i = 1; i < SIZE; i++)
  64. {
  65. nzval[i-1] = i;
  66. nzval2[i-1] = 42;
  67. colind[i-1] = i % WIDTH;
  68. colind2[i-1] = colind[i-1];
  69. }
  70. rowptr[0] = 1;
  71. rowptr2[0] = 1;
  72. for (i = 1; i < HEIGHT; i++)
  73. {
  74. rowptr[i] = i * WIDTH;
  75. rowptr2[i] = rowptr[i];
  76. }
  77. rowptr[HEIGHT] = NNZ + 1;
  78. rowptr2[HEIGHT] = rowptr[HEIGHT];
  79. starpu_csr_data_register(&csr_handle,
  80. STARPU_MAIN_RAM,
  81. NNZ,
  82. HEIGHT,
  83. (uintptr_t) nzval,
  84. colind,
  85. rowptr,
  86. 0,
  87. sizeof(nzval[0]));
  88. starpu_csr_data_register(&csr2_handle,
  89. STARPU_MAIN_RAM,
  90. NNZ,
  91. HEIGHT,
  92. (uintptr_t) nzval2,
  93. colind2,
  94. rowptr2,
  95. 0,
  96. sizeof(nzval2[0]));
  97. }
  98. static void
  99. unregister_data(void)
  100. {
  101. starpu_data_unregister(csr_handle);
  102. starpu_data_unregister(csr2_handle);
  103. }
  104. void
  105. test_csr_cpu_func(void *buffers[], void *args)
  106. {
  107. STARPU_SKIP_IF_VALGRIND;
  108. int *val;
  109. int factor;
  110. int i;
  111. uint32_t nnz = STARPU_CSR_GET_NNZ(buffers[0]);
  112. val = (int *) STARPU_CSR_GET_NZVAL(buffers[0]);
  113. factor = *(int *) args;
  114. for (i = 0; i < (int)nnz; i++)
  115. {
  116. if (val[i] != (i+1) * factor)
  117. {
  118. csr_config.copy_failed = FAILURE;
  119. return;
  120. }
  121. val[i] *= -1;
  122. }
  123. }
  124. int main(int argc, char **argv)
  125. {
  126. struct data_interface_test_summary summary;
  127. struct starpu_conf conf;
  128. starpu_conf_init(&conf);
  129. conf.ncuda = 2;
  130. conf.nopencl = 1;
  131. conf.nmic = -1;
  132. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  133. goto enodev;
  134. register_data();
  135. run_tests(&csr_config, &summary);
  136. unregister_data();
  137. starpu_shutdown();
  138. data_interface_test_summary_print(stderr, &summary);
  139. return data_interface_test_summary_success(&summary);
  140. enodev:
  141. return STARPU_TEST_SKIPPED;
  142. }