nowhere.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2016 Université de Bordeaux
  4. * Copyright (C) 2017 Inria
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <errno.h>
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include "../helper.h"
  23. /*
  24. * Try the NOWHERE flag
  25. */
  26. static int x, y;
  27. static void prod(void *descr[], void *_args STARPU_ATTRIBUTE_UNUSED)
  28. {
  29. int *v = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  30. *v = 1;
  31. }
  32. static struct starpu_codelet cl_prod =
  33. {
  34. .cpu_funcs = { prod },
  35. .nbuffers = 1,
  36. .modes = { STARPU_W },
  37. };
  38. static void callback0(void *callback_arg)
  39. {
  40. STARPU_ASSERT(x==0);
  41. STARPU_ASSERT(y==0);
  42. }
  43. static void callback(void *callback_arg)
  44. {
  45. STARPU_ASSERT(x>=1);
  46. STARPU_ASSERT(y>=1);
  47. }
  48. static struct starpu_codelet cl_nowhere =
  49. {
  50. .where = STARPU_NOWHERE,
  51. .nbuffers = 2,
  52. .modes = { STARPU_R, STARPU_R },
  53. };
  54. static void cons(void *descr[], void *_args STARPU_ATTRIBUTE_UNUSED)
  55. {
  56. int *v = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  57. STARPU_ASSERT(*v == 1);
  58. *v = 2;
  59. }
  60. static struct starpu_codelet cl_cons =
  61. {
  62. .cpu_funcs = { cons },
  63. .nbuffers = 1,
  64. .modes = { STARPU_RW },
  65. };
  66. int main(int argc, char **argv)
  67. {
  68. starpu_data_handle_t handle_x, handle_y;
  69. int ret;
  70. ret = starpu_initialize(NULL, &argc, &argv);
  71. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  73. if (starpu_memory_nodes_get_numa_count() > 1)
  74. {
  75. /* FIXME: assumes only one RAM node */
  76. starpu_shutdown();
  77. return STARPU_TEST_SKIPPED;
  78. }
  79. starpu_variable_data_register(&handle_x, STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  80. starpu_variable_data_register(&handle_y, STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  81. ret = starpu_task_insert(&cl_nowhere, STARPU_R, handle_x, STARPU_R, handle_y, STARPU_CALLBACK, callback0, 0);
  82. if (ret == -ENODEV) goto enodev;
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  84. ret = starpu_task_insert(&cl_prod, STARPU_W, handle_x, 0);
  85. if (ret == -ENODEV) goto enodev;
  86. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  87. ret = starpu_task_insert(&cl_prod, STARPU_W, handle_y, 0);
  88. if (ret == -ENODEV) goto enodev;
  89. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  90. ret = starpu_task_insert(&cl_nowhere, STARPU_R, handle_x, STARPU_R, handle_y, STARPU_CALLBACK, callback, 0);
  91. if (ret == -ENODEV) goto enodev;
  92. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  93. ret = starpu_task_insert(&cl_cons, STARPU_RW, handle_x, 0);
  94. if (ret == -ENODEV) goto enodev;
  95. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  96. ret = starpu_task_insert(&cl_cons, STARPU_RW, handle_y, 0);
  97. if (ret == -ENODEV) goto enodev;
  98. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  99. ret = starpu_task_wait_for_all();
  100. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  101. starpu_data_unregister(handle_x);
  102. starpu_data_unregister(handle_y);
  103. starpu_shutdown();
  104. return EXIT_SUCCESS;
  105. enodev:
  106. starpu_data_unregister(handle_x);
  107. starpu_data_unregister(handle_y);
  108. fprintf(stderr, "WARNING: No one can execute this task\n");
  109. /* yes, we do not perform the computation but we did detect that no one
  110. * could perform the kernel, so this is not an error from StarPU */
  111. starpu_shutdown();
  112. return STARPU_TEST_SKIPPED;
  113. }