starpu_worker_exists.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012-2015,2017 CNRS
  5. * Copyright (C) 2013-2014,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 <starpu.h>
  19. #include "core/workers.h"
  20. #include "../helper.h"
  21. /*
  22. * Test that _starpu_worker_exists works appropriately
  23. */
  24. static int can_always_execute(unsigned workerid,
  25. struct starpu_task *task,
  26. unsigned nimpl)
  27. {
  28. (void) workerid;
  29. (void) task;
  30. (void) nimpl;
  31. return 1;
  32. }
  33. static int can_never_execute(unsigned workerid,
  34. struct starpu_task *task,
  35. unsigned nimpl)
  36. {
  37. (void) workerid;
  38. (void) task;
  39. (void) nimpl;
  40. return 0;
  41. }
  42. void fake(void *buffers[], void *args)
  43. {
  44. (void) buffers;
  45. (void) args;
  46. }
  47. static struct starpu_codelet cl =
  48. {
  49. .cpu_funcs = { fake},
  50. .cuda_funcs = { fake},
  51. .opencl_funcs = { fake},
  52. .cpu_funcs_name = { "fake"},
  53. .nbuffers = 0
  54. };
  55. int main(int argc, char **argv)
  56. {
  57. int ret;
  58. struct starpu_task *task;
  59. ret = starpu_initialize(NULL, &argc, &argv);
  60. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  61. task = starpu_task_create();
  62. task->cl = &cl;
  63. task->destroy = 0;
  64. task->sched_ctx = 0;
  65. cl.can_execute = NULL;
  66. ret = _starpu_worker_exists(task);
  67. if (!ret)
  68. {
  69. FPRINTF(stderr, "failure with can_execute=NULL\n");
  70. return EXIT_FAILURE;
  71. }
  72. cl.can_execute = can_always_execute;
  73. ret = _starpu_worker_exists(task);
  74. if (!ret)
  75. {
  76. FPRINTF(stderr, "failure with can_always_execute\n");
  77. return EXIT_FAILURE;
  78. }
  79. cl.can_execute = can_never_execute;
  80. ret = _starpu_worker_exists(task);
  81. if (ret)
  82. {
  83. FPRINTF(stderr, "failure with can_never_execute\n");
  84. return EXIT_FAILURE;
  85. }
  86. starpu_task_destroy(task);
  87. starpu_shutdown();
  88. return EXIT_SUCCESS;
  89. }