invalid_tasks.c 2.3 KB

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