invalid_blocking_calls.c 2.5 KB

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