async_tasks_overhead.c 5.1 KB

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