Apache Mesos
allocator.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_GPU_ALLOCATOR_HPP__
18 #define __NVIDIA_GPU_ALLOCATOR_HPP__
19 
20 #include <iosfwd>
21 #include <memory>
22 #include <set>
23 
24 #include <mesos/resources.hpp>
25 
26 #include <process/future.hpp>
27 
28 #include <stout/nothing.hpp>
29 #include <stout/try.hpp>
30 
31 #include "slave/flags.hpp"
32 
33 namespace mesos {
34 namespace internal {
35 namespace slave {
36 
37 // Simple abstraction of a GPU.
38 //
39 // TODO(klueska): Once we have a generic "Device" type it will look
40 // very similar to this. At that point we should build redefine this
41 // abstraction in terms of it.
42 struct Gpu
43 {
44  unsigned int major;
45  unsigned int minor;
46 };
47 
48 
49 // Manages the allocation of GPU devices. This can be shared across
50 // components (e.g. containerizers) to ensure that components do not
51 // perform conflicting allocation of GPU devices.
53 {
54 public:
55  NvidiaGpuAllocator() = delete;
56 
57  static Try<Resources> resources(const Flags& flags);
58 
60  const Flags& flags,
61  const Resources& resources);
62 
63  const std::set<Gpu>& total() const;
64 
65  process::Future<std::set<Gpu>> allocate(size_t count);
66  process::Future<Nothing> allocate(const std::set<Gpu>& gpus);
67  process::Future<Nothing> deallocate(const std::set<Gpu>& gpus);
68 
69 private:
70  NvidiaGpuAllocator(const std::set<Gpu>& gpus);
71 
72  // Forward declaration.
73  struct Data;
74 
75  std::shared_ptr<Data> data;
76 };
77 
78 
79 bool operator<(const Gpu& left, const Gpu& right);
80 bool operator>(const Gpu& left, const Gpu& right);
81 bool operator<=(const Gpu& left, const Gpu& right);
82 bool operator>=(const Gpu& left, const Gpu& right);
83 bool operator==(const Gpu& left, const Gpu& right);
84 bool operator!=(const Gpu& left, const Gpu& right);
85 
86 std::ostream& operator<<(std::ostream& stream, const Gpu& gpu);
87 
88 } // namespace slave {
89 } // namespace internal {
90 } // namespace mesos {
91 
92 #endif // __NVIDIA_GPU_ALLOCATOR_HPP__
bool operator>(const Gpu &left, const Gpu &right)
bool operator<(const Gpu &left, const Gpu &right)
bool operator<=(const Gpu &left, const Gpu &right)
bool operator==(const DockerVolume &left, const DockerVolume &right)
Definition: state.hpp:29
std::ostream & operator<<(std::ostream &stream, const MesosContainerizerProcess::State &state)
Definition: check.hpp:33
Definition: resources.hpp:83
Definition: allocator.hpp:42
Definition: allocator.hpp:52
Definition: flags.hpp:39
unsigned int minor
Definition: allocator.hpp:45
Definition: agent.hpp:25
Definition: attributes.hpp:24
bool operator>=(const Gpu &left, const Gpu &right)
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
bool operator!=(const Gpu &left, const Gpu &right)
unsigned int major
Definition: allocator.hpp:44
Definition: parse.hpp:33
Definition: future.hpp:58