invalid_tasks.c 2.2 KB

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