starpu_task_bundle.c 3.6 KB

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