forked from AndiH/CUDA-Hough-Transform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AhTwoArraysToMatrix.h
118 lines (98 loc) · 4.48 KB
/
AhTwoArraysToMatrix.h
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
#ifndef TWOARRAYSTOMATRIX_H
#define TWOARRAYSTOMATRIX_H
#include <cusp/coo_matrix.h>
#include <cusp/print.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/functional.h>
#include <thrust/extrema.h>
#include <thrust/transform.h>
#include <thrust/sort.h>
#include <thrust/reduce.h>
#include <thrust/inner_product.h>
#include <thrust/iterator/zip_iterator.h>
#include "TH2D.h"
#include "TMatrixD.h"
#include "TStopwatch.h"
class AhTwoArraysToMatrix
{
public:
AhTwoArraysToMatrix();
AhTwoArraysToMatrix(thrust::host_vector<double>, thrust::host_vector<double>, int, double, double, int, double, double, bool doTiming = false, bool doBoundaryCheck = false);
virtual ~AhTwoArraysToMatrix();
void SetXValues(thrust::host_vector<double> _xvalues) { fXValues = _xvalues; };
void SetYValues(thrust::host_vector<double> _yvalues) { fYValues = _yvalues; };
void SetNBinsX(int _nbinsx) { fNBinsX = _nbinsx; };
void SetNBinsY(int _nbinsy) { fNBinsY = _nbinsy; };
void SetXlow(double _xlow) { fXlow = _xlow; };
void SetXup(double _xup) { fXup = _xup; };
void SetYlow(double _ylow) { fYlow = _ylow; };
void SetYup(double _yup) { fYup = _yup; };
thrust::device_vector<int> TranslateValuesToMatrixCoordinates (const thrust::device_vector<double>&, double, double);
thrust::device_vector<double> RetranslateValuesFromMatrixCoordinates (const thrust::device_vector<int> &values, double inverseStepWidth, double lowValue);
bool DoBoundaryCheck();
void DoTranslations();
void DoRetranslations();
void CalculateHistogram();
cusp::coo_matrix<int, double, cusp::device_memory> GetCUSPMatrix() {return fCUSPMatrix;}
TMatrixD GetTMatrixD();
TH2D * GetHistogram();
int GetNBinsX() { return fNBinsX; };
int GetNBinsY() { return fNBinsY; };
double GetXlow() { return fXlow; };
double GetXup() { return fXup; };
double GetYlow() { return fYlow; };
double GetYup() { return fYup; };
thrust::device_vector<int> GetPlainXValues();
thrust::device_vector<int> GetPlainYValues();
thrust::device_vector<double> GetMultiplicities();
thrust::device_vector<double> GetBinContent() { return GetMultiplicities(); };
thrust::device_vector<thrust::tuple<int, int, double> > GetPlainMatrixValues();
thrust::device_vector<thrust::tuple<double, double, double> > GetRetranslatedMatrixValues();
double GetTimeTranslateValues() { return fTimeTranslateValues; }; // in MILLI seconds, see http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDART__EVENT_g14c387cc57ce2e328f6669854e6020a5.html
double GetTimeHistSort() { return fTimeHistSort; }; // in MILLI seconds
double GetTimeHistSum() { return fTimeHistSum; }; // in MILLI seconds
double GetTimeCreateTMatrixD() { return fSwCreateTMatrixD->CpuTime(); }; // in SECONDS
double GetTimeCreateTH2D() { return fSwCreateTH2D->CpuTime(); }; // in SECONDS
protected:
// Not used, just kept here for ... well... I don't know for what
TStopwatch * GetSwTranslateValues() { return fSwTranslateValues; }; // breaks if fDoTiming is not set to true
TStopwatch * GetSwHistSort() { return fSwHistSort; }; // breaks if fDoTiming is not set to true
TStopwatch * GetSwHistSum() { return fSwHistSum; }; // breaks if fDoTiming is not set to true
TStopwatch * GetSwCreateTMatrixD() { return fSwCreateTMatrixD; }; // breaks if fDoTiming is not set to true
TStopwatch * GetSwCreateTH2D() { return fSwCreateTH2D; }; // breaks if fDoTiming is not set to true
private:
template <class T>
thrust::device_vector<T> CuspVectorToDeviceVector(const cusp::array1d<T, cusp::device_memory> &cuspvec);
bool fDoTiming;
thrust::device_vector<double> fXValues;
thrust::device_vector<double> fYValues;
thrust::device_vector<int> fTranslatedXValues;
thrust::device_vector<int> fTranslatedYValues;
thrust::device_vector<double> fRetranslatedXValues;
thrust::device_vector<double> fRetranslatedYValues;
int fNBinsX;
int fNBinsY;
double fXlow;
double fXup;
double fYlow;
double fYup;
cusp::coo_matrix<int, double, cusp::device_memory> fCUSPMatrix;
double fXStepWidth;
double fYStepWidth;
bool fReTranslationHasBeenDone;
// Stuff for timing purposes
TStopwatch * fSwTranslateValues;
TStopwatch * fSwHistSort;
TStopwatch * fSwHistSum;
TStopwatch * fSwCreateTMatrixD;
TStopwatch * fSwCreateTH2D;
cudaEvent_t start, stop;
float fTimeTranslateValues;
float fTimeHistSort;
float fTimeHistSum;
cusp::array1d<int, cusp::device_memory> fI;
cusp::array1d<int, cusp::device_memory> fJ;
cusp::array1d<double, cusp::device_memory> fV;
};
#endif //TWOARRAYSTOMATRIX_H