starpu_worker_exists.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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
  54. 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. }