cl_enqueuemapbuffer.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. static void mapbuffer_callback(void *args) {
  18. command_map_buffer cmd = (command_map_buffer)args;
  19. starpu_tag_notify_from_apps(cmd->event->id);
  20. cmd->event->status = CL_COMPLETE;
  21. }
  22. static void mapbuffer_task(void *args) {
  23. command_map_buffer cmd = (command_map_buffer)args;
  24. enum starpu_access_mode mode = (cmd->map_flags == CL_MAP_READ ? STARPU_R : STARPU_RW);
  25. starpu_data_acquire_cb(cmd->buffer->handle, mode, mapbuffer_callback, cmd);
  26. }
  27. cl_int command_map_buffer_submit(command_map_buffer cmd) {
  28. static struct starpu_codelet codelet = {
  29. .name = "SOCL_MAP_BUFFER"
  30. };
  31. cpu_task_submit(cmd, mapbuffer_task, cmd, 0, &codelet, 0, NULL);
  32. return CL_SUCCESS;
  33. }
  34. CL_API_ENTRY void * CL_API_CALL
  35. soclEnqueueMapBuffer(cl_command_queue cq,
  36. cl_mem buffer,
  37. cl_bool blocking,
  38. cl_map_flags map_flags,
  39. size_t offset,
  40. size_t cb,
  41. cl_uint num_events,
  42. const cl_event * events,
  43. cl_event * event,
  44. cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
  45. {
  46. cl_event ev = event_create();
  47. command_map_buffer cmd = command_map_buffer_create(buffer, map_flags, offset, cb, ev);
  48. command_queue_enqueue(cq, cmd, num_events, events);
  49. if (errcode_ret != NULL)
  50. *errcode_ret = CL_SUCCESS;
  51. RETURN_CUSTOM_EVENT(ev,event);
  52. MAY_BLOCK_CUSTOM(blocking,ev);
  53. return (void*)(starpu_variable_get_local_ptr(buffer->handle) + offset);
  54. }