submit.c 3.0 KB

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