GVM User Suite
User tools for the GVM open source project.
nvidia-manager.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 <gpu/nvidia/manager.h>
24 #include <gpu/nvidia/resources.h>
25 
26 #include <utils/colors.h>
27 
28 using std::cout;
29 
39 {
40  struct NvMdev mgr = create_nv_mgr();
41  struct VirtDisplay display = {};
42  struct MDevRequest requested = {};
43 
44  display.num_heads = 4;
45  display.max_res_x = 1024;
46  display.max_res_y = 1024;
47  display.frl_config = 120;
48  display.frl_enable = 0;
49 
50  requested.disp = &display;
51  requested.num = 1;
52  requested.v_dev_id = 0x1B301B30;
53  requested.p_dev_id = 0x1B30;
54  requested.name = "GVM";
55  requested.gpu_class = "GeForce";
56  requested.max_inst = 1;
57  requested.fb_len = 896;
58  requested.fb_res = 128;
59  requested.map_vid_size = 4;
60  requested.enc_cap = 100;
61  requested.bar1_len = 0x100;
62 
63  bool ret = mgr.fd != -1;
64 
65  if (ret) {
66  create_nv_mgr_mdevs(&mgr, NULL, 0, &requested, 1);
68  }
69 
70  free_nv_mgr(&mgr);
71 
72  return ret;
73 }
74 
75 int main()
76 {
77  const uint32_t NUM_TESTS = 1;
78 
79  const std::string test_names[] = {
80  "Create MDevs"
81  };
82  const std::string test_details[] = {
83  "Nvidia manager create mdevs failed.",
84  };
85 
86  bool (*tests[])(void) = {
88  };
89 
90  uint32_t failures = 0;
91 
92  for (uint32_t i = 0; i < NUM_TESTS; ++i) {
93  bool test_result = tests[i]() == 1;
94 
95  if (test_result)
96  cout << GREEN_COLOR << test_names[i]
97  << " succeeded" RESET_COLOR "\n";
98  else {
99  ++failures;
100  cout << RED_COLOR << test_names[i]
101  << ": " << test_details[i]
102  << RESET_COLOR "\n";
103  }
104  }
105 
106  if (failures == 0)
107  cout << GREEN_COLOR << "All tests succeeded" RESET_COLOR "\n";
108  else
109  cout << RED_COLOR << failures << "/"
110  << NUM_TESTS << " tests failed" RESET_COLOR "\n";
111 }
#define RED_COLOR
Red color.
Definition: colors.h:30
#define GREEN_COLOR
Green color.
Definition: colors.h:33
#define RESET_COLOR
Reset color.
Definition: colors.h:51
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
bool create_mdevs()
int main()
Mediated Device Request Structure.
Definition: mdev.h:62
uint32_t map_vid_size
Mappable video size (IN MEGABYTES).
Definition: mdev.h:74
const char * name
Name of the GPU.
Definition: mdev.h:66
uint32_t bar1_len
Bar 1 Length.
Definition: mdev.h:77
uint32_t max_inst
Max number of mediated GPUs.
Definition: mdev.h:68
uint64_t v_dev_id
Virtual device id.
Definition: mdev.h:64
uint32_t fb_res
Frame buffer reserved (IN MEGABYTES).
Definition: mdev.h:73
uint64_t p_dev_id
Physical device id.
Definition: mdev.h:65
uint32_t fb_len
Frame buffer length (IN MEGABYTES).
Definition: mdev.h:72
uint32_t num
Number of the mdev.
Definition: mdev.h:63
uint32_t enc_cap
Definition: mdev.h:75
const char * gpu_class
GPU Class structure.
Definition: mdev.h:67
struct VirtDisplay * disp
Virtual display structure.
Definition: mdev.h:69
Structure for managing the mediated stack.
Definition: resources.h:74
int fd
Control file descriptor.
Definition: resources.h:75
Virtual Display.
Definition: mdev.h:49
uint32_t frl_config
Frame rate limiter.
Definition: mdev.h:53
uint32_t max_res_y
Max resolution Y.
Definition: mdev.h:52
uint32_t frl_enable
If we use the frame rate limiter.
Definition: mdev.h:54
uint32_t max_res_x
Max resolution X.
Definition: mdev.h:51
uint32_t num_heads
Number of monitor heads.
Definition: mdev.h:50