invalidate_pending_requests.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2020 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 invalidating a variable which is pending a request
  20. */
  21. #define SIZE (100<<20)
  22. int main(void)
  23. {
  24. int ret;
  25. char *var = NULL;
  26. starpu_data_handle_t handle;
  27. ret = starpu_init(NULL);
  28. if (ret == -ENODEV) goto skip;
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  30. if (starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) == 0 &&
  31. starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER) == 0)
  32. goto enodev;
  33. var = malloc(SIZE);
  34. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)var, SIZE);
  35. /* Let a request fly */
  36. starpu_fxt_trace_user_event_string("requesting");
  37. starpu_data_fetch_on_node(handle, 1, 1);
  38. starpu_fxt_trace_user_event_string("requested");
  39. /* But suddenly invalidate the data while it's on the fly! */
  40. starpu_data_invalidate_submit(handle);
  41. starpu_fxt_trace_user_event_string("invalidated");
  42. starpu_data_unregister(handle);
  43. free(var);
  44. starpu_shutdown();
  45. return 0;
  46. enodev:
  47. starpu_shutdown();
  48. skip:
  49. return STARPU_TEST_SKIPPED;
  50. }