readonly.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2010-2013,2015,2017 CNRS
  5. * Copyright (C) 2010,2013,2014,2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Try accessing a variable in read-only mode
  22. */
  23. #ifdef STARPU_USE_OPENCL
  24. static void codelet(void *descr[], void *_args)
  25. {
  26. (void)descr;
  27. (void)_args;
  28. FPRINTF(stderr, "codelet\n");
  29. }
  30. #endif
  31. static struct starpu_codelet cl =
  32. {
  33. #ifdef STARPU_USE_OPENCL
  34. .opencl_funcs = {codelet},
  35. #endif
  36. .nbuffers = 1,
  37. .modes = {STARPU_R}
  38. };
  39. int main(void)
  40. {
  41. int ret;
  42. int var = 42;
  43. starpu_data_handle_t handle;
  44. ret = starpu_init(NULL);
  45. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  47. int copy = starpu_asynchronous_copy_disabled();
  48. FPRINTF(stderr, "copy %d\n", copy);
  49. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  50. ret = starpu_task_insert(&cl,
  51. STARPU_R, handle,
  52. 0);
  53. if (ret == -ENODEV) goto enodev;
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  55. starpu_task_wait_for_all();
  56. starpu_data_unregister(handle);
  57. starpu_shutdown();
  58. return 0;
  59. enodev:
  60. starpu_data_unregister(handle);
  61. starpu_shutdown();
  62. /* yes, we do not perform the computation but we did detect that no one
  63. * could perform the kernel, so this is not an error from StarPU */
  64. fprintf(stderr, "WARNING: No one can execute this task\n");
  65. return STARPU_TEST_SKIPPED;
  66. }