GpuRgbMemory.hpp
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<string>
#include "cuda_kernels.h"
#include "define.hpp"
#include "utiltools.hpp"
using namespace std;
class GpuRgbMemory{
public:
GpuRgbMemory(int _channel, int _width, int _height, string _id, string _gpuid, bool _isused){
channel = _channel;
width = _width;
height = _height;
size = channel * width * height;
isused = _isused;
id = _id;
gpuid = _gpuid;
timestamp = UtilTools::get_cur_time_ms();
cudaSetDevice(atoi(gpuid.c_str()));
CHECK_CUDA(cudaMalloc((void **)&pHwRgb, size * sizeof(unsigned char)));
}
~GpuRgbMemory(){
if (pHwRgb) {
cudaSetDevice(atoi(gpuid.c_str()));
CHECK_CUDA(cudaFree(pHwRgb));
pHwRgb = nullptr;
}
}
int getSize() {
return size;
}
bool isIsused() {
return isused;
}
void setIsused(bool _isused) {
isused = _isused;
// 更新时间戳
timestamp = UtilTools::get_cur_time_ms();
}
string getId() {
return id;
}
string getGpuId() {
return gpuid;
}
unsigned char* getMem(){
return pHwRgb;
}
long long getTimesstamp(){
return timestamp;
}
int getWidth(){
return width;
}
int getHeight(){
return height;
}
int getChannel(){
return channel;
}
private:
int size;
bool isused;
string id;
string gpuid;
unsigned char * pHwRgb{nullptr};
long long timestamp;
int width{0};
int height{0};
int channel{3};
};