matrix_interface.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <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. static 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. .handle = &matrix_handle,
  45. .dummy_handle = &matrix2_handle,
  46. .copy_failed = 0,
  47. .name = "matrix_interface"
  48. };
  49. static int matrix[WIDTH * HEIGHT];
  50. static int matrix2[WIDTH * HEIGHT];
  51. static void
  52. register_data(void)
  53. {
  54. int i;
  55. int size = WIDTH * HEIGHT;
  56. for (i = 0; i < size; i++)
  57. matrix[i] = i;
  58. starpu_matrix_data_register(&matrix_handle,
  59. 0,
  60. (uintptr_t) matrix,
  61. WIDTH, /* ld */
  62. WIDTH,
  63. HEIGHT,
  64. sizeof(matrix[0]));
  65. starpu_matrix_data_register(&matrix2_handle,
  66. 0,
  67. (uintptr_t) matrix2,
  68. WIDTH, /* ld */
  69. WIDTH,
  70. HEIGHT,
  71. sizeof(matrix[0]));
  72. }
  73. static void
  74. unregister_data(void)
  75. {
  76. starpu_data_unregister(matrix_handle);
  77. starpu_data_unregister(matrix2_handle);
  78. }
  79. static void
  80. test_matrix_cpu_func(void *buffers[], void *args)
  81. {
  82. STARPU_SKIP_IF_VALGRIND;
  83. int *val;
  84. int factor;
  85. int i;
  86. unsigned int nx, ny;
  87. nx = STARPU_MATRIX_GET_NX(buffers[0]);
  88. ny = STARPU_MATRIX_GET_NY(buffers[0]);
  89. val = (int *) STARPU_MATRIX_GET_PTR(buffers[0]);
  90. factor = *(int *) args;
  91. for (i = 0; i < nx*ny; i++)
  92. {
  93. if (val[i] != i * factor)
  94. {
  95. matrix_config.copy_failed = 1;
  96. return;
  97. }
  98. val[i] *= -1;
  99. }
  100. }
  101. int
  102. main(void)
  103. {
  104. data_interface_test_summary *summary;
  105. struct starpu_conf conf =
  106. {
  107. .ncpus = -1,
  108. .ncuda = 2,
  109. .nopencl = 1
  110. };
  111. if (starpu_init(&conf) == -ENODEV || starpu_cpu_worker_get_count() == 0)
  112. goto enodev;
  113. register_data();
  114. summary = run_tests(&matrix_config);
  115. if (!summary)
  116. exit(EXIT_FAILURE);
  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. }