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