execute_schedule.c 3.0 KB

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