cl_createcommandqueue.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Inria
  4. * Copyright (C) 2012,2014,2017 CNRS
  5. * Copyright (C) 2010-2011,2013, 2018 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 release_callback_command_queue(void * e)
  20. {
  21. cl_command_queue cq = (cl_command_queue)e;
  22. //Disable StarPU profiling if necessary
  23. if (cq->properties & CL_QUEUE_PROFILING_ENABLE)
  24. {
  25. profiling_queue_count -= 1;
  26. if (profiling_queue_count == 0)
  27. starpu_profiling_status_set(STARPU_PROFILING_DISABLE);
  28. }
  29. /* Release references */
  30. gc_entity_unstore(&cq->context);
  31. /* Destruct object */
  32. STARPU_PTHREAD_MUTEX_DESTROY(&cq->mutex);
  33. }
  34. CL_API_SUFFIX__VERSION_1_0
  35. CL_API_ENTRY cl_command_queue CL_API_CALL
  36. soclCreateCommandQueue(cl_context context,
  37. cl_device_id device,
  38. cl_command_queue_properties properties,
  39. cl_int * errcode_ret)
  40. {
  41. cl_command_queue cq;
  42. cq = (cl_command_queue)gc_entity_alloc(sizeof(struct _cl_command_queue),
  43. release_callback_command_queue, "command_queue");
  44. if (cq == NULL)
  45. {
  46. if (errcode_ret != NULL)
  47. *errcode_ret = CL_OUT_OF_HOST_MEMORY;
  48. return NULL;
  49. }
  50. cq->properties = properties;
  51. gc_entity_store(&cq->context, context);
  52. char * fd = getenv("SOCL_FORCE_DYNAMIC");
  53. int force_dynamic = fd == NULL ? 0 : atoi(fd);
  54. cq->device = force_dynamic ? NULL : device;
  55. #ifdef DEBUG
  56. static int id = 0;
  57. cq->id = id++;
  58. #endif
  59. //Enable StarPU profiling if necessary
  60. if (properties & CL_QUEUE_PROFILING_ENABLE)
  61. {
  62. if (profiling_queue_count == 0)
  63. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  64. profiling_queue_count += 1;
  65. }
  66. cq->commands = NULL;
  67. cq->barrier = NULL;
  68. STARPU_PTHREAD_MUTEX_INIT(&cq->mutex, NULL);
  69. if (errcode_ret != NULL)
  70. *errcode_ret = CL_SUCCESS;
  71. return cq;
  72. }