tasks_overhead.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <sys/time.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <pthread.h>
  20. #include <starpu.h>
  21. starpu_data_handle data_handles[8];
  22. float *buffers[8];
  23. static unsigned ntasks = 65536;
  24. static unsigned nbuffers = 0;
  25. struct starpu_task *tasks;
  26. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  27. {
  28. }
  29. static starpu_codelet dummy_codelet =
  30. {
  31. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  32. .cpu_func = dummy_func,
  33. .cuda_func = dummy_func,
  34. .opencl_func = dummy_func,
  35. .model = NULL,
  36. .nbuffers = 0
  37. };
  38. void inject_one_task(void)
  39. {
  40. struct starpu_task *task = starpu_task_create();
  41. task->cl = &dummy_codelet;
  42. task->cl_arg = NULL;
  43. task->callback_func = NULL;
  44. task->synchronous = 1;
  45. starpu_task_submit(task);
  46. }
  47. static void parse_args(int argc, char **argv)
  48. {
  49. int c;
  50. while ((c = getopt(argc, argv, "i:b:h")) != -1)
  51. switch(c) {
  52. case 'i':
  53. ntasks = atoi(optarg);
  54. break;
  55. case 'b':
  56. nbuffers = atoi(optarg);
  57. dummy_codelet.nbuffers = nbuffers;
  58. break;
  59. case 'h':
  60. fprintf(stderr, "Usage: %s [-i ntasks] [-b nbuffers] [-h]\n", argv[0]);
  61. break;
  62. }
  63. }
  64. int main(int argc, char **argv)
  65. {
  66. unsigned i;
  67. double timing_submit;
  68. struct timeval start_submit;
  69. struct timeval end_submit;
  70. double timing_exec;
  71. struct timeval start_exec;
  72. struct timeval end_exec;
  73. parse_args(argc, argv);
  74. unsigned buffer;
  75. for (buffer = 0; buffer < nbuffers; buffer++)
  76. {
  77. buffers[buffer] = malloc(16*sizeof(float));
  78. starpu_vector_data_register(&data_handles[buffer], 0, (uintptr_t)buffers[buffer], 16, sizeof(float));
  79. }
  80. starpu_init(NULL);
  81. fprintf(stderr, "#tasks : %d\n#buffers : %d\n", ntasks, nbuffers);
  82. /* submit tasks (but don't execute them yet !) */
  83. tasks = malloc(ntasks*sizeof(struct starpu_task));
  84. gettimeofday(&start_submit, NULL);
  85. for (i = 0; i < ntasks; i++)
  86. {
  87. tasks[i].callback_func = NULL;
  88. tasks[i].cl = &dummy_codelet;
  89. tasks[i].cl_arg = NULL;
  90. tasks[i].synchronous = 0;
  91. tasks[i].use_tag = 1;
  92. tasks[i].tag_id = (starpu_tag_t)i;
  93. /* we have 8 buffers at most */
  94. for (buffer = 0; buffer < nbuffers; buffer++)
  95. {
  96. tasks[i].buffers[buffer].handle = data_handles[buffer];
  97. tasks[i].buffers[buffer].mode = STARPU_RW;
  98. }
  99. }
  100. gettimeofday(&start_submit, NULL);
  101. for (i = 1; i < ntasks; i++)
  102. {
  103. starpu_tag_declare_deps((starpu_tag_t)i, 1, (starpu_tag_t)(i-1));
  104. starpu_task_submit(&tasks[i]);
  105. }
  106. /* submit the first task */
  107. starpu_task_submit(&tasks[0]);
  108. gettimeofday(&end_submit, NULL);
  109. /* wait for the execution of the tasks */
  110. gettimeofday(&start_exec, NULL);
  111. starpu_tag_wait((starpu_tag_t)(ntasks - 1));
  112. gettimeofday(&end_exec, NULL);
  113. timing_submit = (double)((end_submit.tv_sec - start_submit.tv_sec)*1000000 + (end_submit.tv_usec - start_submit.tv_usec));
  114. timing_exec = (double)((end_exec.tv_sec - start_exec.tv_sec)*1000000 + (end_exec.tv_usec - start_exec.tv_usec));
  115. fprintf(stderr, "Total submit: %lf secs\n", timing_submit/1000000);
  116. fprintf(stderr, "Per task submit: %lf usecs\n", timing_submit/ntasks);
  117. fprintf(stderr, "\n");
  118. fprintf(stderr, "Total execution: %lf secs\n", timing_exec/1000000);
  119. fprintf(stderr, "Per task execution: %lf usecs\n", timing_exec/ntasks);
  120. fprintf(stderr, "\n");
  121. fprintf(stderr, "Total: %lf secs\n", (timing_submit+timing_exec)/1000000);
  122. fprintf(stderr, "Per task: %lf usecs\n", (timing_submit+timing_exec)/ntasks);
  123. {
  124. char *output_dir = getenv("STARPU_BENCH_DIR");
  125. char *bench_id = getenv("STARPU_BENCH_ID");
  126. if (output_dir && bench_id) {
  127. char file[1024];
  128. FILE *f;
  129. sprintf(file, "%s/tasks_overhead_total_submit.dat", output_dir);
  130. f = fopen(file, "a");
  131. fprintf(f, "%s\t%lf\n", bench_id, timing_submit/1000000);
  132. fclose(f);
  133. sprintf(file, "%s/tasks_overhead_per_task_submit.dat", output_dir);
  134. f = fopen(file, "a");
  135. fprintf(f, "%s\t%lf\n", bench_id, timing_submit/ntasks);
  136. fclose(f);
  137. sprintf(file, "%s/tasks_overhead_total_execution.dat", output_dir);
  138. f = fopen(file, "a");
  139. fprintf(f, "%s\t%lf\n", bench_id, timing_exec/1000000);
  140. fclose(f);
  141. sprintf(file, "%s/tasks_overhead_per_task_execution.dat", output_dir);
  142. f = fopen(file, "a");
  143. fprintf(f, "%s\t%lf\n", bench_id, timing_exec/ntasks);
  144. fclose(f);
  145. sprintf(file, "%s/tasks_overhead_total_submit_execution.dat", output_dir);
  146. f = fopen(file, "a");
  147. fprintf(f, "%s\t%lf\n", bench_id, (timing_submit+timing_exec)/1000000);
  148. fclose(f);
  149. sprintf(file, "%s/tasks_overhead_per_task_submit_execution.dat", output_dir);
  150. f = fopen(file, "a");
  151. fprintf(f, "%s\t%lf\n", bench_id, (timing_submit+timing_exec)/ntasks);
  152. fclose(f);
  153. }
  154. }
  155. starpu_shutdown();
  156. return 0;
  157. }