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