csr_interface.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 <starpu.h>
  17. #include "../test_interfaces.h"
  18. #include "../../../common/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. static 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. .handle = &csr_handle,
  52. .dummy_handle = &csr2_handle,
  53. .copy_failed = 0,
  54. .name = "csr_interface"
  55. };
  56. static void
  57. register_data(void)
  58. {
  59. int i;
  60. for (i = 1; i < SIZE; i++)
  61. {
  62. nzval[i-1] = i;
  63. nzval2[i-1] = 42;
  64. colind[i-1] = i % WIDTH;
  65. colind2[i-1] = colind[i];
  66. }
  67. rowptr[0] = 1;
  68. rowptr2[0] = 1;
  69. for (i = 1; i < HEIGHT; i++)
  70. {
  71. rowptr[i] = i * WIDTH;
  72. rowptr2[i] = rowptr[i];
  73. }
  74. rowptr[HEIGHT] = NNZ + 1;
  75. rowptr2[HEIGHT] = rowptr[HEIGHT];
  76. starpu_csr_data_register(&csr_handle,
  77. 0,
  78. NNZ,
  79. HEIGHT,
  80. (uintptr_t) nzval,
  81. colind,
  82. rowptr,
  83. 0,
  84. sizeof(nzval[0]));
  85. starpu_csr_data_register(&csr2_handle,
  86. 0,
  87. NNZ,
  88. HEIGHT,
  89. (uintptr_t) nzval2,
  90. colind2,
  91. rowptr2,
  92. 0,
  93. sizeof(nzval2[0]));
  94. }
  95. static void
  96. unregister_data(void)
  97. {
  98. starpu_data_unregister(csr_handle);
  99. starpu_data_unregister(csr2_handle);
  100. }
  101. static void
  102. test_csr_cpu_func(void *buffers[], void *args)
  103. {
  104. int *val;
  105. int factor;
  106. int i;
  107. uint32_t nnz = STARPU_CSR_GET_NNZ(buffers[0]);
  108. val = (int *) STARPU_CSR_GET_NZVAL(buffers[0]);
  109. factor = *(int *) args;
  110. for (i = 0; i < nnz; i++)
  111. {
  112. if (val[i] != (i+1) * factor)
  113. {
  114. csr_config.copy_failed = 1;
  115. return;
  116. }
  117. val[i] *= -1;
  118. }
  119. }
  120. int
  121. main(void)
  122. {
  123. data_interface_test_summary *summary;
  124. struct starpu_conf conf =
  125. {
  126. .ncpus = -1,
  127. .ncuda = 2,
  128. .nopencl = 1
  129. };
  130. if (starpu_init(&conf) == -ENODEV)
  131. goto enodev;
  132. register_data();
  133. summary = run_tests(&csr_config);
  134. if (!summary)
  135. exit(EXIT_FAILURE);
  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. }