multiformat_worker.c 3.0 KB

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