SCM Repository
Annotation of /branches/vis12/src/clinfo/main.c
Parent Directory
|
Revision Log
Revision 2075 - (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 : | * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
26 : | * All rights reserved. | ||
27 : | */ | ||
28 : | |||
29 : | jhr | 2075 | #include "Diderot/clinfo.h" |
30 : | jhr | 1640 | #include <stdio.h> |
31 : | #include <string.h> | ||
32 : | #include <stdlib.h> | ||
33 : | jhr | 2075 | #include <stdbool.h> |
34 : | jhr | 1640 | |
35 : | #define MAX_PLATFORMS 16 | ||
36 : | |||
37 : | static void usage (); | ||
38 : | jhr | 1671 | static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name); |
39 : | jhr | 1640 | |
40 : | int main (int argc, const char **argv) | ||
41 : | { | ||
42 : | if (argc < 2) { | ||
43 : | usage(); | ||
44 : | } | ||
45 : | |||
46 : | jhr | 1671 | // get CL info |
47 : | jhr | 2075 | CLInfo_t *info = Diderot_GetCLInfo (); |
48 : | jhr | 1671 | |
49 : | jhr | 1640 | // process command-line options |
50 : | jhr | 2075 | 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 : | jhr | 1671 | for (int i = 0; i < info->numPlatforms; i++) { |
55 : | printf ("%s\n", info->platforms[i].name); | ||
56 : | jhr | 1640 | } |
57 : | } | ||
58 : | else if ((strcmp(argv[1], "version") == 0) && (argc == 3)) { | ||
59 : | char buf[256]; | ||
60 : | jhr | 2075 | PlatformInfo_t *platform = GetPlatformByName(info, argv[2]); |
61 : | clGetPlatformInfo (platform->id, CL_PLATFORM_VERSION, sizeof(buf), buf, 0); | ||
62 : | jhr | 1640 | printf ("%s\n", buf); |
63 : | } | ||
64 : | else if ((strcmp(argv[1], "devices") == 0) && (argc == 3)) { | ||
65 : | jhr | 2075 | if (strcmp(argv[2], "all") == 0) { |
66 : | // list all devices | ||
67 : | for (int i = 0; i < info->numPlatforms; i++) { | ||
68 : | PlatformInfo_t *plat = &(info->platforms[i]); | ||
69 : | for (int j = 0; j < plat->numDevices; j++) { | ||
70 : | DeviceInfo_t *dev = &(plat->devices[j]); | ||
71 : | 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 : | jhr | 1640 | } |
78 : | jhr | 2075 | 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 : | jhr | 1640 | } |
89 : | else if ((strcmp(argv[1], "extensions") == 0) && (argc == 3)) { | ||
90 : | jhr | 2075 | PlatformInfo_t *platform = GetPlatformByName(info, argv[2]); |
91 : | jhr | 1640 | size_t bufSz; |
92 : | // get the size of the extensions buffer | ||
93 : | jhr | 2075 | clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, 0, 0, &bufSz); |
94 : | jhr | 1640 | char *buf = (char *)malloc(bufSz); |
95 : | jhr | 2075 | clGetPlatformInfo (platform->id, CL_PLATFORM_EXTENSIONS, bufSz, buf, 0); |
96 : | jhr | 1640 | char *p = buf; |
97 : | while (p != 0) { | ||
98 : | p = strchr(p, ' '); | ||
99 : | if (p != 0) *p = '\n'; | ||
100 : | } | ||
101 : | printf ("%s", buf); | ||
102 : | free (buf); | ||
103 : | } | ||
104 : | else | ||
105 : | usage(); | ||
106 : | |||
107 : | } | ||
108 : | |||
109 : | static void usage () | ||
110 : | { | ||
111 : | jhr | 2075 | 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 : | jhr | 1640 | exit (1); |
125 : | } | ||
126 : | |||
127 : | jhr | 1671 | static PlatformInfo_t *GetPlatformByName (const CLInfo_t *info, const char *name) |
128 : | jhr | 1640 | { |
129 : | jhr | 1671 | for (cl_uint i = 0; i < info->numPlatforms; i++) { |
130 : | if (strcmp(info->platforms[i].name, name) == 0) | ||
131 : | return &(info->platforms[i]); | ||
132 : | jhr | 1640 | } |
133 : | |||
134 : | fprintf (stderr, "platform %s not found\n", name); | ||
135 : | exit (1); | ||
136 : | |||
137 : | } |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |