1+ #include < iostream>
2+
3+ #include < RunAsGPU/Shared/Shared.hpp>
4+ #include < RunAsGPU/Shared/HelpPage.hpp>
5+ #include < RunAsGPU/Shared/Runner.hpp>
6+
7+ namespace fs = std::filesystem;
8+
9+ void list () {
10+ std::vector<GraphicalUnit> gpu_list = Runner::ListGraphicalUnits ();
11+ for (int i = 0 ; i < gpu_list.size (); i++) {
12+ const GraphicalUnit& unit = gpu_list[i];
13+
14+ std::cout << " GPU - " << unit.vendorName << " (" << std::hex << unit.vendor << " )\n " ;
15+ std::cout << " \t Name = " << unit.productName << " (" << std::hex << unit.product << " )\n " ;
16+ std::cout << " \t ID = " << i << " \n " ;
17+ std::cout << " \t Connector = " ;
18+
19+ switch (unit.connector ) {
20+ case EXTERNAL:
21+ std::cout << " External Graphics Card" << std::endl;
22+ break ;
23+ case INTERNAL:
24+ std::cout << " Internal GPU" << std::endl;
25+ break ;
26+ case DEDICATED:
27+ std::cout << " Dedicated GPU" << std::endl;
28+ break ;
29+ }
30+
31+ if (i != gpu_list.size () - 1 )
32+ std::cout << std::endl;
33+ }
34+ }
35+
36+ int main (int argc, char **argv) {
37+ if (argc == 1 || (argc == 2 && (std::string (argv[1 ]) == " --help" || std::string (argv[1 ]) == " -h" ))) {
38+ std::string fn = GetExecutablePath ().filename ().string ();
39+
40+ std::cout << " RunAsGPU v1.0" << std::endl;
41+ std::cout << " usage: ./" << fn << " [action] [options] [exec [..args]]" << std::endl << std::endl;
42+ std::cout << " actions:" << std::endl;
43+
44+ HelpPage actions;
45+ actions.setStartSpaceWidth (4 );
46+ actions.setDescSeparator (" " );
47+ actions.addArg (" run" , " " , " Run an executable" );
48+ actions.addArg (" list" , " " , " List all active GPUs" );
49+ actions.display (std::cout);
50+
51+ std::cout << std::endl;
52+ std::cout << " options:" << std::endl;
53+
54+ HelpPage options;
55+ options.setStartSpaceWidth (4 );
56+ options.setSpaceWidth (3 );
57+ options.setDescSeparator (" =" );
58+ options.addArg (" -ui | --unit-id" , " ID" , " Select a specific GPU by its given ID" );
59+ options.addArg (" -fu | --find-unit" , " [GPU]" , " Find a GPU by its identification (Vendor ID, Device / Product ID, Name)" );
60+ options.addArg (" -fnu | --find-unit-name" , " [Name]" , " Find a GPU by the name" );
61+ options.addArg (" -fvu | --find-unit-vendor" , " [Vendor]" , " Find a GPU by the name or ID of the Vendor (e.g. NVIDIA)" );
62+ options.addArg (" -fpu | --find-unit-product" , " [Product]" , " Find a GPU by the name or ID of the Product (e.g. GeForce 6800 XT)" );
63+ options.addArg (" -ni | --non-interactive" , " " , " Will not prompt for GPU selection (e.g. running as a script)" );
64+ options.display (std::cout);
65+
66+ return 0 ;
67+ }
68+
69+ std::vector<std::string> args;
70+ std::string action = argv[1 ];
71+ if (action == " list" ) {
72+ list ();
73+ return 0 ;
74+ }
75+
76+ return 0 ;
77+ }
0 commit comments