invalid_tasks.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. #include <common/config.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(int argc, char **argv)
  26. {
  27. return STARPU_TEST_SKIPPED;
  28. }
  29. #else
  30. void dummy_func(void *descr[], void *arg)
  31. {
  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(int argc, char **argv)
  41. {
  42. int ret;
  43. /* We force StarPU to use 1 CPU only */
  44. unsetenv("STARPU_NCUDA");
  45. unsetenv("STARPU_NOPENCL");
  46. unsetenv("STARPU_NCPUS");
  47. struct starpu_conf conf;
  48. starpu_conf_init(&conf);
  49. conf.ncpus = 1;
  50. conf.nopencl = 0;
  51. conf.ncuda = 0;
  52. ret = starpu_init(&conf);
  53. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  55. struct starpu_task *task = starpu_task_create();
  56. task->cl = &gpu_only_cl;
  57. /* Only a GPU device could execute that task ! */
  58. ret = starpu_task_submit(task);
  59. STARPU_ASSERT(ret == -ENODEV);
  60. task->destroy = 0;
  61. starpu_task_destroy(task);
  62. struct starpu_task *task_specific = starpu_task_create();
  63. task_specific->cl = &gpu_only_cl;
  64. task_specific->execute_on_a_specific_worker = 1;
  65. task_specific->workerid = 0;
  66. /* Only a CUDA device could execute that task ! */
  67. ret = starpu_task_submit(task_specific);
  68. STARPU_ASSERT(ret == -ENODEV);
  69. task_specific->destroy = 0;
  70. starpu_task_destroy(task_specific);
  71. starpu_shutdown();
  72. return EXIT_SUCCESS;
  73. }
  74. #endif