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 #include <nvidia/gdk/nvml.h>
21 
22 #include <string>
23 
24 #include <stout/nothing.hpp>
25 #include <stout/try.hpp>
26 
27 // The `nvml` namespace acts as a higher-level wrapper on top of the
28 // NVIDIA Management Library (NVML). By providing this higher-level
29 // API, we eliminate the build-time dependency on `libnvidia-ml` in
30 // favor of a runtime dependency. The caller may probe to see if the
31 // library is available, and may take different code paths accordingly.
32 // This is advantageous for deploying a common `libmesos` on machines
33 // both with and without GPUs installed. Only those machines that have
34 // GPUs need to have the `libnvidia-ml` library installed on their
35 // system.
36 //
37 // TODO(klueska): Add unit tests and provide finalization support.
38 namespace nvml {
39 
40 // Returns whether the NVML library is installed on the system
41 // and can be loaded at runtime.
42 bool isAvailable();
43 
44 // Load and initialize NVML. This must be called prior to making
45 // use of the NVML wrapper functions below.
47 
48 // NVML wrapper functions. May be called after initializing
49 // the library.
53 Try<unsigned int> deviceGetMinorNumber(nvmlDevice_t handle);
54 
55 } // namespace nvml {
56 
57 #endif // __NVIDIA_NVML_HPP__
Definition: check.hpp:33
Try< unsigned int > deviceGetMinorNumber(nvmlDevice_t handle)
Try< Nothing > initialize()
Definition: net.hpp:76
Try< unsigned int > deviceGetCount()
Try< std::string > systemGetDriverVersion()
Definition: nvml.hpp:38
bool isAvailable()
Try< nvmlDevice_t > deviceGetHandleByIndex(unsigned int index)