submit.c 2.9 KB

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