multiformat_worker.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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 "generic.h"
  18. #include "../../../../helper.h"
  19. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  20. extern struct stats global_stats;
  21. static int vector[NX]; static starpu_data_handle_t handle;
  22. #endif
  23. #ifdef STARPU_USE_CUDA
  24. static int ncuda;
  25. static int cuda_worker;
  26. #endif
  27. #ifdef STARPU_USE_OPENCL
  28. static int nopencl;
  29. static int opencl_worker;
  30. #endif
  31. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  32. static struct starpu_codelet cl =
  33. {
  34. .modes = { STARPU_RW },
  35. #ifdef STARPU_USE_CUDA
  36. .cuda_funcs = { cuda_func },
  37. #endif
  38. #ifdef STARPU_USE_OPENCL
  39. .opencl_funcs = { opencl_func },
  40. #endif
  41. .nbuffers = 1,
  42. };
  43. static void
  44. register_handle(void)
  45. {
  46. int i;
  47. for (i = 0; i < NX; i++)
  48. vector[i] = i;
  49. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  50. }
  51. static void
  52. unregister_handle(void)
  53. {
  54. starpu_data_unregister(handle);
  55. }
  56. static int
  57. create_and_submit_tasks(void)
  58. {
  59. struct starpu_task *task;
  60. task = starpu_task_create();
  61. task->cl = &cl;
  62. task->handles[0] = handle;
  63. task->execute_on_a_specific_worker = 1;
  64. #ifdef STARPU_USE_CUDA
  65. if (ncuda > 0)
  66. {
  67. task->workerid = cuda_worker;
  68. }
  69. else
  70. #endif
  71. #ifdef STARPU_USE_OPENCL
  72. if (nopencl > 0)
  73. {
  74. task->workerid = opencl_worker;
  75. }
  76. else
  77. #endif
  78. {
  79. task->destroy = 0;
  80. starpu_task_destroy(task);
  81. return -ENODEV;
  82. }
  83. return starpu_task_submit(task);
  84. }
  85. #endif
  86. int
  87. main(int argc, char **argv)
  88. {
  89. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  90. int err;
  91. err = starpu_initialize(NULL, &argc, &argv);
  92. if (err == -ENODEV)
  93. goto enodev;
  94. #ifdef STARPU_USE_CUDA
  95. ncuda = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  96. &cuda_worker, 1);
  97. if (ncuda < 0)
  98. ncuda = 1;
  99. #endif
  100. #ifdef STARPU_USE_OPENCL
  101. nopencl = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  102. &opencl_worker, 1);
  103. if (nopencl < 0)
  104. nopencl = 1;
  105. #endif
  106. reset_stats(&global_stats);
  107. register_handle();
  108. err = create_and_submit_tasks();
  109. unregister_handle();
  110. starpu_shutdown();
  111. if (err == -ENODEV)
  112. goto enodev;
  113. #if defined(STARPU_USE_CUDA)
  114. if (global_stats.cuda == 1)
  115. {
  116. if (global_stats.cpu_to_cuda == 1 &&
  117. global_stats.cuda_to_cpu == 1)
  118. return EXIT_SUCCESS;
  119. else
  120. return EXIT_FAILURE;
  121. }
  122. #endif /* !STARPU_USE_CUDA */
  123. #if defined(STARPU_USE_OPENCL)
  124. if (global_stats.opencl == 1)
  125. {
  126. if (global_stats.cpu_to_opencl == 1 &&
  127. global_stats.opencl_to_cpu == 1)
  128. return EXIT_SUCCESS;
  129. else
  130. return EXIT_FAILURE;
  131. }
  132. #endif /* !STARPU_USE_OPENCL */
  133. /* We should not get here */
  134. return EXIT_FAILURE;
  135. enodev:
  136. #endif
  137. return STARPU_TEST_SKIPPED;
  138. }