-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcuda_pyramid.cuh
174 lines (138 loc) · 4.78 KB
/
cuda_pyramid.cuh
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef CUDA_PYRAMID_CUH
#define CUDA_PYRAMID_CUH
#include "cuda_polygon.cuh"
#include "model_class.hpp"
// OpenCV includes
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
// Local includes
//#include "kernels.cuh"
#include "defines.hpp"
#include "domains.hpp"
#include "enums.hpp"
// Utility includes
#include <assert.h>
#include <map>
#include <vector>
// Multithread includes
#include <future>
#include <thread>
#include <nvToolsExt.h> // Marker for the nvvp profiler
class cudaImage {
int start{0};
int step{0};
int stop{0};
ImageType imageType;
cudaStream_t stream;
std::vector<cudaArray *> d_images_cuArray;
std::vector<cudaTextureObject_t> textures;
std::vector<cudaSurfaceObject_t> surfaces;
int rowsLevel0{0};
int colsLevel0{0};
int number_of_colors{0};
void makePyramid(const cv::Mat &image_in);
void uploadImage0(const cv::Mat &image_in);
void allocateImages(const cv::Mat &image_in);
void createAndBindTextures();
void createAndBindSurfaces();
void deleteSurfaces();
void deleteTextures();
void deleteCudaArrays();
public:
cudaImage(const cv::Mat &image_, int start_, int step_, int stop_,
ImageType imageType_, cudaStream_t stream_)
: start(start_), step(step_), stop(stop_), imageType(imageType_),
stream(stream_) {
// Put a marker on the nvvp CUDA profiler
nvtxRangePushA("cudaImage::cudaImage");
assert(image_.isContinuous());
allocateImages(image_);
createAndBindSurfaces();
createAndBindTextures();
uploadImage0(image_);
makePyramid(image_);
nvtxRangePop();
}
~cudaImage() {
deleteSurfaces();
deleteTextures();
deleteCudaArrays();
}
void setStart(int Start_);
void setStep(int Step_);
void setStop(int Stop_);
void testPyramid();
void setImageType(ImageType imageType_);
void recycleImage(const cv::Mat &image_in, ImageType imageType_);
cudaTextureObject_t getTexture(int level_);
};
class cudaPyramid {
/**
cudaPyramid contains all the data that is to be uploaded to the GPU
*/
int start{0};
int step{0};
int stop{0};
cudaImage *undImage{nullptr};
cudaImage *defImage{nullptr};
cudaImage *nxtImage{nullptr};
cudaStream_t undStream;
cudaStream_t defStream;
cudaStream_t nxtStream;
std::map<int, cudaPolygon *> polygons; // Each polygon object contains the
// fitting model, und_x and y, und
// centers, def_x and y, DdilDe.
cudaImage *getNewPyramid(const cv::Mat CvImage, ImageType imageType_,
cudaStream_t stream_);
void createImageStreams();
void destroyImageStreams();
void deleteImages();
void deletePolygons();
public:
cudaPyramid() { createImageStreams(); }
~cudaPyramid() {
deleteImages();
destroyImageStreams();
deletePolygons();
#if DEBUG_CUDA_POLYGON
printf("Deleting cudaPyramid\n");
#endif
}
void resetImagePyramids(const cv::Mat undCvImage, const cv::Mat defCvImage,
const cv::Mat nxtCvImage, const int start_,
const int step_, const int stop_);
void newNxtPyramid(const cv::Mat nxtCvImage);
void makeUndPyramidFromDef();
void makeDefPyramidFromNxt();
cudaTextureObject_t getUndTexture(int level_);
cudaTextureObject_t getDefTexture(int level_);
int getPyramidStart();
int getPyramidStep();
int getPyramidStop();
// Methods to make the polygons
void resetPolygon(int iSector, int x0, int y0, int x1, int y1,
fittingModelEnum fittingModel_);
void resetPolygon(int iSector, float r, float dr, float a, float da, float cx,
float cy, int as, fittingModelEnum fittingModel_);
void resetPolygon(v_points blobContour, fittingModelEnum fittingModel_);
// Accessor methods for the polygons
v_points getUndXY0ToCPU(int iSector);
v_points getDefXY0ToCPU(int iSector);
int getNumberOfPoints(int iSector, int level_);
float *getUndXPtr(int iSector, int level_);
float *getUndYPtr(int iSector, int level_);
float *getUndCenter(int iSector, int level_);
float *getGlobalABChi(int iSector);
float *getParameters(int iSector, parameterTypeEnum parSrc);
void initializeParametersLevel0(int iSector, float *initialGuess_);
void transferParameters(int iSector, parameterTypeEnum parSrc,
parameterTypeEnum parDst);
void updateParameters(int iSector, int numberOfModelParameters,
parameterTypeEnum parSrc, parameterTypeEnum parDst,
cudaStream_t stream);
void scaleParametersForLevel(int iSector, int level_);
CorrelationResult *getCorrelationResultsToCPU(int iSector);
void updatePolygon(int iSector,
deformationDescriptionEnum deformationDescription);
};
#endif // CUDA_PYRAMID_CUH