cl_enqueuemapbuffer.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012-2013,2017 CNRS
  5. * Copyright (C) 2010-2011,2013 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include "socl.h"
  19. static void mapbuffer_task(void *args)
  20. {
  21. command_map_buffer cmd = (command_map_buffer)args;
  22. cl_event ev = command_event_get(cmd);
  23. ev->prof_start = _socl_nanotime();
  24. gc_entity_release(ev);
  25. enum starpu_data_access_mode mode = (cmd->map_flags == CL_MAP_READ ? STARPU_R : STARPU_RW);
  26. starpu_data_acquire_cb(cmd->buffer->handle, mode, command_completed_task_callback, cmd);
  27. }
  28. static struct starpu_codelet codelet_mapbuffer =
  29. {
  30. .name = "SOCL_MAP_BUFFER"
  31. };
  32. cl_int command_map_buffer_submit(command_map_buffer cmd)
  33. {
  34. gc_entity_retain(cmd);
  35. cpu_task_submit(cmd, mapbuffer_task, cmd, 0, 0, &codelet_mapbuffer, 0, NULL);
  36. return CL_SUCCESS;
  37. }
  38. CL_API_ENTRY void * CL_API_CALL
  39. soclEnqueueMapBuffer(cl_command_queue cq,
  40. cl_mem buffer,
  41. cl_bool blocking,
  42. cl_map_flags map_flags,
  43. size_t offset,
  44. size_t cb,
  45. cl_uint num_events,
  46. const cl_event * events,
  47. cl_event * event,
  48. cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
  49. {
  50. command_map_buffer cmd = command_map_buffer_create(buffer, map_flags, offset, cb);
  51. cl_event ev = command_event_get(cmd);
  52. command_queue_enqueue(cq, cmd, num_events, events);
  53. if (errcode_ret != NULL)
  54. *errcode_ret = CL_SUCCESS;
  55. MAY_BLOCK_THEN_RETURN_EVENT(ev,blocking,event);
  56. return (void*)(starpu_variable_get_local_ptr(buffer->handle) + offset);
  57. }