invalid_blocking_calls.c 2.9 KB

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