invalid_blocking_calls.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. #define TAG 0x42
  18. static starpu_data_handle handle;
  19. static unsigned data = 42;
  20. static void wrong_func(void *descr[], void *arg)
  21. {
  22. int ret;
  23. /* try to fetch data in the RAM while we are in a codelet, such a
  24. * blocking call is forbidden */
  25. ret = starpu_data_acquire(handle, STARPU_RW);
  26. if (ret != -EDEADLK)
  27. exit(-1);
  28. ret = starpu_tag_wait(TAG);
  29. if (ret != -EDEADLK)
  30. exit(-1);
  31. }
  32. static starpu_codelet wrong_codelet =
  33. {
  34. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  35. .cpu_func = wrong_func,
  36. .cuda_func = wrong_func,
  37. .opencl_func = wrong_func,
  38. .model = NULL,
  39. .nbuffers = 0
  40. };
  41. static void wrong_callback(void *arg)
  42. {
  43. int ret;
  44. ret = starpu_data_acquire(handle, STARPU_RW);
  45. if (ret != -EDEADLK)
  46. exit(-1);
  47. ret = starpu_tag_wait(TAG);
  48. if (ret != -EDEADLK)
  49. exit(-1);
  50. }
  51. int main(int argc, char **argv)
  52. {
  53. int ret;
  54. starpu_init(NULL);
  55. /* register a piece of data */
  56. starpu_vector_data_register(&handle, 0, (uintptr_t)&data,
  57. 1, sizeof(unsigned));
  58. struct starpu_task *task = starpu_task_create();
  59. task->cl = &wrong_codelet;
  60. task->buffers[0].handle = handle;
  61. task->buffers[0].mode = STARPU_RW;
  62. task->use_tag = 1;
  63. task->tag_id = TAG;
  64. task->callback_func = wrong_callback;
  65. ret = starpu_task_submit(task);
  66. if (ret == -ENODEV)
  67. goto enodev;
  68. ret = starpu_tag_wait(TAG);
  69. if (ret)
  70. return -1;
  71. /* This call is valid as it is done by the application outside a
  72. * callback */
  73. ret = starpu_data_acquire(handle, STARPU_RW);
  74. if (ret)
  75. return -1;
  76. starpu_data_release(handle);
  77. starpu_shutdown();
  78. return 0;
  79. enodev:
  80. fprintf(stderr, "WARNING: No one can execute this task\n");
  81. /* yes, we do not perform the computation but we did detect that no one
  82. * could perform the kernel, so this is not an error from StarPU */
  83. return 0;
  84. }