opencl.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* GCC-StarPU
  2. Copyright (C) 2012 Institut National de Recherche en Informatique et Automatique
  3. GCC-StarPU is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. GCC-StarPU is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with GCC-StarPU. If not, see <http://www.gnu.org/licenses/>. */
  13. #undef NDEBUG
  14. #include <mocks.h>
  15. #include <stdlib.h>
  16. /* Claim that OpenCL is supported. */
  17. #pragma starpu add_target "opencl"
  18. static void my_task (int x, float a[x])
  19. __attribute__ ((task));
  20. static void my_task_opencl (int x, float a[x])
  21. __attribute__ ((task_implementation ("opencl", my_task)));
  22. #pragma starpu opencl my_task_opencl "test.cl" "kern" 8
  23. int
  24. main ()
  25. {
  26. static float a[123];
  27. #pragma starpu initialize
  28. memset (a, 0, sizeof a);
  29. expected_register_arguments.pointer = a;
  30. expected_register_arguments.elements = sizeof a / sizeof a[0];
  31. expected_register_arguments.element_size = sizeof a[0];
  32. #pragma starpu register a
  33. static int x = 123;
  34. struct task_insert_argument expected[] =
  35. {
  36. { STARPU_VALUE, &x, sizeof x },
  37. { STARPU_RW, a },
  38. { 0, 0, 0 }
  39. };
  40. expected_task_insert_arguments = expected;
  41. expected_task_insert_targets = STARPU_OPENCL;
  42. size_t y = 8; expected_cl_enqueue_kernel_arguments.global_work_size = &y;
  43. my_task (123, a);
  44. my_task (123, a);
  45. my_task (123, a);
  46. assert (tasks_submitted == 3);
  47. assert (load_opencl_calls == 1);
  48. assert (load_opencl_kernel_calls == 3);
  49. assert (opencl_set_kernel_arg_calls == 3 * 2);
  50. assert (opencl_enqueue_calls == 3);
  51. assert (opencl_finish_calls == 3);
  52. assert (opencl_release_event_calls == 3);
  53. assert (opencl_collect_stats_calls == 3);
  54. return EXIT_SUCCESS;
  55. }