coo_interface.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 INRIA
  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. #define NX 2
  19. #define NY 2
  20. #define MATRIX_SIZE (NX*NY)
  21. #if defined(STARPU_USE_CPU) || defined(STAPRU_USE_MIC)
  22. void test_coo_cpu_func(void *buffers[], void *args);
  23. #endif
  24. #ifdef STARPU_USE_CUDA
  25. extern void test_coo_cuda_func(void *buffers[], void *args);
  26. #endif
  27. #ifdef STARPU_USE_OPENCL
  28. extern void test_coo_opencl_func(void *buffers[], void *args);
  29. #endif
  30. static starpu_data_handle_t coo_handle, coo2_handle;
  31. struct test_config coo_config =
  32. {
  33. #ifdef STARPU_USE_CPU
  34. .cpu_func = test_coo_cpu_func,
  35. #endif /* ! STARPU_USE_CPU */
  36. #ifdef STARPU_USE_CUDA
  37. .cuda_func = test_coo_cuda_func,
  38. #endif /* !STARPU_USE_CUDA */
  39. #ifdef STARPU_USE_OPENCL
  40. .opencl_func = test_coo_opencl_func,
  41. #endif /* !STARPU_USE_OPENCL */
  42. #ifdef STARPU_USE_MIC
  43. .cpu_func_name = "test_coo_cpu_func",
  44. #endif
  45. .handle = &coo_handle,
  46. .dummy_handle = &coo2_handle,
  47. .copy_failed = SUCCESS,
  48. .name = "coo_interface"
  49. };
  50. void
  51. test_coo_cpu_func(void *buffers[], void *args)
  52. {
  53. int factor = *(int *) args;
  54. int *values = (int *) STARPU_COO_GET_VALUES(buffers[0]);
  55. unsigned size = STARPU_COO_GET_NVALUES(buffers[0]);
  56. int i;
  57. for (i = 0; i < (int)size; i++)
  58. {
  59. if (values[i] != i * factor)
  60. {
  61. coo_config.copy_failed = FAILURE;
  62. return;
  63. }
  64. values[i] *= -1;
  65. }
  66. }
  67. static uint32_t columns[MATRIX_SIZE];
  68. static uint32_t rows[MATRIX_SIZE];
  69. static int values[MATRIX_SIZE];
  70. static uint32_t columns2[MATRIX_SIZE];
  71. static uint32_t rows2[MATRIX_SIZE];
  72. static int values2[MATRIX_SIZE];
  73. static void
  74. register_data(void)
  75. {
  76. /*
  77. We use the following matrix :
  78. +---+---+
  79. | 0 | 1 |
  80. +---+---+
  81. | 2 | 3 |
  82. +---+---+
  83. Of course, we're not supposed to register the zeros, but it does not
  84. matter for this test.
  85. */
  86. columns[0] = 0;
  87. rows[0] = 0;
  88. values[0] = 0;
  89. columns[1] = 1;
  90. rows[1] = 0;
  91. values[1] = 1;
  92. columns[2] = 0;
  93. rows[2] = 1;
  94. values[2] = 2;
  95. columns[3] = 1;
  96. rows[3] = 1;
  97. values[3] = 3;
  98. int i;
  99. for (i = 0; i < MATRIX_SIZE; i++)
  100. {
  101. columns2[i] = -1;
  102. rows2[i] = -1;
  103. values2[i] = -1;
  104. }
  105. starpu_coo_data_register(&coo_handle,
  106. STARPU_MAIN_RAM,
  107. NX,
  108. NY,
  109. MATRIX_SIZE,
  110. columns,
  111. rows,
  112. (uintptr_t) values,
  113. sizeof(values[0]));
  114. starpu_coo_data_register(&coo2_handle,
  115. STARPU_MAIN_RAM,
  116. NX,
  117. NY,
  118. MATRIX_SIZE,
  119. columns2,
  120. rows2,
  121. (uintptr_t) values2,
  122. sizeof(values2[0]));
  123. }
  124. static void
  125. unregister_data(void)
  126. {
  127. starpu_data_unregister(coo_handle);
  128. starpu_data_unregister(coo2_handle);
  129. }
  130. int
  131. main(int argc, char **argv)
  132. {
  133. struct starpu_conf conf;
  134. data_interface_test_summary *summary;
  135. starpu_conf_init(&conf);
  136. conf.ncuda = 2;
  137. conf.nopencl = 1;
  138. conf.nmic = -1;
  139. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  140. goto enodev;
  141. register_data();
  142. summary = run_tests(&coo_config);
  143. if (!summary)
  144. exit(EXIT_FAILURE);
  145. unregister_data();
  146. data_interface_test_summary_print(stderr, summary);
  147. starpu_shutdown();
  148. return data_interface_test_summary_success(summary);
  149. enodev:
  150. return STARPU_TEST_SKIPPED;
  151. }