invalid_tasks.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 "../helper.h"
  18. /*
  19. * Check that we detect that with only a CPU we can't submit a GPU-only task
  20. */
  21. #if !defined(STARPU_USE_CPU)
  22. #warning no cpu are available. Skipping test
  23. int main(void)
  24. {
  25. return STARPU_TEST_SKIPPED;
  26. }
  27. #else
  28. void dummy_func(void *descr[], void *arg)
  29. {
  30. (void)descr;
  31. (void)arg;
  32. }
  33. static struct starpu_codelet gpu_only_cl =
  34. {
  35. .cuda_funcs = {dummy_func},
  36. .opencl_funcs = {dummy_func},
  37. .model = NULL,
  38. .nbuffers = 0
  39. };
  40. int main(void)
  41. {
  42. int ret;
  43. /* We force StarPU to use 1 CPU only */
  44. struct starpu_conf conf;
  45. starpu_conf_init(&conf);
  46. conf.precedence_over_environment_variables = 1;
  47. starpu_conf_noworker(&conf);
  48. conf.ncpus = 1;
  49. conf.nmpi_ms = -1;
  50. ret = starpu_init(&conf);
  51. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  53. struct starpu_task *task = starpu_task_create();
  54. task->cl = &gpu_only_cl;
  55. /* Only a GPU device could execute that task ! */
  56. ret = starpu_task_submit(task);
  57. STARPU_ASSERT(ret == -ENODEV);
  58. task->destroy = 0;
  59. starpu_task_destroy(task);
  60. struct starpu_task *task_specific = starpu_task_create();
  61. task_specific->cl = &gpu_only_cl;
  62. task_specific->execute_on_a_specific_worker = 1;
  63. task_specific->workerid = 0;
  64. /* Only a CUDA device could execute that task ! */
  65. ret = starpu_task_submit(task_specific);
  66. STARPU_ASSERT(ret == -ENODEV);
  67. task_specific->destroy = 0;
  68. starpu_task_destroy(task_specific);
  69. starpu_shutdown();
  70. return EXIT_SUCCESS;
  71. }
  72. #endif