starpu_task_wait_for_all.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 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 <starpu.h>
  18. #include <sys/time.h>
  19. #include <pthread.h>
  20. #include <stdio.h>
  21. #include <unistd.h>
  22. #include "../helper.h"
  23. static unsigned ntasks = 65536;
  24. static void dummy_func(void *descr[], void *arg)
  25. {
  26. }
  27. static struct starpu_codelet dummy_codelet =
  28. {
  29. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL|STARPU_GORDON,
  30. .cpu_funcs = {dummy_func, NULL},
  31. .cuda_funcs = {dummy_func, NULL},
  32. .opencl_funcs = {dummy_func, NULL},
  33. #ifdef STARPU_USE_GORDON
  34. .gordon_func = 0, /* this will be defined later */
  35. #endif
  36. .model = NULL,
  37. .nbuffers = 0
  38. };
  39. static void init_gordon_kernel(void)
  40. {
  41. #ifdef STARPU_USE_GORDON
  42. unsigned elf_id =
  43. gordon_register_elf_plugin("./microbenchs/null_kernel_gordon.spuelf");
  44. gordon_load_plugin_on_all_spu(elf_id);
  45. unsigned gordon_null_kernel =
  46. gordon_register_kernel(elf_id, "empty_kernel");
  47. gordon_load_kernel_on_all_spu(gordon_null_kernel);
  48. dummy_codelet.gordon_func = gordon_null_kernel;
  49. #endif
  50. }
  51. static int inject_one_task(void)
  52. {
  53. struct starpu_task *task = starpu_task_create();
  54. task->cl = &dummy_codelet;
  55. task->cl_arg = NULL;
  56. task->callback_func = NULL;
  57. task->callback_arg = NULL;
  58. int ret = starpu_task_submit(task);
  59. return ret;
  60. }
  61. static void usage(char **argv)
  62. {
  63. FPRINTF(stderr, "%s [-i ntasks] [-p sched_policy] [-h]\n", argv[0]);
  64. exit(-1);
  65. }
  66. static void parse_args(int argc, char **argv, struct starpu_conf *conf)
  67. {
  68. int c;
  69. while ((c = getopt(argc, argv, "i:p:h")) != -1)
  70. switch(c)
  71. {
  72. case 'i':
  73. ntasks = atoi(optarg);
  74. break;
  75. case 'p':
  76. conf->sched_policy_name = optarg;
  77. break;
  78. case 'h':
  79. usage(argv);
  80. break;
  81. }
  82. }
  83. int main(int argc, char **argv)
  84. {
  85. unsigned i;
  86. double timing;
  87. struct timeval start;
  88. struct timeval end;
  89. int ret;
  90. struct starpu_conf conf;
  91. starpu_conf_init(&conf);
  92. parse_args(argc, argv, &conf);
  93. #ifdef STARPU_SLOW_MACHINE
  94. ntasks /= 10;
  95. #endif
  96. ret = starpu_init(&conf);
  97. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  98. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  99. init_gordon_kernel();
  100. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  101. gettimeofday(&start, NULL);
  102. for (i = 0; i < ntasks; i++)
  103. {
  104. ret = inject_one_task();
  105. if (ret == -ENODEV) goto enodev;
  106. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  107. }
  108. ret = starpu_task_wait_for_all();
  109. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  110. gettimeofday(&end, NULL);
  111. timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  112. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  113. FPRINTF(stderr, "Per task: %f usecs\n", timing/ntasks);
  114. starpu_shutdown();
  115. return EXIT_SUCCESS;
  116. enodev:
  117. fprintf(stderr, "WARNING: No one can execute this task\n");
  118. /* yes, we do not perform the computation but we did detect that no one
  119. * could perform the kernel, so this is not an error from StarPU */
  120. starpu_shutdown();
  121. return STARPU_TEST_SKIPPED;
  122. }