submit.c 3.2 KB

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