Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/cuda/src/clinfo/main.c
ViewVC logotype

Diff of /branches/cuda/src/clinfo/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/clinfo/clinfo.c revision 1640, Wed Nov 16 02:19:51 2011 UTC trunk/src/clinfo/main.c revision 1671, Sun Dec 4 10:56:10 2011 UTC
# Line 1  Line 1 
1  /*! \file clinfo.c  /*! \file main.c
2   *   *
3   * \author John Reppy   * \author John Reppy
4   *   *
# Line 23  Line 23 
23   * All rights reserved.   * All rights reserved.
24   */   */
25    
26  #include "Diderot/config.h"  #include "clinfo.h"
 # ifdef HAVE_CL_CL_H  
 #   include <CL/cl.h>  
 # elif defined(HAVE_OPENCL_CL_H)  
 #   include <OpenCL/cl.h>  
 # else  
 #   error no cl.h  
 # endif  
27  #include <stdio.h>  #include <stdio.h>
28  #include <string.h>  #include <string.h>
29  #include <stdlib.h>  #include <stdlib.h>
# Line 38  Line 31 
31  #define MAX_PLATFORMS   16  #define MAX_PLATFORMS   16
32    
33  static void usage ();  static void usage ();
34  static int GetPlatforms (int max, cl_platform_id *platforms);  static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name);
 static cl_platform_id GetPlatformByName (const char *name);  
 static int GetDevices (cl_platform_id plat, cl_device_type ty, cl_device_id **devs);  
35    
36  int main (int argc, const char **argv)  int main (int argc, const char **argv)
37  {  {
     cl_platform_id      platforms[MAX_PLATFORMS];  
   
38      if (argc < 2) {      if (argc < 2) {
39          usage();          usage();
40      }      }
41    
42      // get CL info
43        CLInfo_t *info = GetCLInfo ();
44    
45    // process command-line options    // process command-line options
46      if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) {      if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) {
47          char buf[256];          for (int i = 0;  i < info->numPlatforms;  i++) {
48          int numPlatforms = GetPlatforms (MAX_PLATFORMS, platforms);              printf ("%s\n", info->platforms[i].name);
         for (int i = 0;  i < numPlatforms;  i++) {  
             clGetPlatformInfo (platforms[i], CL_PLATFORM_NAME, sizeof(buf), buf, 0);  
             printf ("%s\n", buf);  
49          }          }
50      }      }
51      else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) {      else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) {
52          char buf[256];          char buf[256];
53          cl_platform_id id = GetPlatformByName(argv[2]);          cl_platform_id id = GetPlatformByName(info, argv[2]);
54          clGetPlatformInfo (id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0);          clGetPlatformInfo (id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0);
55          printf ("%s\n", buf);          printf ("%s\n", buf);
56      }      }
# Line 100  Line 89 
89      exit (1);      exit (1);
90  }  }
91    
92  static int GetPlatforms (int max, cl_platform_id *platforms)  static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name)
 {  
     cl_uint n;  
   // get number of OpenCL platforms  
     if (clGetPlatformIDs (max, platforms, &n) != CL_SUCCESS) {  
         fprintf(stderr, "unable to get platform IDs\n");  
         exit (1);  
     }  
     return n;  
 }  
   
 static cl_platform_id GetPlatformByName (const char *name)  
93  {  {
94      cl_platform_id platforms[MAX_PLATFORMS];      for (cl_uint i = 0;  i < info->numPlatforms;  i++) {
95      char buf[256];          if (strcmp(info->platforms[i].name, name) == 0)
96                return &(info->platforms[i]);
   // get number of OpenCL platforms  
     cl_uint n = GetPlatforms (MAX_PLATFORMS, platforms);  
     for (cl_uint i = 0;  i < n;  i++) {  
         clGetPlatformInfo (platforms[i], CL_PLATFORM_NAME, sizeof(buf), buf, 0);  
         if (strcmp(buf, name) == 0) return platforms[i];  
97      }      }
98    
99      fprintf (stderr, "platform %s not found\n", name);      fprintf (stderr, "platform %s not found\n", name);
100      exit (1);      exit (1);
101    
102  }  }
   
 static int GetDevices (cl_platform_id plat, cl_device_type ty, cl_device_id **devs)  
 {  
     cl_uint numDevs;  
   
   // get number of devices for the platform  
     clGetDeviceIDs (plat, ty, 0, 0, &numDevs);  
   
     cl_device_id *devices = (cl_device_id *)malloc(numDevs * sizeof(cl_device_id));  
     clGetDeviceIDs (plat, ty, numDevs, devices, 0);  
   
     *devs = devices;  
     return numDevs;  
 }  

Legend:
Removed from v.1640  
changed lines
  Added in v.1671

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0