matrix_interface.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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 <config.h>
  17. #include <starpu.h>
  18. #include "../test_interfaces.h"
  19. #include "../../../helper.h"
  20. #define WIDTH 16
  21. #define HEIGHT 16
  22. #ifdef STARPU_USE_CPU
  23. void test_matrix_cpu_func(void *buffers[], void *args);
  24. #endif /* !STARPU_USE_CPU */
  25. #ifdef STARPU_USE_CUDA
  26. extern void test_matrix_cuda_func(void *buffers[], void *_args);
  27. #endif
  28. #ifdef STARPU_USE_OPENCL
  29. extern void test_matrix_opencl_func(void *buffers[], void *args);
  30. #endif
  31. static starpu_data_handle_t matrix_handle;
  32. static starpu_data_handle_t matrix2_handle;
  33. struct test_config matrix_config =
  34. {
  35. #ifdef STARPU_USE_CPU
  36. .cpu_func = test_matrix_cpu_func,
  37. #endif /* ! STARPU_USE_CPU */
  38. #ifdef STARPU_USE_CUDA
  39. .cuda_func = test_matrix_cuda_func,
  40. #endif
  41. #ifdef STARPU_USE_OPENCL
  42. .opencl_func = test_matrix_opencl_func,
  43. #endif
  44. #ifdef STARPU_USE_MIC
  45. .cpu_func_name = "test_matrix_cpu_func",
  46. #endif
  47. .handle = &matrix_handle,
  48. .dummy_handle = &matrix2_handle,
  49. .copy_failed = SUCCESS,
  50. .name = "matrix_interface"
  51. };
  52. static int matrix[WIDTH * HEIGHT];
  53. static int matrix2[WIDTH * HEIGHT];
  54. static void
  55. register_data(void)
  56. {
  57. int i;
  58. int size = WIDTH * HEIGHT;
  59. for (i = 0; i < size; i++)
  60. matrix[i] = i;
  61. starpu_matrix_data_register(&matrix_handle,
  62. STARPU_MAIN_RAM,
  63. (uintptr_t) matrix,
  64. WIDTH, /* ld */
  65. WIDTH,
  66. HEIGHT,
  67. sizeof(matrix[0]));
  68. starpu_matrix_data_register(&matrix2_handle,
  69. STARPU_MAIN_RAM,
  70. (uintptr_t) matrix2,
  71. WIDTH, /* ld */
  72. WIDTH,
  73. HEIGHT,
  74. sizeof(matrix[0]));
  75. }
  76. static void
  77. unregister_data(void)
  78. {
  79. starpu_data_unregister(matrix_handle);
  80. starpu_data_unregister(matrix2_handle);
  81. }
  82. void
  83. test_matrix_cpu_func(void *buffers[], void *args)
  84. {
  85. STARPU_SKIP_IF_VALGRIND;
  86. int *val;
  87. int factor;
  88. int i;
  89. int nx, ny;
  90. nx = STARPU_MATRIX_GET_NX(buffers[0]);
  91. ny = STARPU_MATRIX_GET_NY(buffers[0]);
  92. val = (int *) STARPU_MATRIX_GET_PTR(buffers[0]);
  93. factor = *(int *) args;
  94. for (i = 0; i < nx*ny; i++)
  95. {
  96. if (val[i] != i * factor)
  97. {
  98. matrix_config.copy_failed = FAILURE;
  99. return;
  100. }
  101. val[i] *= -1;
  102. }
  103. }
  104. int
  105. main(int argc, char **argv)
  106. {
  107. 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. summary = run_tests(&matrix_config);
  117. if (!summary)
  118. exit(EXIT_FAILURE);
  119. unregister_data();
  120. starpu_shutdown();
  121. data_interface_test_summary_print(stderr, summary);
  122. return data_interface_test_summary_success(summary);
  123. enodev:
  124. return STARPU_TEST_SKIPPED;
  125. }