nowhere.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2016 Université de Bordeaux
  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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #include "../helper.h"
  22. /*
  23. * Try the NOWHERE flag
  24. */
  25. static int x, y;
  26. static void prod(void *descr[], void *_args STARPU_ATTRIBUTE_UNUSED)
  27. {
  28. int *v = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  29. *v = 1;
  30. }
  31. static struct starpu_codelet cl_prod =
  32. {
  33. .cpu_funcs = { prod },
  34. .nbuffers = 1,
  35. .modes = { STARPU_W },
  36. };
  37. static void callback0(void *callback_arg)
  38. {
  39. STARPU_ASSERT(x==0);
  40. STARPU_ASSERT(y==0);
  41. }
  42. static void callback(void *callback_arg)
  43. {
  44. STARPU_ASSERT(x>=1);
  45. STARPU_ASSERT(y>=1);
  46. }
  47. static struct starpu_codelet cl_nowhere =
  48. {
  49. .where = STARPU_NOWHERE,
  50. .nbuffers = 2,
  51. .modes = { STARPU_R, STARPU_R },
  52. };
  53. static void cons(void *descr[], void *_args STARPU_ATTRIBUTE_UNUSED)
  54. {
  55. int *v = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  56. STARPU_ASSERT(*v == 1);
  57. *v = 2;
  58. }
  59. static struct starpu_codelet cl_cons =
  60. {
  61. .cpu_funcs = { cons },
  62. .nbuffers = 1,
  63. .modes = { STARPU_RW },
  64. };
  65. int main(int argc, char **argv)
  66. {
  67. starpu_data_handle_t handle_x, handle_y;
  68. int ret;
  69. ret = starpu_initialize(NULL, &argc, &argv);
  70. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  72. starpu_variable_data_register(&handle_x, STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  73. starpu_variable_data_register(&handle_y, STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  74. ret = starpu_task_insert(&cl_nowhere, STARPU_R, handle_x, STARPU_R, handle_y, STARPU_CALLBACK, callback0, 0);
  75. if (ret == -ENODEV) goto enodev;
  76. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  77. ret = starpu_task_insert(&cl_prod, STARPU_W, handle_x, 0);
  78. if (ret == -ENODEV) goto enodev;
  79. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  80. ret = starpu_task_insert(&cl_prod, STARPU_W, handle_y, 0);
  81. if (ret == -ENODEV) goto enodev;
  82. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  83. ret = starpu_task_insert(&cl_nowhere, STARPU_R, handle_x, STARPU_R, handle_y, STARPU_CALLBACK, callback, 0);
  84. if (ret == -ENODEV) goto enodev;
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  86. ret = starpu_task_insert(&cl_cons, STARPU_RW, handle_x, 0);
  87. if (ret == -ENODEV) goto enodev;
  88. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  89. ret = starpu_task_insert(&cl_cons, STARPU_RW, handle_y, 0);
  90. if (ret == -ENODEV) goto enodev;
  91. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  92. ret = starpu_task_wait_for_all();
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  94. starpu_data_unregister(handle_x);
  95. starpu_data_unregister(handle_y);
  96. starpu_shutdown();
  97. return EXIT_SUCCESS;
  98. enodev:
  99. starpu_data_unregister(handle_x);
  100. starpu_data_unregister(handle_y);
  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. starpu_shutdown();
  105. return STARPU_TEST_SKIPPED;
  106. }