invalid_blocking_calls.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (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_sync_data_with_mem(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,
  35. .cpu_func = wrong_func,
  36. .cuda_func = wrong_func,
  37. .model = NULL,
  38. .nbuffers = 0
  39. };
  40. static void wrong_callback(void *arg)
  41. {
  42. int ret;
  43. ret = starpu_sync_data_with_mem(handle, STARPU_RW);
  44. if (ret != -EDEADLK)
  45. exit(-1);
  46. ret = starpu_tag_wait(TAG);
  47. if (ret != -EDEADLK)
  48. exit(-1);
  49. }
  50. int main(int argc, char **argv)
  51. {
  52. int ret;
  53. starpu_init(NULL);
  54. /* register a piece of data */
  55. starpu_register_vector_data(&handle, 0, (uintptr_t)&data,
  56. 1, sizeof(unsigned));
  57. struct starpu_task *task = starpu_task_create();
  58. task->cl = &wrong_codelet;
  59. task->buffers[0].handle = handle;
  60. task->buffers[0].mode = STARPU_RW;
  61. task->use_tag = 1;
  62. task->tag_id = TAG;
  63. task->callback_func = wrong_callback;
  64. ret = starpu_submit_task(task);
  65. if (ret == -ENODEV)
  66. goto enodev;
  67. ret = starpu_tag_wait(TAG);
  68. if (ret)
  69. return -1;
  70. /* This call is valid as it is done by the application outside a
  71. * callback */
  72. ret = starpu_sync_data_with_mem(handle, STARPU_RW);
  73. if (ret)
  74. return -1;
  75. starpu_release_data_from_mem(handle);
  76. starpu_shutdown();
  77. return 0;
  78. enodev:
  79. fprintf(stderr, "WARNING: No one can execute this task\n");
  80. /* yes, we do not perform the computation but we did detect that no one
  81. * could perform the kernel, so this is not an error from StarPU */
  82. return 0;
  83. }