invalid_blocking_calls.c 2.8 KB

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