starpu_worker_exists.c 2.2 KB

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