csr_interface.c 3.7 KB

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