xref: /aosp_15_r20/external/clpeak/src/options.cpp (revision 1cd03ba3888297bc945f2c84574e105e3ced3e34)
1 #include <clpeak.h>
2 
3 #define DEFAULT_XML_FILE_NAME "clpeak_results.xml"
4 
5 static const char *helpStr =
6     "\n clpeak [OPTIONS]"
7     "\n"
8     "\n OPTIONS:"
9     "\n  -p, --platform num          choose platform (num starts with 0)"
10     "\n  -d, --device num            choose device (num starts with 0)"
11     "\n  -pn, --platformName name    choose platform name"
12     "\n  -dn, --deviceName name      choose device name"
13     "\n  -tn, --testName name        choose test name"
14     "\n  --use-event-timer           time using cl events instead of std chrono timer"
15     "\n                              hide driver latencies [default: No]"
16     "\n  --global-bandwidth          selectively run global bandwidth test"
17     "\n  --compute-hp                selectively run half precision compute test"
18     "\n  --compute-sp                selectively run single precision compute test"
19     "\n  --compute-dp                selectively run double precision compute test"
20     "\n  --compute-integer           selectively run integer compute test"
21     "\n  --compute-intfast           selectively run integer 24bit compute test"
22     "\n  --compute-char              selectively run char (integer 8bit) compute test"
23     "\n  --compute-short             selectively run short (integer 16bit) compute test"
24     "\n  --transfer-bandwidth        selectively run transfer bandwidth test"
25     "\n  --kernel-latency            selectively run kernel latency test"
26     "\n  --all-tests                 run all above tests [default]"
27     "\n  --enable-xml-dump           Dump results to xml file"
28     "\n  -f, --xml-file file_name    specify file name for xml dump"
29     "\n  -v, --version               display version"
30     "\n  -h, --help                  display help message"
31     "\n";
32 
parseArgs(int argc,char ** argv)33 int clPeak::parseArgs(int argc, char **argv)
34 {
35   bool forcedTests = false;
36   bool enableXml = false;
37   string xmlFileName;
38 
39   for (int i = 1; i < argc; i++)
40   {
41     if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0))
42     {
43       log->print(helpStr);
44       log->print(NEWLINE);
45       exit(0);
46     }
47     else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0))
48     {
49       stringstream versionStr;
50       versionStr << "clpeak version: " << VERSION_STR;
51 
52       log->print(versionStr.str().c_str());
53       log->print(NEWLINE);
54       exit(0);
55     }
56     else if ((strcmp(argv[i], "-p") == 0) || (strcmp(argv[i], "--platform") == 0))
57     {
58       if ((i + 1) < argc)
59       {
60         forcePlatform = true;
61         specifiedPlatform = strtoul(argv[i + 1], NULL, 0);
62         i++;
63       }
64     }
65     else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--device") == 0))
66     {
67       if ((i + 1) < argc)
68       {
69         forceDevice = true;
70         specifiedDevice = strtoul(argv[i + 1], NULL, 0);
71         i++;
72       }
73     }
74     else if ((strcmp(argv[i], "-pn") == 0) || (strcmp(argv[i], "--platformName") == 0))
75     {
76       if ((i + 1) < argc)
77       {
78         forcePlatformName = true;
79         specifiedPlatformName = argv[i + 1];
80         i++;
81       }
82     }
83     else if ((strcmp(argv[i], "-dn") == 0) || (strcmp(argv[i], "--deviceName") == 0))
84     {
85       if ((i + 1) < argc)
86       {
87         forceDeviceName = true;
88         specifiedDeviceName = argv[i + 1];
89         i++;
90       }
91     }
92     else if ((strcmp(argv[i], "-tn") == 0) || (strcmp(argv[i], "--testName") == 0))
93     {
94       if ((i + 1) < argc)
95       {
96         forceTest = true;
97         specifiedTestName = argv[i + 1];
98         i++;
99       }
100     }
101     else if (strcmp(argv[i], "--use-event-timer") == 0)
102     {
103       useEventTimer = true;
104     }
105     else if ((strcmp(argv[i], "--global-bandwidth") == 0) || (strcmp(argv[i], "--compute-hp") == 0) || (strcmp(argv[i], "--compute-sp") == 0) || (strcmp(argv[i], "--compute-dp") == 0) || (strcmp(argv[i], "--compute-integer") == 0) || (strcmp(argv[i], "--compute-intfast") == 0) || (strcmp(argv[i], "--transfer-bandwidth") == 0) || (strcmp(argv[i], "--kernel-latency") == 0) || (strcmp(argv[i], "--compute-char") == 0) || (strcmp(argv[i], "--compute-short") == 0))
106     {
107       // Disable all and enable only selected ones
108       if (!forcedTests)
109       {
110         isGlobalBW = isComputeHP = isComputeSP = isComputeDP = isComputeInt = isComputeIntFast = isComputeChar = isComputeShort = isTransferBW = isKernelLatency = false;
111         forcedTests = true;
112       }
113 
114       if (strcmp(argv[i], "--global-bandwidth") == 0)
115       {
116         isGlobalBW = true;
117       }
118       else if (strcmp(argv[i], "--compute-hp") == 0)
119       {
120         isComputeHP = true;
121       }
122       else if (strcmp(argv[i], "--compute-sp") == 0)
123       {
124         isComputeSP = true;
125       }
126       else if (strcmp(argv[i], "--compute-dp") == 0)
127       {
128         isComputeDP = true;
129       }
130       else if (strcmp(argv[i], "--compute-integer") == 0)
131       {
132         isComputeInt = true;
133       }
134       else if (strcmp(argv[i], "--compute-intfast") == 0)
135       {
136         isComputeIntFast = true;
137       }
138       else if (strcmp(argv[i], "--compute-char") == 0)
139       {
140         isComputeChar = true;
141       }
142       else if (strcmp(argv[i], "--compute-short") == 0)
143       {
144         isComputeShort = true;
145       }
146       else if (strcmp(argv[i], "--transfer-bandwidth") == 0)
147       {
148         isTransferBW = true;
149       }
150       else if (strcmp(argv[i], "--kernel-latency") == 0)
151       {
152         isKernelLatency = true;
153       }
154     }
155     else if (strcmp(argv[i], "--all-tests") == 0)
156     {
157       isGlobalBW = isComputeHP = isComputeSP = isComputeDP = isComputeInt = isComputeIntFast = isTransferBW = isKernelLatency = true;
158     }
159     else if (strcmp(argv[i], "--enable-xml-dump") == 0)
160     {
161       enableXml = true;
162       if (xmlFileName.length() < 1)
163       {
164         xmlFileName = DEFAULT_XML_FILE_NAME;
165       }
166     }
167     else if ((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--xml-file") == 0))
168     {
169       if ((i + 1) < argc)
170       {
171         enableXml = true;
172         xmlFileName = argv[i + 1];
173         i++;
174       }
175     }
176     else
177     {
178       log->print(helpStr);
179       log->print(NEWLINE);
180       exit(-1);
181     }
182   }
183 
184   // Allocate logger after parsing
185   log = new logger(enableXml, xmlFileName);
186   return 0;
187 }
188