matrix_interface.c 3.1 KB

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