cl_getdeviceids.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  18. * \brief Return one device of each kind
  19. *
  20. * \param[in] platform Must be StarPU platform ID or NULL
  21. */
  22. CL_API_ENTRY cl_int CL_API_CALL
  23. soclGetDeviceIDs(cl_platform_id platform,
  24. cl_device_type device_type,
  25. cl_uint num_entries,
  26. cl_device_id * devices,
  27. cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0
  28. {
  29. if (platform != NULL && platform != &socl_platform)
  30. return CL_INVALID_PLATFORM;
  31. if ((devices != NULL && num_entries == 0)
  32. || (devices == NULL && num_devices == NULL))
  33. return CL_INVALID_VALUE;
  34. if (!(device_type & (CL_DEVICE_TYPE_CPU | CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR | CL_DEVICE_TYPE_DEFAULT))
  35. && (device_type != CL_DEVICE_TYPE_ALL))
  36. return CL_INVALID_DEVICE_TYPE;
  37. {
  38. int i;
  39. unsigned int num = 0;
  40. for (i=0; i<socl_device_count; i++) {
  41. if (socl_devices[i].type & device_type) {
  42. if (devices != NULL && num < num_entries)
  43. devices[num] = (cl_device_id)&socl_devices[i];
  44. num++;
  45. }
  46. }
  47. if (num_devices != NULL)
  48. *num_devices = num;
  49. }
  50. return CL_SUCCESS;
  51. }