submit.c 3.0 KB

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