Advertisement
Guest User

abbasaly012

a guest
Feb 27th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <CL/cl.h>
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <unistd.h>
  5.  
  6. int main( int argc, const char* argv[] ){
  7. cl_int err;
  8. unsigned int i;
  9.  
  10. // Get all platform IDs
  11. cl_uint nr_of_platforms;
  12. err = clGetPlatformIDs(0, NULL, &nr_of_platforms);
  13. assert(err == CL_SUCCESS);
  14. fprintf(stderr,"EC: %i\n",err);
  15. if (nr_of_platforms == 0) {
  16. fprintf(stderr, "No OpenCL platforms found.\n");
  17. return;
  18. }
  19. cl_platform_id platforms[nr_of_platforms];
  20. err = clGetPlatformIDs(nr_of_platforms, platforms, NULL);
  21. fprintf(stderr,"EC: %i\n",err);
  22. assert(err == CL_SUCCESS);
  23.  
  24. // Now select platform and device. We simply pick the first device that is of the requested type.
  25. cl_platform_id platform = NULL;
  26. cl_device_id device = NULL;
  27. for (i=0; i<nr_of_platforms; ++i) {
  28. cl_uint nr_of_devices;
  29. err = clGetDeviceIDs(
  30. platforms[i], (1 ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU),
  31. 0, NULL, &nr_of_devices);
  32. fprintf(stderr,"EC: %i\n",err);
  33. if (!err && nr_of_devices > 0) {
  34. platform = platforms[i];
  35. err = clGetDeviceIDs(platform, 1 ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device, NULL);
  36. fprintf(stderr,"EC: %i\n",err);
  37. assert(err == CL_SUCCESS);
  38. break;
  39. }
  40. }
  41.  
  42. // Check if we selected a device
  43. if (device == NULL) {
  44. fprintf(stderr, "No suitable OpenCL device found.\n");
  45. return;
  46. }
  47.  
  48. cl_context context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
  49. fprintf(stderr,"EC: %i\n",err);
  50. assert(err == CL_SUCCESS);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement