starpu_worker_exists.c 2.2 KB

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