starpu_task_bundle.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <config.h>
  17. #if STARPU_HAVE_VALGRIND_H
  18. #include <valgrind/valgrind.h>
  19. #endif
  20. #include <starpu.h>
  21. #include "../helper.h"
  22. #define NB_BUNDLE 10
  23. #define NB_ITERATION 5
  24. void func_cpu(void *descr[], void *args)
  25. {
  26. STARPU_SKIP_IF_VALGRIND;
  27. float *x = (float *) STARPU_VARIABLE_GET_PTR(descr[0]);
  28. float factor;
  29. factor = *(float *) args;
  30. *x *= factor;
  31. }
  32. struct starpu_codelet codelet =
  33. {
  34. .modes = {STARPU_RW},
  35. .where = STARPU_CPU,
  36. .cpu_funcs = {func_cpu, NULL},
  37. .nbuffers = 1
  38. };
  39. int main(int argc, char **argv)
  40. {
  41. int i, j, ret;
  42. float data[NB_BUNDLE];
  43. float factors[NB_BUNDLE];
  44. starpu_data_handle_t handles[NB_BUNDLE];
  45. struct starpu_task *task[NB_ITERATION];
  46. starpu_task_bundle_t bundles[NB_BUNDLE];
  47. for (i = 0; i < NB_BUNDLE; i++)
  48. {
  49. data[i] = i + 1;
  50. factors[i] = NB_BUNDLE - i;
  51. }
  52. ret = starpu_init(NULL);
  53. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  55. for (i = 0; i < NB_BUNDLE; i++)
  56. starpu_variable_data_register(&handles[i], 0, (uintptr_t)&data[i], sizeof(float));
  57. FPRINTF(stderr, "VALUES:");
  58. for (i = 0; i < NB_BUNDLE; i++)
  59. FPRINTF(stderr, " %f (%f)", data[i], factors[i]);
  60. FPRINTF(stderr, "\n");
  61. for (i = 0; i < NB_BUNDLE; i++)
  62. {
  63. starpu_task_bundle_create(&bundles[i]);
  64. for (j = 0; j < NB_ITERATION; j++)
  65. {
  66. task[j] = starpu_task_create();
  67. task[j]->cl = &codelet;
  68. task[j]->cl_arg = &factors[i];
  69. task[j]->cl_arg_size = sizeof(float);
  70. task[j]->handles[0] = handles[i];
  71. ret = starpu_task_bundle_insert(bundles[i], task[j]);
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  73. }
  74. ret = starpu_task_bundle_remove(bundles[i], task[NB_ITERATION / 2]);
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_remove");
  76. for (j = 0; j < NB_ITERATION; j++)
  77. {
  78. ret = starpu_task_submit(task[j]);
  79. if (ret == -ENODEV) goto enodev;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  81. }
  82. starpu_task_bundle_close(bundles[i]);
  83. }
  84. ret = starpu_task_wait_for_all();
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  86. for(i = 0; i < NB_BUNDLE ; i++)
  87. {
  88. ret = starpu_data_acquire(handles[i], STARPU_R);
  89. STARPU_CHECK_RETURN_VALUE(ret, "starpu_data_acquire");
  90. }
  91. FPRINTF(stderr, "VALUES:");
  92. for (i = 0; i < NB_BUNDLE; i++)
  93. FPRINTF(stderr, " %f (%f)", data[i], factors[i]);
  94. FPRINTF(stderr, "\n");
  95. for(i = 0; i < NB_BUNDLE ; i++)
  96. {
  97. starpu_data_release(handles[i]);
  98. starpu_data_unregister(handles[i]);
  99. }
  100. starpu_shutdown();
  101. return EXIT_SUCCESS;
  102. enodev:
  103. starpu_shutdown();
  104. fprintf(stderr, "WARNING: No one can execute this task\n");
  105. /* yes, we do not perform the computation but we did detect that no one
  106. * could perform the kernel, so this is not an error from StarPU */
  107. return STARPU_TEST_SKIPPED;
  108. }