csr_interface.c 3.4 KB

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