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

SCM Repository

[diderot] Annotation of /branches/vis12/src/clinfo/main.c
ViewVC logotype

Annotation of /branches/vis12/src/clinfo/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3291 - (view) (download) (as text)

1 : jhr 1671 /*! \file main.c
2 : jhr 1640 *
3 :     * \author John Reppy
4 :     *
5 :     * \brief This program is used to determine properties of the host machine's
6 :     * OpenCL support.
7 :     *
8 :     * Usage:
9 : jhr 2075 * clinfo cmd [args]
10 : jhr 1640 *
11 : jhr 2075 * 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
15 :     * host.
16 :     * version <platform> -- prints version of OpenCL supported by the platform. The
17 :     * format is "OpenCL major.minor ..."
18 :     * devices all -- prints a list of all of the devices
19 :     * 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
22 : jhr 1640 */
23 :    
24 :     /*
25 : jhr 3291 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
26 :     *
27 :     * COPYRIGHT (c) 2015 The University of Chicago
28 : jhr 1640 * All rights reserved.
29 :     */
30 :    
31 : jhr 2075 #include "Diderot/clinfo.h"
32 : jhr 1640 #include <stdio.h>
33 :     #include <string.h>
34 :     #include <stdlib.h>
35 : jhr 2075 #include <stdbool.h>
36 : jhr 1640
37 :     #define MAX_PLATFORMS 16
38 :    
39 :     static void usage ();
40 : jhr 1671 static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name);
41 : jhr 1640
42 :     int main (int argc, const char **argv)
43 :     {
44 :     if (argc < 2) {
45 :     usage();
46 :     }
47 :    
48 : jhr 1671 // get CL info
49 : jhr 2075 CLInfo_t *info = Diderot_GetCLInfo ();
50 : jhr 1671
51 : jhr 1640 // process command-line options
52 : jhr 2075 if ((strcmp(argv[1], "all") == 0) && (argc == 2)) {
53 :     Diderot_PrintCLInfo (stdout, info);
54 :     }
55 :     else if ((strcmp(argv[1], "platforms") == 0) && (argc == 2)) {
56 : jhr 1671 for (int i = 0; i < info->numPlatforms; i++) {
57 :     printf ("%s\n", info->platforms[i].name);
58 : jhr 1640 }
59 :     }
60 :     else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) {
61 :     char buf[256];
62 : jhr 2075 PlatformInfo_t *platform = GetPlatformByName(info, argv[2]);
63 :     clGetPlatformInfo (platform->id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0);
64 : jhr 1640 printf ("%s\n", buf);
65 :     }
66 :     else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) {
67 : jhr 2075 if (strcmp(argv[2], "all") == 0) {
68 :     // list all devices
69 :     for (int i = 0; i < info->numPlatforms; i++) {
70 :     PlatformInfo_t *plat = &(info->platforms[i]);
71 :     for (int j = 0; j < plat->numDevices; j++) {
72 :     DeviceInfo_t *dev = &(plat->devices[j]);
73 :     if (dev->isAvail)
74 :     printf ("%d.%d: %s\n", i, j, dev->name);
75 :     else
76 :     printf ("%d.%d: %s **UNAVAILABLE**\n", i, j, dev->name);
77 :     }
78 :     }
79 : jhr 1640 }
80 : jhr 2075 else {
81 :     PlatformInfo_t *plat = GetPlatformByName(info, argv[2]);
82 :     for (int i = 0; i < plat->numDevices; i++) {
83 :     DeviceInfo_t *dev = &(plat->devices[i]);
84 :     printf ("%d.%d: %s%s\n",
85 :     dev->index[0], dev->index[1],
86 :     dev->name,
87 :     dev->isAvail ? "" : " **UNAVAILABLE**");
88 :     }
89 :     }
90 : jhr 1640 }
91 :     else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) {
92 : jhr 2075 PlatformInfo_t *platform = GetPlatformByName(info, argv[2]);
93 : jhr 1640 size_t bufSz;
94 :     // get the size of the extensions buffer
95 : jhr 2075 clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz);
96 : jhr 1640 char *buf = (char *)malloc(bufSz);
97 : jhr 2075 clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0);
98 : jhr 1640 char *p = buf;
99 :     while (p != 0) {
100 :     p = strchr(p, ' ');
101 :     if (p != 0) *p = '\n';
102 :     }
103 :     printf ("%s", buf);
104 :     free (buf);
105 :     }
106 :     else
107 :     usage();
108 :    
109 :     }
110 :    
111 :     static void usage ()
112 :     {
113 : jhr 2075 fprintf (stderr, "usage: clinfo <cmd>\n");
114 :     fprintf (stderr, " where <cmd> is one of:\n");
115 :     fprintf (stderr, " all -- prints all of the info about the available OpenCL\n");
116 :     fprintf (stderr, " platforms and devices.\n");
117 :     fprintf (stderr, " platforms -- prints a list of OpenCL platforms supported by the\n");
118 :     fprintf (stderr, " host.\n");
119 :     fprintf (stderr, " version <platform> -- prints version of OpenCL supported by the platform. The\n");
120 :     fprintf (stderr, " format is \"OpenCL major.minor ...\"\n");
121 :     fprintf (stderr, " devices all -- prints a list of all of the devices\n");
122 :     fprintf (stderr, " devices <platform> -- prints a list of the devices on the named platform\n");
123 :     fprintf (stderr, " extensions <device> -- prints a list of extensions that are\n");
124 :     fprintf (stderr, " supported by the device\n");
125 :    
126 : jhr 1640 exit (1);
127 :     }
128 :    
129 : jhr 1671 static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name)
130 : jhr 1640 {
131 : jhr 1671 for (cl_uint i = 0; i < info->numPlatforms; i++) {
132 :     if (strcmp(info->platforms[i].name, name) == 0)
133 :     return &(info->platforms[i]);
134 : jhr 1640 }
135 :    
136 :     fprintf (stderr, "platform %s not found\n", name);
137 :     exit (1);
138 :    
139 :     }

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