GVM User Suite
User tools for the GVM open source project.
gvm-mgr.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 #include <gvm/nvidia/manager.h>
27 
28 #include <utils/configs.h>
29 
30 using std::cout;
31 
43 static struct cag_option options[] = {
44 {
45 .identifier = 'c',
46 .access_letters = "c",
47 .access_name = "config",
48 .value_name = "CONFIG",
49 .description = "Configuration file to use."
50 },
51 {
52 .identifier = 'h',
53 .access_letters = "h",
54 .access_name = "help",
55 .value_name = NULL,
56 .description = "Shows the command help"
57 },
58 {
59 .identifier = 'a',
60 .access_letters = "a",
61 .access_name = "advanced-help",
62 .value_name = NULL,
63 .description = "Shows the advanced help"
64 }
65 };
66 
67 int main(int argc, char *argv[])
68 {
69  char identifier;
70  const char *config = NULL;
71  cag_option_context context;
72 
73  cag_option_prepare(&context, options, CAG_ARRAY_SIZE(options), argc, argv);
74  while (cag_option_fetch(&context)) {
75  identifier = cag_option_get(&context);
76  switch (identifier) {
77  case 'c':
78  config = cag_option_get_value(&context);
79  break;
80  case 'a':
81  printf("THE FALCONS WILL NEVER TAKE ME ALIVE\n");
82  return 0;
83  case 'h':
84  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");
85  printf("Usage: gvm-mgr [OPTION]...\n");
86  printf("Controls a GVM compatible VM\n\n");
88  return 0;
89  }
90  }
91 
92  if (config == NULL) {
93  printf("Little CPU man will not be crushed by the Tensors?\n");
94  return 0;
95  }
96 
97  struct GpuConfigs configs = get_configs(config);
98  struct NvMdev mgr = create_nv_mgr();
99 
100  for (size_t i = 0; i < configs.config_size; ++i) {
101  struct GpuConfig config = configs.configs[i];
102  create_nv_mgr_mdevs(&mgr, config.gpus, config.gpu_size, config.requests, config.mdev_size);
103  }
104 
105  register_nv_mgr_mdevs(&mgr);
106 
107  printf("Registered MDevs on the system.\n");
108 
109  struct VmMgr vm_mgr = init_nv_vm_mgr(&mgr);
110 
111  while (true) {
112  handle_vm_start(&vm_mgr, &mgr);
113  }
114 
115  free_nv_mgr(&mgr);
116 }
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-mgr.cpp:67
static struct cag_option options[]
Definition: gvm-mgr.cpp:43
void handle_vm_start(struct VmMgr *mgr, struct NvMdev *mdev_mgr)
Handles a start request.
Definition: manager.c:119
struct VmMgr init_nv_vm_mgr(struct NvMdev *mdevs)
Initializes a NVIDIA VM manager to connect to a VM.
Definition: manager.c:86
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
Structure for VM management.
Definition: vm_mgr.h:33
const char identifier
Definition: cargs.h:70