starpu_task_bundle.c 3.4 KB

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