starpu_task_wait_for_all.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 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 <starpu.h>
  18. #include <sys/time.h>
  19. #include <pthread.h>
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include "../helper.h"
  23. static unsigned ntasks = 65536;
  24. static void dummy_func(void *descr[], void *arg)
  25. {
  26. }
  27. static struct starpu_codelet dummy_codelet =
  28. {
  29. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL|STARPU_GORDON,
  30. .cpu_funcs = {dummy_func, NULL},
  31. .cuda_funcs = {dummy_func, NULL},
  32. .opencl_funcs = {dummy_func, NULL},
  33. #ifdef STARPU_USE_GORDON
  34. .gordon_func = 0, /* this will be defined later */
  35. #endif
  36. .model = NULL,
  37. .nbuffers = 0
  38. };
  39. static void init_gordon_kernel(void)
  40. {
  41. #ifdef STARPU_USE_GORDON
  42. unsigned elf_id =
  43. gordon_register_elf_plugin("./microbenchs/null_kernel_gordon.spuelf");
  44. gordon_load_plugin_on_all_spu(elf_id);
  45. unsigned gordon_null_kernel =
  46. gordon_register_kernel(elf_id, "empty_kernel");
  47. gordon_load_kernel_on_all_spu(gordon_null_kernel);
  48. dummy_codelet.gordon_func = gordon_null_kernel;
  49. #endif
  50. }
  51. static int inject_one_task(void)
  52. {
  53. struct starpu_task *task = starpu_task_create();
  54. task->cl = &dummy_codelet;
  55. task->cl_arg = NULL;
  56. task->callback_func = NULL;
  57. task->callback_arg = NULL;
  58. int ret = starpu_task_submit(task);
  59. return ret;
  60. }
  61. static struct starpu_conf conf =
  62. {
  63. .sched_policy_name = NULL,
  64. .ncpus = -1,
  65. .ncuda = -1,
  66. .nopencl = -1,
  67. .nspus = -1,
  68. .use_explicit_workers_bindid = 0,
  69. .use_explicit_workers_cuda_gpuid = 0,
  70. .use_explicit_workers_opencl_gpuid = 0,
  71. .calibrate = 0
  72. };
  73. static void usage(char **argv)
  74. {
  75. FPRINTF(stderr, "%s [-i ntasks] [-p sched_policy] [-h]\n", argv[0]);
  76. exit(-1);
  77. }
  78. static void parse_args(int argc, char **argv)
  79. {
  80. int c;
  81. while ((c = getopt(argc, argv, "i:p:h")) != -1)
  82. switch(c)
  83. {
  84. case 'i':
  85. ntasks = atoi(optarg);
  86. break;
  87. case 'p':
  88. conf.sched_policy_name = optarg;
  89. break;
  90. case 'h':
  91. usage(argv);
  92. break;
  93. }
  94. }
  95. int main(int argc, char **argv)
  96. {
  97. unsigned i;
  98. double timing;
  99. struct timeval start;
  100. struct timeval end;
  101. int ret;
  102. parse_args(argc, argv);
  103. #ifdef STARPU_SLOW_MACHINE
  104. ntasks /= 10;
  105. #endif
  106. ret = starpu_init(&conf);
  107. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  108. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  109. init_gordon_kernel();
  110. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  111. gettimeofday(&start, NULL);
  112. for (i = 0; i < ntasks; i++)
  113. {
  114. ret = inject_one_task();
  115. if (ret == -ENODEV) goto enodev;
  116. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  117. }
  118. ret = starpu_task_wait_for_all();
  119. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  120. gettimeofday(&end, NULL);
  121. timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  122. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  123. FPRINTF(stderr, "Per task: %f usecs\n", timing/ntasks);
  124. starpu_shutdown();
  125. return EXIT_SUCCESS;
  126. enodev:
  127. fprintf(stderr, "WARNING: No one can execute this task\n");
  128. /* yes, we do not perform the computation but we did detect that no one
  129. * could perform the kernel, so this is not an error from StarPU */
  130. starpu_shutdown();
  131. return STARPU_TEST_SKIPPED;
  132. }