execute_schedule.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU 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. * StarPU 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 <stdio.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #include "../helper.h"
  22. #include <common/thread.h>
  23. /*
  24. * Test binding tasks on specific workers and in a specific order
  25. */
  26. #ifdef STARPU_QUICK_CHECK
  27. #define K 2
  28. #else
  29. #define K 16
  30. #endif
  31. #define N 64
  32. static unsigned current = 1;
  33. void codelet(void *descr[], void *_args)
  34. {
  35. (void)descr;
  36. uintptr_t me = (uintptr_t) _args;
  37. STARPU_ASSERT(current == me);
  38. current++;
  39. }
  40. static double cost_function(struct starpu_task *task, unsigned nimpl)
  41. {
  42. (void) task;
  43. (void) nimpl;
  44. return 1000;
  45. }
  46. static struct starpu_perfmodel model =
  47. {
  48. .type = STARPU_COMMON,
  49. .cost_function = cost_function,
  50. .symbol = "cost"
  51. };
  52. static struct starpu_codelet cl =
  53. {
  54. .cpu_funcs = {codelet},
  55. .cuda_funcs = {codelet},
  56. .opencl_funcs = {codelet},
  57. .nbuffers = 1,
  58. .modes = {STARPU_R},
  59. .model = &model,
  60. };
  61. int main(int argc, char **argv)
  62. {
  63. int ret;
  64. struct starpu_task *dep_task[N];
  65. int *t[N];
  66. starpu_data_handle_t h[N];
  67. unsigned n, i, k;
  68. ret = starpu_initialize(NULL, &argc, &argv);
  69. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  71. for (n = 0; n < N; n++)
  72. {
  73. t[n] = malloc((1<<20) * sizeof(*(t[n])));
  74. starpu_variable_data_register(&h[n], STARPU_MAIN_RAM, (uintptr_t) t[n], (1<<20) * sizeof(*(t[n])));
  75. }
  76. for (k = 0; k < K; k++)
  77. {
  78. for (n = 0; n < N; n++)
  79. {
  80. struct starpu_task *task;
  81. dep_task[n] = starpu_task_create();
  82. dep_task[n]->cl = NULL;
  83. task = starpu_task_create();
  84. task->cl = &cl;
  85. task->execute_on_a_specific_worker = 1;
  86. task->workerid = 0;
  87. /* We request for running the tasks in the opposite order of the submission order */
  88. task->workerorder = k*N + (N-n);
  89. task->cl_arg = (void*) (uintptr_t) (k*N + (N-n));
  90. task->handles[0] = h[n];
  91. starpu_task_declare_deps_array(task, 1, &dep_task[n]);
  92. ret = starpu_task_submit(task);
  93. if (ret == -ENODEV) goto enodev;
  94. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  95. }
  96. for (n = 0; n < N; n++)
  97. {
  98. i = (int)starpu_drand48()%(N-n);
  99. ret = starpu_task_submit(dep_task[i]);
  100. memmove(&dep_task[i], &dep_task[i+1], (N-i-1)*sizeof(dep_task[i]));
  101. if (ret == -ENODEV) goto enodev;
  102. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  103. }
  104. }
  105. starpu_task_wait_for_all();
  106. for (n = 0; n < N; n++)
  107. {
  108. starpu_data_unregister(h[n]);
  109. free(t[n]);
  110. }
  111. starpu_shutdown();
  112. return EXIT_SUCCESS;
  113. enodev:
  114. starpu_shutdown();
  115. fprintf(stderr, "WARNING: No one can execute this task\n");
  116. /* yes, we do not perform the computation but we did detect that no one
  117. * could perform the kernel, so this is not an error from StarPU */
  118. return STARPU_TEST_SKIPPED;
  119. }