sync_tasks_overhead.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2014,2016,2020 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 synchronous tasks
  23. */
  24. starpu_data_handle_t data_handles[8];
  25. float *buffers[8];
  26. #ifdef STARPU_QUICK_CHECK
  27. static unsigned ntasks = 128;
  28. #else
  29. static unsigned ntasks = 65536;
  30. #endif
  31. static unsigned nbuffers = 0;
  32. #define BUFFERSIZE 16
  33. void dummy_func(void *descr[], void *arg)
  34. {
  35. (void)descr;
  36. (void)arg;
  37. }
  38. static struct starpu_codelet dummy_codelet =
  39. {
  40. .cpu_funcs = {dummy_func},
  41. .cuda_funcs = {dummy_func},
  42. .opencl_funcs = {dummy_func},
  43. .cpu_funcs_name = {"dummy_func"},
  44. .model = NULL,
  45. .nbuffers = 0,
  46. .modes = {STARPU_RW, STARPU_RW, STARPU_RW, STARPU_RW, STARPU_RW, STARPU_RW, STARPU_RW, STARPU_RW}
  47. };
  48. static int inject_one_task(void)
  49. {
  50. int ret;
  51. struct starpu_task *task = starpu_task_create();
  52. task->cl = &dummy_codelet;
  53. task->cl_arg = NULL;
  54. task->callback_func = NULL;
  55. task->synchronous = 1;
  56. ret = starpu_task_submit(task);
  57. return ret;
  58. }
  59. static void usage(char **argv)
  60. {
  61. fprintf(stderr, "Usage: %s [-i ntasks] [-p sched_policy] [-b nbuffers] [-h]\n", argv[0]);
  62. exit(EXIT_FAILURE);
  63. }
  64. static void parse_args(int argc, char **argv, struct starpu_conf *conf)
  65. {
  66. int c;
  67. while ((c = getopt(argc, argv, "i:b:p:h")) != -1)
  68. switch(c)
  69. {
  70. case 'i':
  71. ntasks = atoi(optarg);
  72. break;
  73. case 'b':
  74. nbuffers = atoi(optarg);
  75. dummy_codelet.nbuffers = nbuffers;
  76. break;
  77. case 'p':
  78. conf->sched_policy_name = optarg;
  79. break;
  80. case 'h':
  81. usage(argv);
  82. break;
  83. }
  84. }
  85. int main(int argc, char **argv)
  86. {
  87. int ret;
  88. unsigned i;
  89. double timing;
  90. double start;
  91. double end;
  92. struct starpu_conf conf;
  93. starpu_conf_init(&conf);
  94. conf.ncpus = 2;
  95. parse_args(argc, argv, &conf);
  96. ret = starpu_initialize(&conf, &argc, &argv);
  97. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  98. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  99. unsigned buffer;
  100. for (buffer = 0; buffer < nbuffers; buffer++)
  101. {
  102. starpu_malloc((void**)&buffers[buffer], BUFFERSIZE*sizeof(float));
  103. starpu_vector_data_register(&data_handles[buffer], STARPU_MAIN_RAM, (uintptr_t)buffers[buffer], BUFFERSIZE, sizeof(float));
  104. }
  105. fprintf(stderr, "#tasks : %u\n#buffers : %u\n", ntasks, nbuffers);
  106. start = starpu_timing_now();
  107. for (i = 0; i < ntasks; i++)
  108. {
  109. struct starpu_task *task = starpu_task_create();
  110. task->cl = &dummy_codelet;
  111. task->synchronous = 1;
  112. /* we have 8 buffers at most */
  113. for (buffer = 0; buffer < nbuffers; buffer++)
  114. {
  115. task->handles[buffer] = data_handles[buffer];
  116. }
  117. ret = starpu_task_submit(task);
  118. if (ret == -ENODEV) goto enodev;
  119. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  120. }
  121. end = starpu_timing_now();
  122. timing = end - start;
  123. fprintf(stderr, "Total: %f secs\n", timing/1000000);
  124. fprintf(stderr, "Per task: %f usecs\n", timing/ntasks);
  125. {
  126. char *output_dir = getenv("STARPU_BENCH_DIR");
  127. char *bench_id = getenv("STARPU_BENCH_ID");
  128. if (output_dir && bench_id)
  129. {
  130. char number[1+sizeof(nbuffers)*3+1];
  131. const char *numberp;
  132. char file[1024];
  133. FILE *f;
  134. if (nbuffers)
  135. {
  136. snprintf(number, sizeof(number), "_%u", nbuffers);
  137. numberp = number;
  138. }
  139. else
  140. numberp = "";
  141. snprintf(file, sizeof(file), "%s/sync_tasks_overhead_total%s.dat", output_dir, numberp);
  142. f = fopen(file, "a");
  143. fprintf(f, "%s\t%f\n", bench_id, timing/1000000);
  144. fclose(f);
  145. snprintf(file, sizeof(file), "%s/sync_tasks_overhead_per_task%s.dat", output_dir, numberp);
  146. f = fopen(file, "a");
  147. fprintf(f, "%s\t%f\n", bench_id, timing/ntasks);
  148. fclose(f);
  149. }
  150. }
  151. for (buffer = 0; buffer < nbuffers; buffer++)
  152. {
  153. starpu_data_unregister(data_handles[buffer]);
  154. starpu_free((void*)buffers[buffer]);
  155. }
  156. starpu_shutdown();
  157. return EXIT_SUCCESS;
  158. enodev:
  159. fprintf(stderr, "WARNING: No one can execute this task\n");
  160. /* yes, we do not perform the computation but we did detect that no one
  161. * could perform the kernel, so this is not an error from StarPU */
  162. starpu_shutdown();
  163. return STARPU_TEST_SKIPPED;
  164. }