TBTK
Need a break? Support the development by playing Polarity Puzzles
GPUResourceManager.h
1 /* Copyright 2016 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_GPU_RESOURCE_MANAGER
25 #define COM_DAFER45_TBTK_GPU_RESOURCE_MANAGER
26 
27 #include "Communicator.h"
28 
29 #ifndef __APPLE__
30 # include <omp.h>
31 #endif
32 
33 namespace TBTK{
34 
35 class GPUResourceManager : public Communicator{
36 public:
38  int getNumDevices();
39 
41  int allocateDevice();
42 
44  void freeDevice(int device);
45 
47  static GPUResourceManager& getInstance();
48 private:
50  GPUResourceManager();
51 
53  GPUResourceManager(const GPUResourceManager &gpuResourceManager) = delete;
54 
56  GPUResourceManager& operator=(const GPUResourceManager &gpuResourceManager) = delete;
57 
59  int numDevices;
60 
62  bool *busyDevices;
63 
64 #ifndef __APPLE__
65 
66  omp_lock_t busyDevicesLock;
67 #endif
68 
70  void createDeviceTable();
71 
73  void destroyDeviceTable();
74 };
75 
76 inline int GPUResourceManager::getNumDevices(){
77  return numDevices;
78 }
79 
80 }; //End of namespace TBTK
81 
82 #endif
83 
Definition: Boolean.h:32
Base class for classes that can communicate their status during execution.