nowhere.c 3.8 KB

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