cl_enqueuemapbuffer.c 2.1 KB

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