cl_createcommandqueue.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 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_ENTRY cl_command_queue CL_API_CALL
  35. soclCreateCommandQueue(cl_context context,
  36. cl_device_id device,
  37. cl_command_queue_properties properties,
  38. cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0
  39. {
  40. cl_command_queue cq;
  41. cq = (cl_command_queue)gc_entity_alloc(sizeof(struct _cl_command_queue),
  42. release_callback_command_queue, "command_queue");
  43. if (cq == NULL)
  44. {
  45. if (errcode_ret != NULL)
  46. *errcode_ret = CL_OUT_OF_HOST_MEMORY;
  47. return NULL;
  48. }
  49. cq->properties = properties;
  50. gc_entity_store(&cq->context, context);
  51. char * fd = getenv("SOCL_FORCE_DYNAMIC");
  52. int force_dynamic = fd == NULL ? 0 : atoi(fd);
  53. cq->device = force_dynamic ? NULL : device;
  54. #ifdef DEBUG
  55. static int id = 0;
  56. cq->id = id++;
  57. #endif
  58. //Enable StarPU profiling if necessary
  59. if (properties & CL_QUEUE_PROFILING_ENABLE)
  60. {
  61. if (profiling_queue_count == 0)
  62. starpu_profiling_status_set(STARPU_PROFILING_ENABLE);
  63. profiling_queue_count += 1;
  64. }
  65. cq->commands = NULL;
  66. cq->barrier = NULL;
  67. STARPU_PTHREAD_MUTEX_INIT(&cq->mutex, NULL);
  68. if (errcode_ret != NULL)
  69. *errcode_ret = CL_SUCCESS;
  70. return cq;
  71. }