Openholo  v4.2
Open Source Digital Holographic Library
CUDA.cpp
Go to the documentation of this file.
1 #include "CUDA.h"
2 #include "define.h"
3 #include <iostream>
4 #include <string>
5 #include <iomanip>
6 
7 static void HandleError(cudaError_t err,
8  const char *file,
9  int line) {
10  if (err != cudaSuccess) {
11  printf("%s in %s at line %d\n", cudaGetErrorString(err),
12  file, line);
13  exit(EXIT_FAILURE);
14  }
15 }
16 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
17 
18 
19 #define HANDLE_NULL( a ) {if (a == NULL) { \
20  printf( "Host memory failed in %s at line %d\n", \
21  __FILE__, __LINE__ ); \
22  exit( EXIT_FAILURE );}}
23 
24 
25 CUDA* CUDA::instance = nullptr;
26 
27 CUDA::CUDA()
28 {
29  printDevInfo();
30  m_nThread = 512;
31 }
32 
33 
34 CUDA::~CUDA()
35 {
36 }
37 
38 
39 bool CUDA::printDevInfo()
40 {
41  int devID;
42  HANDLE_ERROR(cudaGetDevice(&devID));
43  HANDLE_ERROR(cudaGetDeviceProperties(&devProp, devID));
44 
45  LOG("GPU Spec : %s\n", devProp.name);
46 #ifdef _WIN64
47  LOG(" - Global Memory : %llu\n", devProp.totalGlobalMem);
48  LOG(" - Const Memory : %llu\n", devProp.totalConstMem);
49 #else
50  LOG(" - Global Memory : %zu\n", devProp.totalGlobalMem);
51  LOG(" - Const Memory : %zu\n", devProp.totalConstMem);
52 #endif
53  LOG(" - MP(Multiprocessor) Count : %d\n", devProp.multiProcessorCount);
54  LOG(" - Maximum Threads per MP : %d\n", devProp.maxThreadsPerMultiProcessor);
55  LOG(" - Warp Size : %u\n", devProp.warpSize);
56 #ifdef _WIN64
57  LOG(" - Shared Memory per MP : %llu\n", devProp.sharedMemPerMultiprocessor);
58 #else
59  LOG(" - Shared Memory per MP : %zu\n", devProp.sharedMemPerMultiprocessor);
60 #endif
61  LOG(" - Block per MP : %d\n", devProp.maxThreadsPerMultiProcessor / devProp.maxThreadsPerBlock);
62 #ifdef _WIN64
63  LOG(" - Shared Memory per Block : %llu\n", devProp.sharedMemPerBlock);
64 #else
65  LOG(" - Shared Memory per Block : %zu\n", devProp.sharedMemPerBlock);
66 #endif
67  LOG(" - Maximum Threads per Block : %d\n", devProp.maxThreadsPerBlock);
68  LOG(" - Maximum Threads of each Dimension of a Block (X: %d / Y: %d / Z: %d)\n",
69  devProp.maxThreadsDim[_X], devProp.maxThreadsDim[_Y], devProp.maxThreadsDim[_Z]);
70  LOG(" - Maximum Blocks of each Dimension of a Grid, (X: %d / Y: %d / Z: %d)\n",
71  devProp.maxGridSize[_X], devProp.maxGridSize[_Y], devProp.maxGridSize[_Z]);
72  LOG(" - Device supports allocating Managed Memory on this system : %d\n\n", devProp.managedMemory);
73 
74 
75  return true;
76 }
77 
78 void CUDA::printMemoryInfo(uint64_t total, uint64_t free)
79 {
80  uint64_t gb = 1024 * 1024 * 1024;
81  LOG("CUDA Memory: %.1f/%.1fGB\n", static_cast<double>(total - free) / gb, static_cast<double>(total) / gb);
82 }
#define HANDLE_ERROR(err)
Definition: CUDA.cpp:16
void printMemoryInfo(uint64_t total, uint64_t free)
Definition: CUDA.cpp:78
#define _X
Definition: define.h:92
Definition: CUDA.h:7
#define _Y
Definition: define.h:96
#define _Z
Definition: define.h:100