csr_interface.c 3.5 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. #include <starpu.h>
  18. #include "../test_interfaces.h"
  19. #include "../../../helper.h"
  20. #define WIDTH 8
  21. #define HEIGHT 4
  22. #define SIZE (WIDTH * HEIGHT)
  23. #define NNZ (SIZE-1)
  24. #ifdef STARPU_USE_CPU
  25. void test_csr_cpu_func(void *buffers[], void *args);
  26. #endif /* !STARPU_USE_CPU */
  27. #ifdef STARPU_USE_CUDA
  28. extern void test_csr_cuda_func(void *buffers[], void *_args);
  29. #endif
  30. #ifdef STARPU_USE_OPENCL
  31. extern void test_csr_opencl_func(void *buffers[], void *args);
  32. #endif
  33. static int nzval[NNZ];
  34. static int nzval2[NNZ];
  35. static uint32_t colind[NNZ];
  36. static uint32_t colind2[NNZ];
  37. static uint32_t rowptr[HEIGHT+1];
  38. static uint32_t rowptr2[HEIGHT+1];
  39. static starpu_data_handle_t csr_handle;
  40. static starpu_data_handle_t csr2_handle;
  41. struct test_config csr_config =
  42. {
  43. #ifdef STARPU_USE_CPU
  44. .cpu_func = test_csr_cpu_func,
  45. #endif /* ! STARPU_USE_CPU */
  46. #ifdef STARPU_USE_CUDA
  47. .cuda_func = test_csr_cuda_func,
  48. #endif
  49. #ifdef STARPU_USE_OPENCL
  50. .opencl_func = test_csr_opencl_func,
  51. #endif
  52. #ifdef STARPU_USE_MIC
  53. .cpu_func_name = "test_csr_cpu_func",
  54. #endif
  55. .handle = &csr_handle,
  56. .dummy_handle = &csr2_handle,
  57. .copy_failed = SUCCESS,
  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-1];
  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. 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 < (int)nnz; i++)
  116. {
  117. if (val[i] != (i+1) * factor)
  118. {
  119. csr_config.copy_failed = FAILURE;
  120. return;
  121. }
  122. val[i] *= -1;
  123. }
  124. }
  125. int
  126. main(int argc, char **argv)
  127. {
  128. data_interface_test_summary *summary;
  129. struct starpu_conf conf;
  130. starpu_conf_init(&conf);
  131. conf.ncuda = 2;
  132. conf.nopencl = 1;
  133. conf.nmic = -1;
  134. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  135. goto enodev;
  136. register_data();
  137. summary = run_tests(&csr_config);
  138. if (!summary)
  139. exit(EXIT_FAILURE);
  140. unregister_data();
  141. starpu_shutdown();
  142. data_interface_test_summary_print(stderr, summary);
  143. return data_interface_test_summary_success(summary);
  144. enodev:
  145. return STARPU_TEST_SKIPPED;
  146. }