profiling.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 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 <starpu.h>
  17. #include <starpu_profiling.h>
  18. #include <assert.h>
  19. static unsigned niter = 500;
  20. void sleep_codelet(__attribute__ ((unused)) void *descr[],
  21. __attribute__ ((unused)) void *_args)
  22. {
  23. usleep(1000);
  24. }
  25. int main(int argc, char **argv)
  26. {
  27. if (argc == 2)
  28. niter = atoi(argv[1]);
  29. starpu_init(NULL);
  30. /* Enable profiling */
  31. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  32. starpu_codelet cl =
  33. {
  34. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  35. .cpu_func = sleep_codelet,
  36. .cuda_func = sleep_codelet,
  37. .opencl_func = sleep_codelet,
  38. .nbuffers = 0
  39. };
  40. struct starpu_task **tasks = malloc(niter*sizeof(struct starpu_task *));
  41. assert(tasks);
  42. unsigned i;
  43. for (i = 0; i < niter; i++)
  44. {
  45. struct starpu_task *task = starpu_task_create();
  46. task->cl = &cl;
  47. /* We will destroy the task structure by hand so that we can
  48. * query the profiling info before the task is destroyed. */
  49. task->destroy = 0;
  50. tasks[i] = task;
  51. int ret = starpu_task_submit(task);
  52. if (STARPU_UNLIKELY(ret == -ENODEV))
  53. {
  54. fprintf(stderr, "No worker may execute this task\n");
  55. exit(0);
  56. }
  57. }
  58. starpu_task_wait_for_all();
  59. int64_t delay_sum = 0;
  60. int64_t length_sum = 0;
  61. for (i = 0; i < niter; i++)
  62. {
  63. struct starpu_task *task = tasks[i];
  64. struct starpu_task_profiling_info *info = task->profiling_info;
  65. /* How much time did it take before the task started ? */
  66. int64_t delay = (info->start_time - info->submit_time);
  67. delay_sum += delay;
  68. /* How long was the task execution ? */
  69. int64_t length = (info->end_time - info->start_time);
  70. length_sum += length;
  71. /* We don't need the task structure anymore */
  72. starpu_task_destroy(task);
  73. }
  74. free(tasks);
  75. fprintf(stderr, "Avg. delay : %2.2f us\n", ((double)delay_sum)/niter);
  76. fprintf(stderr, "Avg. length : %2.2f us\n", ((double)length_sum)/niter);
  77. /* Display the occupancy of all workers during the test */
  78. int worker;
  79. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  80. {
  81. struct starpu_worker_profiling_info worker_info;
  82. starpu_worker_get_profiling_info(worker, &worker_info);
  83. char workername[128];
  84. starpu_worker_get_name(worker, workername, 128);
  85. fprintf(stderr, "Worker %s:\n", workername);
  86. fprintf(stderr, "\ttotal time : %ld us\n", worker_info.total_time);
  87. fprintf(stderr, "\texec time : %ld us\n", worker_info.executing_time);
  88. float overhead = 100.0 - ((100.0*worker_info.executing_time)/worker_info.total_time);
  89. fprintf(stderr, "\toverhead : %.2f %%\n", overhead);
  90. }
  91. starpu_shutdown();
  92. return 0;
  93. }