readonly.c 2.1 KB

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