Openholo  v2.1
Open Source Digital Holographic Library
CUDA.h
Go to the documentation of this file.
1 #pragma once
2 #include <cuda_runtime.h>
3 #include <sys.h> //for LOG() macro
4 #include <atomic>
5 #include <mutex>
6 
7 class CUDA
8 {
9 private:
10  CUDA();
11  ~CUDA();
12  static CUDA *instance;
13  static std::mutex mutex;
14  cudaDeviceProp devProp;
15 
16  int m_nThread;
17 public:
18  static CUDA* getInstance() {
19  std::lock_guard<std::mutex> lock(mutex);
20  if (instance == nullptr) {
21  instance = new CUDA();
22  atexit(releaseInstance);
23  }
24  return instance;
25  }
26 
27  static void releaseInstance() {
28  if (instance) {
29  delete instance;
30  instance = nullptr;
31  }
32  }
33 
34  void setCurThreads(int thread) { m_nThread = thread; }
35  int getCurThreads() { return m_nThread; }
36  int getMaxThreads() { return devProp.maxThreadsPerBlock; }
37  int getWarpSize() { return devProp.warpSize; }
38 
39 private:
40  bool init();
41  bool printDevInfo();
42 
43 public:
44 
45 private:
46 };
47 std::mutex CUDA::mutex;
48 CUDA* CUDA::instance = nullptr;
static CUDA * getInstance()
Definition: CUDA.h:18
int getMaxThreads()
Definition: CUDA.h:36
int getWarpSize()
Definition: CUDA.h:37
void setCurThreads(int thread)
Definition: CUDA.h:34
int getCurThreads()
Definition: CUDA.h:35
Definition: CUDA.h:7
static void releaseInstance()
Definition: CUDA.h:27