execute_schedule.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2013 Inria
  4. * Copyright (C) 2012-2015,2017 CNRS
  5. * Copyright (C) 2013-2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. #include <common/thread.h>
  25. /*
  26. * Test binding tasks on specific workers and in a specific order
  27. */
  28. #ifdef STARPU_QUICK_CHECK
  29. #define K 2
  30. #else
  31. #define K 16
  32. #endif
  33. #define N 64
  34. static unsigned current = 1;
  35. void codelet(void *descr[], void *_args)
  36. {
  37. (void)descr;
  38. uintptr_t me = (uintptr_t) _args;
  39. STARPU_ASSERT(current == me);
  40. current++;
  41. }
  42. static double cost_function(struct starpu_task *task, unsigned nimpl)
  43. {
  44. (void) task;
  45. (void) nimpl;
  46. return 1000;
  47. }
  48. static struct starpu_perfmodel model =
  49. {
  50. .type = STARPU_COMMON,
  51. .cost_function = cost_function,
  52. .symbol = "cost"
  53. };
  54. static struct starpu_codelet cl =
  55. {
  56. .cpu_funcs = {codelet},
  57. .cuda_funcs = {codelet},
  58. .opencl_funcs = {codelet},
  59. .nbuffers = 1,
  60. .modes = {STARPU_R},
  61. .model = &model,
  62. };
  63. int main(int argc, char **argv)
  64. {
  65. int ret;
  66. struct starpu_task *dep_task[N];
  67. int *t[N];
  68. starpu_data_handle_t h[N];
  69. unsigned n, i, k;
  70. ret = starpu_initialize(NULL, &argc, &argv);
  71. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  73. for (n = 0; n < N; n++)
  74. {
  75. t[n] = malloc((1<<20) * sizeof(*(t[n])));
  76. starpu_variable_data_register(&h[n], STARPU_MAIN_RAM, (uintptr_t) t[n], (1<<20) * sizeof(*(t[n])));
  77. }
  78. for (k = 0; k < K; k++)
  79. {
  80. for (n = 0; n < N; n++)
  81. {
  82. struct starpu_task *task;
  83. dep_task[n] = starpu_task_create();
  84. dep_task[n]->cl = NULL;
  85. task = starpu_task_create();
  86. task->cl = &cl;
  87. task->execute_on_a_specific_worker = 1;
  88. task->workerid = 0;
  89. /* We request for running the tasks in the opposite order of the submission order */
  90. task->workerorder = k*N + (N-n);
  91. task->cl_arg = (void*) (uintptr_t) (k*N + (N-n));
  92. task->handles[0] = h[n];
  93. starpu_task_declare_deps_array(task, 1, &dep_task[n]);
  94. ret = starpu_task_submit(task);
  95. if (ret == -ENODEV) goto enodev;
  96. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  97. }
  98. for (n = 0; n < N; n++)
  99. {
  100. i = (int)starpu_drand48()%(N-n);
  101. ret = starpu_task_submit(dep_task[i]);
  102. memmove(&dep_task[i], &dep_task[i+1], (N-i-1)*sizeof(dep_task[i]));
  103. if (ret == -ENODEV) goto enodev;
  104. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  105. }
  106. }
  107. starpu_task_wait_for_all();
  108. for (n = 0; n < N; n++)
  109. {
  110. starpu_data_unregister(h[n]);
  111. free(t[n]);
  112. }
  113. starpu_shutdown();
  114. return EXIT_SUCCESS;
  115. enodev:
  116. starpu_shutdown();
  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. return STARPU_TEST_SKIPPED;
  121. }