multiformat_worker.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. .where = STARPU_CUDA|STARPU_OPENCL,
  35. .modes = { STARPU_RW },
  36. #ifdef STARPU_USE_CUDA
  37. .cuda_funcs = { cuda_func, NULL },
  38. #endif
  39. #ifdef STARPU_USE_OPENCL
  40. .opencl_funcs = { opencl_func, NULL },
  41. #endif
  42. .nbuffers = 1,
  43. };
  44. static void
  45. register_handle(void)
  46. {
  47. int i;
  48. for (i = 0; i < NX; i++)
  49. vector[i] = i;
  50. starpu_multiformat_data_register(&handle, 0, vector, NX, &ops);
  51. }
  52. static void
  53. unregister_handle(void)
  54. {
  55. starpu_data_unregister(handle);
  56. }
  57. static int
  58. create_and_submit_tasks(void)
  59. {
  60. struct starpu_task *task;
  61. task = starpu_task_create();
  62. task->cl = &cl;
  63. task->handles[0] = handle;
  64. task->execute_on_a_specific_worker = 1;
  65. #ifdef STARPU_USE_CUDA
  66. if (ncuda > 0)
  67. {
  68. task->workerid = cuda_worker;
  69. }
  70. else
  71. #endif
  72. #ifdef STARPU_USE_OPENCL
  73. if (nopencl > 0)
  74. {
  75. task->workerid = opencl_worker;
  76. }
  77. else
  78. #endif
  79. {
  80. return -ENODEV;
  81. }
  82. return starpu_task_submit(task);
  83. }
  84. #endif
  85. int
  86. main(void)
  87. {
  88. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  89. int err;
  90. err = starpu_init(NULL);
  91. if (err == -ENODEV)
  92. goto enodev;
  93. #ifdef STARPU_USE_CUDA
  94. ncuda = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  95. &cuda_worker, 1);
  96. if (ncuda < 0)
  97. ncuda = 1;
  98. #endif
  99. #ifdef STARPU_USE_OPENCL
  100. nopencl = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  101. &opencl_worker, 1);
  102. if (nopencl < 0)
  103. nopencl = 1;
  104. #endif
  105. reset_stats(&global_stats);
  106. register_handle();
  107. err = create_and_submit_tasks();
  108. unregister_handle();
  109. starpu_shutdown();
  110. if (err == -ENODEV)
  111. goto enodev;
  112. #if defined(STARPU_USE_CUDA)
  113. if (global_stats.cuda == 1)
  114. {
  115. if (global_stats.cpu_to_cuda == 1 &&
  116. global_stats.cuda_to_cpu == 1)
  117. return EXIT_SUCCESS;
  118. else
  119. return EXIT_FAILURE;
  120. }
  121. #endif /* !STARPU_USE_CUDA */
  122. #if defined(STARPU_USE_OPENCL)
  123. if (global_stats.opencl == 1)
  124. {
  125. if (global_stats.cpu_to_opencl == 1 &&
  126. global_stats.opencl_to_cpu == 1)
  127. return EXIT_SUCCESS;
  128. else
  129. return EXIT_FAILURE;
  130. }
  131. #endif /* !STARPU_USE_OPENCL */
  132. /* We should not get here */
  133. return EXIT_FAILURE;
  134. enodev:
  135. #endif
  136. return STARPU_TEST_SKIPPED;
  137. }