Apache Mesos
nvml.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __NVIDIA_NVML_HPP__
18 #define __NVIDIA_NVML_HPP__
19 
20 #ifdef ENABLE_NVML
21 #include <nvidia/gdk/nvml.h>
22 #else
23 // We provide dummy types in case we do not use the NVML headers.
24 using nvmlDevice_t = int;
25 #endif // ENABLE_NVML
26 
27 #include <string>
28 
29 #include <stout/nothing.hpp>
30 #include <stout/try.hpp>
31 
32 // The `nvml` namespace acts as a higher-level wrapper on top of the
33 // NVIDIA Management Library (NVML). By providing this higher-level
34 // API, we eliminate the build-time dependency on `libnvidia-ml` in
35 // favor of a runtime dependency. The caller may probe to see if the
36 // library is available, and may take different code paths accordingly.
37 // This is advantageous for deploying a common `libmesos` on machines
38 // both with and without GPUs installed. Only those machines that have
39 // GPUs need to have the `libnvidia-ml` library installed on their
40 // system.
41 //
42 // TODO(klueska): Add unit tests and provide finalization support.
43 namespace nvml {
44 
45 // Returns whether the NVML library is installed on the system
46 // and can be loaded at runtime.
47 bool isAvailable();
48 
49 // Load and initialize NVML. This must be called prior to making
50 // use of the NVML wrapper functions below.
52 
53 // NVML wrapper functions. May be called after initializing
54 // the library.
59 
60 } // namespace nvml {
61 
62 #endif // __NVIDIA_NVML_HPP__
Definition: check.hpp:33
Try< unsigned int > deviceGetMinorNumber(nvmlDevice_t handle)
Try< Nothing > initialize()
Definition: net.hpp:76
int nvmlDevice_t
Definition: nvml.hpp:24
Try< unsigned int > deviceGetCount()
Try< std::string > systemGetDriverVersion()
Definition: nvml.hpp:43
bool isAvailable()
Try< nvmlDevice_t > deviceGetHandleByIndex(unsigned int index)