cl_getdeviceids.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 University of Bordeaux
  4. * Copyright (C) 2012 CNRS
  5. * Copyright (C) 2012 Vincent Danjean <Vincent.Danjean@ens-lyon.org>
  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. #include "init.h"
  20. /**
  21. * \brief Return one device of each kind
  22. *
  23. * \param[in] platform Must be StarPU platform ID or NULL
  24. */
  25. CL_API_ENTRY cl_int CL_API_CALL
  26. soclGetDeviceIDs(cl_platform_id platform,
  27. cl_device_type device_type,
  28. cl_uint num_entries,
  29. cl_device_id * devices,
  30. cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0
  31. {
  32. if( ! _starpu_init )
  33. socl_init_starpu();
  34. if (_starpu_init_failed) {
  35. *num_devices = 0;
  36. return CL_SUCCESS;
  37. }
  38. if (platform != NULL && platform != &socl_platform)
  39. return CL_INVALID_PLATFORM;
  40. if ((devices != NULL && num_entries == 0)
  41. || (devices == NULL && num_devices == NULL))
  42. return CL_INVALID_VALUE;
  43. if (!(device_type & (CL_DEVICE_TYPE_CPU | CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR | CL_DEVICE_TYPE_DEFAULT))
  44. && (device_type != CL_DEVICE_TYPE_ALL))
  45. return CL_INVALID_DEVICE_TYPE;
  46. {
  47. int i;
  48. unsigned int num = 0;
  49. for (i=0; i<socl_device_count; i++) {
  50. if (socl_devices[i].type & device_type) {
  51. if (devices != NULL && num < num_entries)
  52. devices[num] = (cl_device_id)&socl_devices[i];
  53. num++;
  54. }
  55. }
  56. if (num_devices != NULL)
  57. *num_devices = num;
  58. }
  59. return CL_SUCCESS;
  60. }