readonly.c 2.0 KB

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