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