multiformat_worker.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 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, NULL },
  37. #endif
  38. #ifdef STARPU_USE_OPENCL
  39. .opencl_funcs = { opencl_func, NULL },
  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, 0, 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. return -ENODEV;
  80. }
  81. return starpu_task_submit(task);
  82. }
  83. #endif
  84. int
  85. main(void)
  86. {
  87. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  88. int err;
  89. err = starpu_init(NULL);
  90. if (err == -ENODEV)
  91. goto enodev;
  92. #ifdef STARPU_USE_CUDA
  93. ncuda = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  94. &cuda_worker, 1);
  95. if (ncuda < 0)
  96. ncuda = 1;
  97. #endif
  98. #ifdef STARPU_USE_OPENCL
  99. nopencl = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  100. &opencl_worker, 1);
  101. if (nopencl < 0)
  102. nopencl = 1;
  103. #endif
  104. reset_stats(&global_stats);
  105. register_handle();
  106. err = create_and_submit_tasks();
  107. unregister_handle();
  108. starpu_shutdown();
  109. if (err == -ENODEV)
  110. goto enodev;
  111. #if defined(STARPU_USE_CUDA)
  112. if (global_stats.cuda == 1)
  113. {
  114. if (global_stats.cpu_to_cuda == 1 &&
  115. global_stats.cuda_to_cpu == 1)
  116. return EXIT_SUCCESS;
  117. else
  118. return EXIT_FAILURE;
  119. }
  120. #endif /* !STARPU_USE_CUDA */
  121. #if defined(STARPU_USE_OPENCL)
  122. if (global_stats.opencl == 1)
  123. {
  124. if (global_stats.cpu_to_opencl == 1 &&
  125. global_stats.opencl_to_cpu == 1)
  126. return EXIT_SUCCESS;
  127. else
  128. return EXIT_FAILURE;
  129. }
  130. #endif /* !STARPU_USE_OPENCL */
  131. /* We should not get here */
  132. return EXIT_FAILURE;
  133. enodev:
  134. #endif
  135. return STARPU_TEST_SKIPPED;
  136. }