nowhere.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 *arg)
  28. {
  29. (void)arg;
  30. int *v = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  31. *v = 1;
  32. }
  33. static struct starpu_codelet cl_prod =
  34. {
  35. .cpu_funcs = { prod },
  36. .nbuffers = 1,
  37. .modes = { STARPU_W },
  38. };
  39. static void callback0(void *callback_arg)
  40. {
  41. (void)callback_arg;
  42. STARPU_ASSERT(x==0);
  43. STARPU_ASSERT(y==0);
  44. }
  45. static void callback(void *callback_arg)
  46. {
  47. (void)callback_arg;
  48. STARPU_ASSERT(x>=1);
  49. STARPU_ASSERT(y>=1);
  50. }
  51. static struct starpu_codelet cl_nowhere =
  52. {
  53. .where = STARPU_NOWHERE,
  54. .nbuffers = 2,
  55. .modes = { STARPU_R, STARPU_R },
  56. };
  57. static void cons(void *descr[], void *_args)
  58. {
  59. (void)_args;
  60. int *v = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  61. STARPU_ASSERT(*v == 1);
  62. *v = 2;
  63. }
  64. static struct starpu_codelet cl_cons =
  65. {
  66. .cpu_funcs = { cons },
  67. .nbuffers = 1,
  68. .modes = { STARPU_RW },
  69. };
  70. int main(int argc, char **argv)
  71. {
  72. starpu_data_handle_t handle_x, handle_y;
  73. int ret;
  74. ret = starpu_initialize(NULL, &argc, &argv);
  75. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  76. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  77. if (starpu_memory_nodes_get_numa_count() > 1)
  78. {
  79. /* FIXME: assumes only one RAM node */
  80. starpu_shutdown();
  81. return STARPU_TEST_SKIPPED;
  82. }
  83. starpu_variable_data_register(&handle_x, STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  84. starpu_variable_data_register(&handle_y, STARPU_MAIN_RAM, (uintptr_t)&y, sizeof(y));
  85. ret = starpu_task_insert(&cl_nowhere, STARPU_R, handle_x, STARPU_R, handle_y, STARPU_CALLBACK, callback0, 0);
  86. if (ret == -ENODEV) goto enodev;
  87. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  88. ret = starpu_task_insert(&cl_prod, STARPU_W, handle_x, 0);
  89. if (ret == -ENODEV) goto enodev;
  90. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  91. ret = starpu_task_insert(&cl_prod, STARPU_W, handle_y, 0);
  92. if (ret == -ENODEV) goto enodev;
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  94. ret = starpu_task_insert(&cl_nowhere, STARPU_R, handle_x, STARPU_R, handle_y, STARPU_CALLBACK, callback, 0);
  95. if (ret == -ENODEV) goto enodev;
  96. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  97. ret = starpu_task_insert(&cl_cons, STARPU_RW, handle_x, 0);
  98. if (ret == -ENODEV) goto enodev;
  99. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  100. ret = starpu_task_insert(&cl_cons, STARPU_RW, handle_y, 0);
  101. if (ret == -ENODEV) goto enodev;
  102. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  103. ret = starpu_task_wait_for_all();
  104. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  105. starpu_data_unregister(handle_x);
  106. starpu_data_unregister(handle_y);
  107. starpu_shutdown();
  108. return EXIT_SUCCESS;
  109. enodev:
  110. starpu_data_unregister(handle_x);
  111. starpu_data_unregister(handle_y);
  112. fprintf(stderr, "WARNING: No one can execute this task\n");
  113. /* yes, we do not perform the computation but we did detect that no one
  114. * could perform the kernel, so this is not an error from StarPU */
  115. starpu_shutdown();
  116. return STARPU_TEST_SKIPPED;
  117. }