matrix_interface.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  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 "../../../common/helper.h"
  19. #define WIDTH 16
  20. #define HEIGHT 16
  21. #ifdef STARPU_USE_CPU
  22. static 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. #ifdef STARPU_USE_CPU
  34. .cpu_func = test_matrix_cpu_func,
  35. #endif /* ! STARPU_USE_CPU */
  36. #ifdef STARPU_USE_CUDA
  37. .cuda_func = test_matrix_cuda_func,
  38. #endif
  39. #ifdef STARPU_USE_OPENCL
  40. .opencl_func = test_matrix_opencl_func,
  41. #endif
  42. .handle = &matrix_handle,
  43. .dummy_handle = &matrix2_handle,
  44. .copy_failed = 0,
  45. .name = "matrix_interface"
  46. };
  47. static int matrix[WIDTH * HEIGHT];
  48. static int matrix2[WIDTH * HEIGHT];
  49. static void
  50. register_data(void)
  51. {
  52. int i;
  53. int size = WIDTH * HEIGHT;
  54. for (i = 0; i < size; i++)
  55. matrix[i] = i;
  56. starpu_matrix_data_register(&matrix_handle,
  57. 0,
  58. (uintptr_t) matrix,
  59. WIDTH, /* ld */
  60. WIDTH,
  61. HEIGHT,
  62. sizeof(matrix[0]));
  63. starpu_matrix_data_register(&matrix2_handle,
  64. 0,
  65. (uintptr_t) matrix2,
  66. WIDTH, /* ld */
  67. WIDTH,
  68. HEIGHT,
  69. sizeof(matrix[0]));
  70. }
  71. static void
  72. unregister_data(void)
  73. {
  74. starpu_data_unregister(matrix_handle);
  75. starpu_data_unregister(matrix2_handle);
  76. }
  77. static void
  78. test_matrix_cpu_func(void *buffers[], void *args)
  79. {
  80. int *val;
  81. int factor;
  82. int i;
  83. unsigned int nx, ny;
  84. nx = STARPU_MATRIX_GET_NX(buffers[0]);
  85. ny = STARPU_MATRIX_GET_NY(buffers[0]);
  86. val = (int *) STARPU_MATRIX_GET_PTR(buffers[0]);
  87. factor = *(int *) args;
  88. for (i = 0; i < nx*ny; i++)
  89. {
  90. if (val[i] != i * factor)
  91. {
  92. matrix_config.copy_failed = 1;
  93. return;
  94. }
  95. val[i] *= -1;
  96. }
  97. }
  98. int
  99. main(void)
  100. {
  101. data_interface_test_summary *summary;
  102. struct starpu_conf conf = {
  103. .ncpus = -1,
  104. .ncuda = 2,
  105. .nopencl = 1
  106. };
  107. if (starpu_init(&conf) == -ENODEV)
  108. goto enodev;
  109. register_data();
  110. summary = run_tests(&matrix_config);
  111. if (!summary)
  112. exit(EXIT_FAILURE);
  113. unregister_data();
  114. starpu_shutdown();
  115. data_interface_test_summary_print(stderr, summary);
  116. return data_interface_test_summary_success(summary);
  117. enodev:
  118. return STARPU_TEST_SKIPPED;
  119. }