tasks-overhead.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (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,
  32. .cpu_func = dummy_func,
  33. .cuda_func = dummy_func,
  34. .model = NULL,
  35. .nbuffers = 0
  36. };
  37. void inject_one_task(void)
  38. {
  39. struct starpu_task *task = starpu_task_create();
  40. task->cl = &dummy_codelet;
  41. task->cl_arg = NULL;
  42. task->callback_func = NULL;
  43. task->synchronous = 1;
  44. starpu_submit_task(task);
  45. }
  46. static void parse_args(int argc, char **argv)
  47. {
  48. int c;
  49. while ((c = getopt(argc, argv, "i:b:h")) != -1)
  50. switch(c) {
  51. case 'i':
  52. ntasks = atoi(optarg);
  53. break;
  54. case 'b':
  55. nbuffers = atoi(optarg);
  56. dummy_codelet.nbuffers = nbuffers;
  57. break;
  58. case 'h':
  59. fprintf(stderr, "Usage: %s [-i ntasks] [-b nbuffers] [-h]\n", argv[0]);
  60. break;
  61. }
  62. }
  63. int main(int argc, char **argv)
  64. {
  65. unsigned i;
  66. double timing_submit;
  67. struct timeval start_submit;
  68. struct timeval end_submit;
  69. double timing_exec;
  70. struct timeval start_exec;
  71. struct timeval end_exec;
  72. parse_args(argc, argv);
  73. unsigned buffer;
  74. for (buffer = 0; buffer < nbuffers; buffer++)
  75. {
  76. buffers[buffer] = malloc(16*sizeof(float));
  77. starpu_register_vector_data(&data_handles[buffer], 0, (uintptr_t)buffers[buffer], 16, sizeof(float));
  78. }
  79. starpu_init(NULL);
  80. fprintf(stderr, "#tasks : %d\n#buffers : %d\n", ntasks, nbuffers);
  81. /* submit tasks (but don't execute them yet !) */
  82. tasks = malloc(ntasks*sizeof(struct starpu_task));
  83. gettimeofday(&start_submit, NULL);
  84. for (i = 0; i < ntasks; i++)
  85. {
  86. tasks[i].callback_func = NULL;
  87. tasks[i].cl = &dummy_codelet;
  88. tasks[i].cl_arg = NULL;
  89. tasks[i].synchronous = 0;
  90. tasks[i].use_tag = 1;
  91. tasks[i].tag_id = (starpu_tag_t)i;
  92. /* we have 8 buffers at most */
  93. for (buffer = 0; buffer < nbuffers; buffer++)
  94. {
  95. tasks[i].buffers[buffer].handle = data_handles[buffer];
  96. tasks[i].buffers[buffer].mode = STARPU_RW;
  97. }
  98. }
  99. gettimeofday(&start_submit, NULL);
  100. for (i = 1; i < ntasks; i++)
  101. {
  102. starpu_tag_declare_deps((starpu_tag_t)i, 1, (starpu_tag_t)(i-1));
  103. starpu_submit_task(&tasks[i]);
  104. }
  105. /* submit the first task */
  106. starpu_submit_task(&tasks[0]);
  107. gettimeofday(&end_submit, NULL);
  108. /* wait for the execution of the tasks */
  109. gettimeofday(&start_exec, NULL);
  110. starpu_tag_wait((starpu_tag_t)(ntasks - 1));
  111. gettimeofday(&end_exec, NULL);
  112. timing_submit = (double)((end_submit.tv_sec - start_submit.tv_sec)*1000000 + (end_submit.tv_usec - start_submit.tv_usec));
  113. timing_exec = (double)((end_exec.tv_sec - start_exec.tv_sec)*1000000 + (end_exec.tv_usec - start_exec.tv_usec));
  114. fprintf(stderr, "Total submit: %lf secs\n", timing_submit/1000000);
  115. fprintf(stderr, "Per task submit: %lf usecs\n", timing_submit/ntasks);
  116. fprintf(stderr, "\n");
  117. fprintf(stderr, "Total execution: %lf secs\n", timing_exec/1000000);
  118. fprintf(stderr, "Per task execution: %lf usecs\n", timing_exec/ntasks);
  119. fprintf(stderr, "\n");
  120. fprintf(stderr, "Total: %lf secs\n", (timing_submit+timing_exec)/1000000);
  121. fprintf(stderr, "Per task: %lf usecs\n", (timing_submit+timing_exec)/ntasks);
  122. starpu_shutdown();
  123. return 0;
  124. }