GVM User Suite
User tools for the GVM open source project.
gvm-cli.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 2666680 Ontario Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  */
19 #include <iostream>
20 
21 #include <unistd.h>
22 
23 #include <cargs.h>
24 
25 #include <gpu/nvidia/manager.h>
26 
27 #include <utils/configs.h>
28 
29 using std::cout;
30 
45 static struct cag_option options[] = {
46 {
47 .identifier = 'c',
48 .access_letters = "c",
49 .access_name = "config",
50 .value_name = "CONFIG",
51 .description = "Configuration file to use."
52 },
53 {
54 .identifier = 'h',
55 .access_letters = "h",
56 .access_name = "help",
57 .value_name = NULL,
58 .description = "Shows the command help"
59 },
60 {
61 .identifier = 'a',
62 .access_letters = "a",
63 .access_name = "advanced-help",
64 .value_name = NULL,
65 .description = "Shows the advanced help"
66 }
67 };
68 
69 int main(int argc, char *argv[])
70 {
71  char identifier;
72  const char *config = NULL;
73  cag_option_context context;
74 
75  cag_option_prepare(&context, options, CAG_ARRAY_SIZE(options), argc, argv);
76  while (cag_option_fetch(&context)) {
77  identifier = cag_option_get(&context);
78  switch (identifier) {
79  case 'c':
80  config = cag_option_get_value(&context);
81  break;
82  case 'a':
83  printf("HELP THE FALCONS ARE CHASING ME...\n");
84  return 0;
85  case 'h':
86  printf("Copyright (C) 2022 2666680 Ontario Inc. O\\A Arc Compute\n\nThis program is free software; you can redistribute it and/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n\n");
87  printf("Usage: gvm-cli [OPTION]...\n");
88  printf("Reimplementation of mdev-gpu under the GVM User Suite\n\n");
90  return 0;
91  }
92  }
93 
94  if (config == NULL) {
95  printf("Why must the Tensor Cores crush the little cpu man?\n");
96  return 0;
97  }
98 
99  struct GpuConfigs configs = get_configs(config);
100  struct NvMdev mgr = create_nv_mgr();
101 
102  for (size_t i = 0; i < configs.config_size; ++i) {
103  struct GpuConfig config = configs.configs[i];
104  create_nv_mgr_mdevs(&mgr, config.gpus, config.gpu_size, config.requests, config.mdev_size);
105  }
106 
107  register_nv_mgr_mdevs(&mgr);
108 
109  printf("Registered MDevs on the system.\n");
110 
111  free_nv_mgr(&mgr);
112 }
CAG_PUBLIC char cag_option_get(const cag_option_context *context)
Gets the identifier of the option.
Definition: cargs.c:444
CAG_PUBLIC void cag_option_prepare(cag_option_context *context, const cag_option *options, size_t option_count, int argc, char **argv)
Prepare argument options context for parsing.
Definition: cargs.c:134
CAG_PUBLIC bool cag_option_fetch(cag_option_context *context)
Fetches an option from the argument list.
Definition: cargs.c:389
CAG_PUBLIC const char * cag_option_get_value(const cag_option_context *context)
Gets the value from the option.
Definition: cargs.c:450
#define CAG_ARRAY_SIZE(arr)
Definition: cargs.h:97
CAG_PUBLIC void cag_option_print(const cag_option *options, size_t option_count, FILE *destination)
Prints all options to the terminal.
Definition: cargs.c:103
struct GpuConfigs get_configs(const char *name)
Parses a config file.
Definition: configs.c:35
void register_nv_mgr_mdevs(struct NvMdev *mgr)
Registers mdevs on the OS.
Definition: manager.c:267
void create_nv_mgr_mdevs(struct NvMdev *mgr, struct Gpu *limited, size_t gpu_size, struct MDevRequest *requested, size_t mdev_size)
Creates necessary mediated devices on GPUs.
Definition: manager.c:184
struct NvMdev create_nv_mgr()
Creates a NVIDIA manager object.
Definition: manager.c:49
void free_nv_mgr(struct NvMdev *mgr)
Deletes a NVIDIA manager object.
Definition: manager.c:158
int main(int argc, char *argv[])
Definition: gvm-cli.cpp:69
static struct cag_option options[]
Definition: gvm-cli.cpp:45
Structure to handle GPU Configurations.
Definition: configs.h:34
struct MDevRequest * requests
List of requested mdevs.
Definition: configs.h:37
size_t mdev_size
How many requested mdevs are in the list of mdevs.
Definition: configs.h:38
size_t gpu_size
How many gpus are in the list of gpus.
Definition: configs.h:36
struct Gpu * gpus
List of gpus.
Definition: configs.h:35
Structure to provide a list of GPU configurations.
Definition: configs.h:45
size_t config_size
Size of the configuration list.
Definition: configs.h:47
struct GpuConfig * configs
List of configurations.
Definition: configs.h:46
Structure for managing the mediated stack.
Definition: resources.h:74
const char identifier
Definition: cargs.h:70