csr_interface.c 3.4 KB

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