matrix_interface.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2011-2013,2015,2017,2019 CNRS
  5. * Copyright (C) 2012,2013 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../test_interfaces.h"
  20. #include "../../../helper.h"
  21. #define WIDTH 16
  22. #define HEIGHT 16
  23. #ifdef STARPU_USE_CPU
  24. void test_matrix_cpu_func(void *buffers[], void *args);
  25. #endif /* !STARPU_USE_CPU */
  26. #ifdef STARPU_USE_CUDA
  27. extern void test_matrix_cuda_func(void *buffers[], void *_args);
  28. #endif
  29. #ifdef STARPU_USE_OPENCL
  30. extern void test_matrix_opencl_func(void *buffers[], void *args);
  31. #endif
  32. static starpu_data_handle_t matrix_handle;
  33. static starpu_data_handle_t matrix2_handle;
  34. struct test_config matrix_config =
  35. {
  36. #ifdef STARPU_USE_CPU
  37. .cpu_func = test_matrix_cpu_func,
  38. #endif /* ! STARPU_USE_CPU */
  39. #ifdef STARPU_USE_CUDA
  40. .cuda_func = test_matrix_cuda_func,
  41. #endif
  42. #ifdef STARPU_USE_OPENCL
  43. .opencl_func = test_matrix_opencl_func,
  44. #endif
  45. #ifdef STARPU_USE_MIC
  46. .cpu_func_name = "test_matrix_cpu_func",
  47. #endif
  48. .handle = &matrix_handle,
  49. .dummy_handle = &matrix2_handle,
  50. .copy_failed = SUCCESS,
  51. .name = "matrix_interface"
  52. };
  53. static int matrix[WIDTH * HEIGHT];
  54. static int matrix2[WIDTH * HEIGHT];
  55. static void
  56. register_data(void)
  57. {
  58. int i;
  59. int size = WIDTH * HEIGHT;
  60. for (i = 0; i < size; i++)
  61. matrix[i] = i;
  62. starpu_matrix_data_register(&matrix_handle,
  63. STARPU_MAIN_RAM,
  64. (uintptr_t) matrix,
  65. WIDTH, /* ld */
  66. WIDTH,
  67. HEIGHT,
  68. sizeof(matrix[0]));
  69. starpu_matrix_data_register(&matrix2_handle,
  70. STARPU_MAIN_RAM,
  71. (uintptr_t) matrix2,
  72. WIDTH, /* ld */
  73. WIDTH,
  74. HEIGHT,
  75. sizeof(matrix[0]));
  76. }
  77. static void
  78. unregister_data(void)
  79. {
  80. starpu_data_unregister(matrix_handle);
  81. starpu_data_unregister(matrix2_handle);
  82. }
  83. void
  84. test_matrix_cpu_func(void *buffers[], void *args)
  85. {
  86. STARPU_SKIP_IF_VALGRIND;
  87. int *val;
  88. int factor;
  89. int i;
  90. int nx, ny;
  91. nx = STARPU_MATRIX_GET_NX(buffers[0]);
  92. ny = STARPU_MATRIX_GET_NY(buffers[0]);
  93. val = (int *) STARPU_MATRIX_GET_PTR(buffers[0]);
  94. factor = *(int *) args;
  95. for (i = 0; i < nx*ny; i++)
  96. {
  97. if (val[i] != i * factor)
  98. {
  99. matrix_config.copy_failed = FAILURE;
  100. return;
  101. }
  102. val[i] *= -1;
  103. }
  104. }
  105. int main(int argc, char **argv)
  106. {
  107. struct data_interface_test_summary summary;
  108. struct starpu_conf conf;
  109. starpu_conf_init(&conf);
  110. conf.ncuda = 2;
  111. conf.nopencl = 1;
  112. conf.nmic = -1;
  113. if (starpu_initialize(&conf, &argc, &argv) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  114. goto enodev;
  115. register_data();
  116. run_tests(&matrix_config, &summary);
  117. unregister_data();
  118. starpu_shutdown();
  119. data_interface_test_summary_print(stderr, &summary);
  120. return data_interface_test_summary_success(&summary);
  121. enodev:
  122. return STARPU_TEST_SKIPPED;
  123. }