async_tasks_overhead.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2014,2016 Université de Bordeaux
  4. * Copyright (C) 2010-2013,2015-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. * Measure the cost of submitting asynchronous tasks
  23. */
  24. static unsigned ntasks = 65536;
  25. //static unsigned finished = 0;
  26. static double cumulated = 0.0;
  27. static double cumulated_push = 0.0;
  28. static double cumulated_pop = 0.0;
  29. void dummy_func(void *descr[], void *arg)
  30. {
  31. (void)descr;
  32. (void)arg;
  33. }
  34. static struct starpu_codelet dummy_codelet =
  35. {
  36. .cpu_funcs = {dummy_func},
  37. .cuda_funcs = {dummy_func},
  38. .opencl_funcs = {dummy_func},
  39. .cpu_funcs_name = {"dummy_func"},
  40. .model = NULL,
  41. .nbuffers = 0
  42. };
  43. //static void inject_one_task(void)
  44. //{
  45. // struct starpu_task *task = starpu_task_create();
  46. //
  47. // task->cl = &dummy_codelet;
  48. // task->cl_arg = NULL;
  49. // task->detach = 0;
  50. //
  51. // int ret = starpu_task_submit(task);
  52. // STARPU_ASSERT(!ret);
  53. //}
  54. static void usage(char **argv)
  55. {
  56. fprintf(stderr, "%s [-i ntasks] [-p sched_policy] [-h]\n", argv[0]);
  57. exit(-1);
  58. }
  59. static void parse_args(int argc, char **argv, struct starpu_conf *conf)
  60. {
  61. int c;
  62. while ((c = getopt(argc, argv, "i:p:h")) != -1)
  63. switch(c)
  64. {
  65. case 'i':
  66. ntasks = atoi(optarg);
  67. break;
  68. case 'p':
  69. conf->sched_policy_name = optarg;
  70. break;
  71. case 'h':
  72. usage(argv);
  73. break;
  74. }
  75. }
  76. int main(int argc, char **argv)
  77. {
  78. int ret;
  79. unsigned i;
  80. double timing;
  81. double start;
  82. double end;
  83. struct starpu_conf conf;
  84. starpu_conf_init(&conf);
  85. conf.ncpus = 2;
  86. #ifdef STARPU_QUICK_CHECK
  87. ntasks = 128;
  88. #endif
  89. parse_args(argc, argv, &conf);
  90. ret = starpu_initialize(&conf, &argc, &argv);
  91. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  92. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  93. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  94. fprintf(stderr, "#tasks : %u\n", ntasks);
  95. /* Create an array of tasks */
  96. struct starpu_task **tasks = (struct starpu_task **) malloc(ntasks*sizeof(struct starpu_task *));
  97. for (i = 0; i < ntasks; i++)
  98. {
  99. struct starpu_task *task = starpu_task_create();
  100. task->cl = &dummy_codelet;
  101. task->cl_arg = NULL;
  102. task->detach = 0;
  103. tasks[i] = task;
  104. }
  105. start = starpu_timing_now();
  106. for (i = 0; i < ntasks; i++)
  107. {
  108. ret = starpu_task_submit(tasks[i]);
  109. if (ret == -ENODEV) goto enodev;
  110. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  111. }
  112. ret = starpu_task_wait_for_all();
  113. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  114. end = starpu_timing_now();
  115. /* Read profiling feedback */
  116. for (i = 0; i < ntasks; i++)
  117. {
  118. struct starpu_profiling_task_info *info;
  119. info = tasks[i]->profiling_info;
  120. double queued = starpu_timing_timespec_delay_us(&info->push_end_time, &info->pop_end_time);
  121. double length = starpu_timing_timespec_delay_us(&info->submit_time, &info->end_time);
  122. double push_duration = starpu_timing_timespec_delay_us(&info->push_start_time, &info->push_end_time);
  123. double pop_duration = starpu_timing_timespec_delay_us(&info->pop_start_time, &info->pop_end_time);
  124. starpu_task_destroy(tasks[i]);
  125. cumulated += (length - queued);
  126. cumulated_push += push_duration;
  127. cumulated_pop += pop_duration;
  128. }
  129. timing = end - start;
  130. fprintf(stderr, "Total: %f secs\n", timing/1000000);
  131. fprintf(stderr, "Per task: %f usecs\n", timing/ntasks);
  132. fprintf(stderr, "Per task (except scheduler): %f usecs\n", cumulated/ntasks);
  133. fprintf(stderr, "Per task (push): %f usecs\n", cumulated_push/ntasks);
  134. fprintf(stderr, "Per task (pop): %f usecs\n", cumulated_pop/ntasks);
  135. {
  136. char *output_dir = getenv("STARPU_BENCH_DIR");
  137. char *bench_id = getenv("STARPU_BENCH_ID");
  138. if (output_dir && bench_id)
  139. {
  140. char file[1024];
  141. FILE *f;
  142. snprintf(file, sizeof(file), "%s/async_tasks_overhead_total.dat", output_dir);
  143. f = fopen(file, "a");
  144. fprintf(f, "%s\t%f\n", bench_id, timing/1000000);
  145. fclose(f);
  146. snprintf(file, sizeof(file), "%s/async_tasks_overhead_per_task.dat", output_dir);
  147. f = fopen(file, "a");
  148. fprintf(f, "%s\t%f\n", bench_id, timing/ntasks);
  149. fclose(f);
  150. }
  151. }
  152. starpu_shutdown();
  153. free(tasks);
  154. return EXIT_SUCCESS;
  155. enodev:
  156. fprintf(stderr, "WARNING: No one can execute this task\n");
  157. /* yes, we do not perform the computation but we did detect that no one
  158. * could perform the kernel, so this is not an error from StarPU */
  159. starpu_shutdown();
  160. free(tasks);
  161. return STARPU_TEST_SKIPPED;
  162. }