event.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011 University of Bordeaux
  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 "socl.h"
  17. #include "event.h"
  18. #include "gc.h"
  19. static void release_callback_event(void * e);
  20. int event_unique_id() {
  21. static int id = 1;
  22. return __sync_fetch_and_add(&id,1);
  23. }
  24. /**
  25. * Create a new event
  26. *
  27. * Events have one-to-one relation with tag. Tag number is event ID
  28. */
  29. cl_event event_create(void) {
  30. cl_event ev;
  31. ev = gc_entity_alloc(sizeof(struct _cl_event), release_callback_event, "event");
  32. ev->id = event_unique_id();
  33. ev->status = CL_SUBMITTED;
  34. ev->command = NULL;
  35. ev->prof_queued = 0L;
  36. ev->prof_submit = 0L;
  37. ev->prof_start = 0L;
  38. ev->prof_end = 0L;
  39. ev->cq = NULL;
  40. return ev;
  41. }
  42. void event_complete(cl_event ev) {
  43. ev->status = CL_COMPLETE;
  44. ev->prof_end = _socl_nanotime();
  45. /* Trigger the tag associated to the command event */
  46. DEBUG_MSG("Trigger event %d\n", ev->id);
  47. starpu_tag_notify_from_apps(ev->id);
  48. }
  49. static void release_callback_event(void * e) {
  50. cl_event event = (cl_event)e;
  51. gc_entity_unstore(&event->cq);
  52. /* Destruct object */
  53. //FIXME
  54. //starpu_tag_remove(event->id);
  55. }