submit.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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 <stdio.h>
  17. #include <unistd.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test task submission
  22. */
  23. static int i = 0, j;
  24. void dummy_func(void *descr[], void *arg)
  25. {
  26. (void)descr;
  27. (void)arg;
  28. int old_i = STARPU_ATOMIC_ADD(&i, 1);
  29. FPRINTF(stdout, "called third task, i = %d\n", old_i+1);
  30. }
  31. static struct starpu_codelet dummy_codelet =
  32. {
  33. .cpu_funcs = {dummy_func},
  34. .cuda_funcs = {dummy_func},
  35. .opencl_funcs = {dummy_func},
  36. .model = NULL,
  37. .nbuffers = 0
  38. };
  39. static void callback(void *arg)
  40. {
  41. (void)arg;
  42. struct starpu_task *task = starpu_task_create();
  43. task->cl = &dummy_codelet;
  44. task->detach = 1;
  45. if (starpu_task_submit(task) == ENODEV)
  46. exit(STARPU_TEST_SKIPPED);
  47. FPRINTF(stdout, "submitted third task, i = %d\n", i);
  48. }
  49. static struct starpu_codelet callback_submit_codelet =
  50. {
  51. .cpu_funcs = {dummy_func},
  52. .cuda_funcs = {dummy_func},
  53. .opencl_funcs = {dummy_func},
  54. .model = NULL,
  55. .nbuffers = 0
  56. };
  57. static void task_submit_func(void *descr[], void *arg)
  58. {
  59. (void)descr;
  60. (void)arg;
  61. struct starpu_task *task = starpu_task_create();
  62. task->cl = &callback_submit_codelet;
  63. task->callback_func = callback;
  64. task->detach = 1;
  65. if (starpu_task_submit(task) == ENODEV)
  66. exit(STARPU_TEST_SKIPPED);
  67. int old_i = STARPU_ATOMIC_ADD(&i, 1);
  68. FPRINTF(stdout, "submitted second task, i = %d\n", old_i + 1);
  69. }
  70. static struct starpu_codelet task_submit_codelet =
  71. {
  72. .cpu_funcs = {task_submit_func},
  73. .cuda_funcs = {task_submit_func},
  74. .opencl_funcs = {task_submit_func},
  75. .model = NULL,
  76. .nbuffers = 0
  77. };
  78. int main(void)
  79. {
  80. int ret;
  81. ret = starpu_init(NULL);
  82. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  84. struct starpu_task *task = starpu_task_create();
  85. task->cl = &task_submit_codelet;
  86. task->detach = 1;
  87. ret = starpu_task_submit(task);
  88. if (ret == -ENODEV) goto enodev;
  89. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  90. starpu_task_wait_for_all();
  91. j = i;
  92. starpu_shutdown();
  93. return j == 3 ? EXIT_SUCCESS : EXIT_FAILURE;
  94. enodev:
  95. fprintf(stderr, "WARNING: No one can execute this task\n");
  96. /* yes, we do not perform the computation but we did detect that no one
  97. * could perform the kernel, so this is not an error from StarPU */
  98. starpu_shutdown();
  99. return STARPU_TEST_SKIPPED;
  100. }