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

SCM Repository

[diderot] Diff of /branches/vis12-cl/src/clinfo/main.c
ViewVC logotype

Diff of /branches/vis12-cl/src/clinfo/main.c

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

revision 2074, Fri Nov 2 22:13:59 2012 UTC revision 2075, Sat Nov 3 13:27:02 2012 UTC
# Line 9  Line 9 
9   *      clinfo cmd [args]   *      clinfo cmd [args]
10   *   *
11   *      where cmd is one of   *      where cmd is one of
12     *              all                     -- prints all of the info about the available OpenCL
13     *                                         platforms and devices.
14   *              platforms               -- prints a list of OpenCL platforms supported by the   *              platforms               -- prints a list of OpenCL platforms supported by the
15   *                                         host.   *                                         host.
16   *              version platform        -- prints version of OpenCL supported by the platform.  The   *              version <platform>      -- prints version of OpenCL supported by the platform.  The
17   *                                         format is "OpenCL major.minor ..."   *                                         format is "OpenCL major.minor ..."
18   *              devices platform        -- prints a list of devices   *              devices all             -- prints a list of all of the devices
19   *              extensions device       -- prints a list of extensions that are   *              devices <platform>      -- prints a list of the devices on the named platform
20     *              extensions <device>     -- prints a list of extensions that are
21   *                                         supported by the device   *                                         supported by the device
22   */   */
23    
# Line 23  Line 26 
26   * All rights reserved.   * All rights reserved.
27   */   */
28    
29  #include "clinfo.h"  #include "Diderot/clinfo.h"
30  #include <stdio.h>  #include <stdio.h>
31  #include <string.h>  #include <string.h>
32  #include <stdlib.h>  #include <stdlib.h>
33    #include <stdbool.h>
34    
35  #define MAX_PLATFORMS   16  #define MAX_PLATFORMS   16
36    
# Line 40  Line 44 
44      }      }
45    
46    // get CL info    // get CL info
47      CLInfo_t *info = GetCLInfo ();      CLInfo_t *info = Diderot_GetCLInfo ();
48    
49    // process command-line options    // process command-line options
50      if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) {      if ((strcmp(argv[1], "all") == 0) && (argc == 2)) {
51            Diderot_PrintCLInfo (stdout, info);
52        }
53        else if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) {
54          for (int i = 0;  i < info->numPlatforms;  i++) {          for (int i = 0;  i < info->numPlatforms;  i++) {
55              printf ("%s\n", info->platforms[i].name);              printf ("%s\n", info->platforms[i].name);
56          }          }
57      }      }
58      else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) {      else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) {
59          char buf[256];          char buf[256];
60          cl_platform_id id = GetPlatformByName(info, argv[2]);          PlatformInfo_t *platform = GetPlatformByName(info, argv[2]);
61          clGetPlatformInfo (id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0);          clGetPlatformInfo (platform->id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0);
62          printf ("%s\n", buf);          printf ("%s\n", buf);
63      }      }
64      else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) {      else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) {
65          cl_platform_id id = GetPlatformByName(argv[2]);          if (strcmp(argv[2], "all") == 0) {
66          cl_device_id *devs;            // list all devices
67          char buf[256];              for (int i = 0;  i < info->numPlatforms;  i++) {
68          int numDevs = GetDevices (id, CL_DEVICE_TYPE_ALL, &devs);                  PlatformInfo_t *plat = &(info->platforms[i]);
69          for (int i = 0;  i < numDevs;  i++) {                  for (int j = 0;  j < plat->numDevices;  j++) {
70              clGetDeviceInfo (devs[i], CL_DEVICE_NAME, sizeof(buf), buf, 0);                      DeviceInfo_t *dev = &(plat->devices[j]);
71              printf ("%s\n", buf);                      if (dev->isAvail)
72                            printf ("%d.%d: %s\n", i, j, dev->name);
73                        else
74                            printf ("%d.%d: %s **UNAVAILABLE**\n", i, j, dev->name);
75                    }
76                }
77            }
78            else {
79                PlatformInfo_t *plat = GetPlatformByName(info, argv[2]);
80                for (int i = 0;  i < plat->numDevices;  i++) {
81                    DeviceInfo_t *dev = &(plat->devices[i]);
82                    printf ("%d.%d: %s%s\n",
83                        dev->index[0], dev->index[1],
84                        dev->name,
85                        dev->isAvail ? "" : " **UNAVAILABLE**");
86                }
87          }          }
88      }      }
89      else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) {      else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) {
90          cl_platform_id id = GetPlatformByName(argv[2]);          PlatformInfo_t *platform = GetPlatformByName(info, argv[2]);
91          size_t bufSz;          size_t bufSz;
92        // get the size of the extensions buffer        // get the size of the extensions buffer
93          clGetPlatformInfo (id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz);          clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz);
94          char *buf = (char *)malloc(bufSz);          char *buf = (char *)malloc(bufSz);
95          clGetPlatformInfo (id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0);          clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0);
96          char *p = buf;          char *p = buf;
97          while (p != 0) {          while (p != 0) {
98              p = strchr(p, ' ');              p = strchr(p, ' ');
# Line 86  Line 108 
108    
109  static void usage ()  static void usage ()
110  {  {
111        fprintf (stderr, "usage: clinfo <cmd>\n");
112        fprintf (stderr, "  where <cmd> is one of:\n");
113        fprintf (stderr, "          all                     -- prints all of the info about the available OpenCL\n");
114        fprintf (stderr, "                                     platforms and devices.\n");
115        fprintf (stderr, "          platforms               -- prints a list of OpenCL platforms supported by the\n");
116        fprintf (stderr, "                                     host.\n");
117        fprintf (stderr, "          version <platform>      -- prints version of OpenCL supported by the platform.  The\n");
118        fprintf (stderr, "                                     format is \"OpenCL major.minor ...\"\n");
119        fprintf (stderr, "          devices all             -- prints a list of all of the devices\n");
120        fprintf (stderr, "          devices <platform>      -- prints a list of the devices on the named platform\n");
121        fprintf (stderr, "          extensions <device>     -- prints a list of extensions that are\n");
122        fprintf (stderr, "                                     supported by the device\n");
123    
124      exit (1);      exit (1);
125  }  }
126    

Legend:
Removed from v.2074  
changed lines
  Added in v.2075

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