tasks_overhead.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 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. starpu_data_handle data_handles[8];
  23. float *buffers[8];
  24. static unsigned ntasks = 65536;
  25. static unsigned nbuffers = 0;
  26. struct starpu_task *tasks;
  27. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  28. {
  29. }
  30. static starpu_codelet dummy_codelet =
  31. {
  32. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  33. .cpu_func = dummy_func,
  34. .cuda_func = dummy_func,
  35. .opencl_func = dummy_func,
  36. .model = NULL,
  37. .nbuffers = 0
  38. };
  39. void inject_one_task(void)
  40. {
  41. struct starpu_task *task = starpu_task_create();
  42. task->cl = &dummy_codelet;
  43. task->cl_arg = NULL;
  44. task->callback_func = NULL;
  45. task->synchronous = 1;
  46. starpu_task_submit(task);
  47. }
  48. static void parse_args(int argc, char **argv)
  49. {
  50. int c;
  51. while ((c = getopt(argc, argv, "i:b:h")) != -1)
  52. switch(c) {
  53. case 'i':
  54. ntasks = atoi(optarg);
  55. break;
  56. case 'b':
  57. nbuffers = atoi(optarg);
  58. dummy_codelet.nbuffers = nbuffers;
  59. break;
  60. case 'h':
  61. fprintf(stderr, "Usage: %s [-i ntasks] [-b nbuffers] [-h]\n", argv[0]);
  62. break;
  63. }
  64. }
  65. int main(int argc, char **argv)
  66. {
  67. unsigned i;
  68. double timing_submit;
  69. struct timeval start_submit;
  70. struct timeval end_submit;
  71. double timing_exec;
  72. struct timeval start_exec;
  73. struct timeval end_exec;
  74. parse_args(argc, argv);
  75. unsigned buffer;
  76. for (buffer = 0; buffer < nbuffers; buffer++)
  77. {
  78. buffers[buffer] = (float *) malloc(16*sizeof(float));
  79. starpu_vector_data_register(&data_handles[buffer], 0, (uintptr_t)buffers[buffer], 16, sizeof(float));
  80. }
  81. starpu_init(NULL);
  82. fprintf(stderr, "#tasks : %u\n#buffers : %u\n", ntasks, nbuffers);
  83. /* submit tasks (but don't execute them yet !) */
  84. tasks = (struct starpu_task *) malloc(ntasks*sizeof(struct starpu_task));
  85. gettimeofday(&start_submit, NULL);
  86. for (i = 0; i < ntasks; i++)
  87. {
  88. tasks[i].callback_func = NULL;
  89. tasks[i].cl = &dummy_codelet;
  90. tasks[i].cl_arg = NULL;
  91. tasks[i].synchronous = 0;
  92. tasks[i].use_tag = 1;
  93. tasks[i].tag_id = (starpu_tag_t)i;
  94. /* we have 8 buffers at most */
  95. for (buffer = 0; buffer < nbuffers; buffer++)
  96. {
  97. tasks[i].buffers[buffer].handle = data_handles[buffer];
  98. tasks[i].buffers[buffer].mode = STARPU_RW;
  99. }
  100. }
  101. gettimeofday(&start_submit, NULL);
  102. for (i = 1; i < ntasks; i++)
  103. {
  104. starpu_tag_declare_deps((starpu_tag_t)i, 1, (starpu_tag_t)(i-1));
  105. starpu_task_submit(&tasks[i]);
  106. }
  107. /* submit the first task */
  108. starpu_task_submit(&tasks[0]);
  109. gettimeofday(&end_submit, NULL);
  110. /* wait for the execution of the tasks */
  111. gettimeofday(&start_exec, NULL);
  112. starpu_tag_wait((starpu_tag_t)(ntasks - 1));
  113. gettimeofday(&end_exec, NULL);
  114. timing_submit = (double)((end_submit.tv_sec - start_submit.tv_sec)*1000000 + (end_submit.tv_usec - start_submit.tv_usec));
  115. timing_exec = (double)((end_exec.tv_sec - start_exec.tv_sec)*1000000 + (end_exec.tv_usec - start_exec.tv_usec));
  116. fprintf(stderr, "Total submit: %f secs\n", timing_submit/1000000);
  117. fprintf(stderr, "Per task submit: %f usecs\n", timing_submit/ntasks);
  118. fprintf(stderr, "\n");
  119. fprintf(stderr, "Total execution: %f secs\n", timing_exec/1000000);
  120. fprintf(stderr, "Per task execution: %f usecs\n", timing_exec/ntasks);
  121. fprintf(stderr, "\n");
  122. fprintf(stderr, "Total: %f secs\n", (timing_submit+timing_exec)/1000000);
  123. fprintf(stderr, "Per task: %f usecs\n", (timing_submit+timing_exec)/ntasks);
  124. {
  125. char *output_dir = getenv("STARPU_BENCH_DIR");
  126. char *bench_id = getenv("STARPU_BENCH_ID");
  127. if (output_dir && bench_id) {
  128. char file[1024];
  129. FILE *f;
  130. sprintf(file, "%s/tasks_overhead_total_submit.dat", output_dir);
  131. f = fopen(file, "a");
  132. fprintf(f, "%s\t%f\n", bench_id, timing_submit/1000000);
  133. fclose(f);
  134. sprintf(file, "%s/tasks_overhead_per_task_submit.dat", output_dir);
  135. f = fopen(file, "a");
  136. fprintf(f, "%s\t%f\n", bench_id, timing_submit/ntasks);
  137. fclose(f);
  138. sprintf(file, "%s/tasks_overhead_total_execution.dat", output_dir);
  139. f = fopen(file, "a");
  140. fprintf(f, "%s\t%f\n", bench_id, timing_exec/1000000);
  141. fclose(f);
  142. sprintf(file, "%s/tasks_overhead_per_task_execution.dat", output_dir);
  143. f = fopen(file, "a");
  144. fprintf(f, "%s\t%f\n", bench_id, timing_exec/ntasks);
  145. fclose(f);
  146. sprintf(file, "%s/tasks_overhead_total_submit_execution.dat", output_dir);
  147. f = fopen(file, "a");
  148. fprintf(f, "%s\t%f\n", bench_id, (timing_submit+timing_exec)/1000000);
  149. fclose(f);
  150. sprintf(file, "%s/tasks_overhead_per_task_submit_execution.dat", output_dir);
  151. f = fopen(file, "a");
  152. fprintf(f, "%s\t%f\n", bench_id, (timing_submit+timing_exec)/ntasks);
  153. fclose(f);
  154. }
  155. }
  156. starpu_shutdown();
  157. return 0;
  158. }