readonly.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU 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. * StarPU 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. #include "../helper.h"
  18. /*
  19. * Try accessing a variable in read-only mode
  20. */
  21. #ifdef STARPU_USE_OPENCL
  22. static void codelet(void *descr[], void *_args)
  23. {
  24. (void)descr;
  25. (void)_args;
  26. FPRINTF(stderr, "codelet\n");
  27. }
  28. #endif
  29. static struct starpu_codelet cl =
  30. {
  31. #ifdef STARPU_USE_OPENCL
  32. .opencl_funcs = {codelet},
  33. #endif
  34. .nbuffers = 1,
  35. .modes = {STARPU_R}
  36. };
  37. int main(void)
  38. {
  39. int ret;
  40. int var = 42;
  41. starpu_data_handle_t handle;
  42. ret = starpu_init(NULL);
  43. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  44. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  45. int copy = starpu_asynchronous_copy_disabled();
  46. FPRINTF(stderr, "copy %d\n", copy);
  47. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&var, sizeof(var));
  48. ret = starpu_task_insert(&cl,
  49. STARPU_R, handle,
  50. 0);
  51. if (ret == -ENODEV) goto enodev;
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  53. starpu_task_wait_for_all();
  54. starpu_data_unregister(handle);
  55. starpu_shutdown();
  56. return 0;
  57. enodev:
  58. starpu_data_unregister(handle);
  59. starpu_shutdown();
  60. /* yes, we do not perform the computation but we did detect that no one
  61. * could perform the kernel, so this is not an error from StarPU */
  62. return STARPU_TEST_SKIPPED;
  63. }