coo_interface.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifdef STARPU_USE_CPU
  22. static 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. .handle = &coo_handle,
  43. .dummy_handle = &coo2_handle,
  44. .copy_failed = SUCCESS,
  45. .name = "coo_interface"
  46. };
  47. static void
  48. test_coo_cpu_func(void *buffers[], void *args)
  49. {
  50. int factor = *(int *) args;
  51. int *values = (int *) STARPU_COO_GET_VALUES(buffers[0]);
  52. unsigned size = STARPU_COO_GET_NVALUES(buffers[0]);
  53. unsigned i;
  54. for (i = 0; i < size; i++)
  55. {
  56. if (values[i] != i * factor)
  57. {
  58. coo_config.copy_failed = FAILURE;
  59. return;
  60. }
  61. values[i] *= -1;
  62. }
  63. }
  64. static uint32_t columns[MATRIX_SIZE];
  65. static uint32_t rows[MATRIX_SIZE];
  66. static int values[MATRIX_SIZE];
  67. static uint32_t columns2[MATRIX_SIZE];
  68. static uint32_t rows2[MATRIX_SIZE];
  69. static int values2[MATRIX_SIZE];
  70. static void
  71. register_data(void)
  72. {
  73. /*
  74. We use the following matrix :
  75. +---+---+
  76. | 0 | 1 |
  77. +---+---+
  78. | 2 | 3 |
  79. +---+---+
  80. Of course, we're not supposed to register the zeros, but it does not
  81. matter for this test.
  82. */
  83. columns[0] = 0;
  84. rows[0] = 0;
  85. values[0] = 0;
  86. columns[1] = 1;
  87. rows[1] = 0;
  88. values[1] = 1;
  89. columns[2] = 0;
  90. rows[2] = 1;
  91. values[2] = 2;
  92. columns[3] = 1;
  93. rows[3] = 1;
  94. values[3] = 3;
  95. int i;
  96. for (i = 0; i < MATRIX_SIZE; i++)
  97. {
  98. columns2[i] = -1;
  99. rows2[i] = -1;
  100. values2[i] = -1;
  101. }
  102. starpu_coo_data_register(&coo_handle,
  103. 0,
  104. NX,
  105. NY,
  106. MATRIX_SIZE,
  107. columns,
  108. rows,
  109. (uintptr_t) values,
  110. sizeof(values[0]));
  111. starpu_coo_data_register(&coo2_handle,
  112. 0,
  113. NX,
  114. NY,
  115. MATRIX_SIZE,
  116. columns2,
  117. rows2,
  118. (uintptr_t) values2,
  119. sizeof(values2[0]));
  120. }
  121. static void
  122. unregister_data(void)
  123. {
  124. starpu_data_unregister(coo_handle);
  125. starpu_data_unregister(coo2_handle);
  126. }
  127. int
  128. main(void)
  129. {
  130. struct starpu_conf conf;
  131. data_interface_test_summary *summary;
  132. starpu_conf_init(&conf);
  133. conf.ncuda = 2;
  134. conf.nopencl = 1;
  135. if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  136. goto enodev;
  137. register_data();
  138. summary = run_tests(&coo_config);
  139. if (!summary)
  140. exit(EXIT_FAILURE);
  141. unregister_data();
  142. data_interface_test_summary_print(stderr, summary);
  143. starpu_shutdown();
  144. return data_interface_test_summary_success(summary);
  145. enodev:
  146. return STARPU_TEST_SKIPPED;
  147. }