-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdsp.cuh
163 lines (110 loc) · 4.2 KB
/
dsp.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
//
// Created by andrei on 3/27/21.
//
#ifndef CPPMEASUREMENT_DSP_CUH
#define CPPMEASUREMENT_DSP_CUH
#include <nppdefs.h>
#include <vector>
#include <complex>
#include <cufft.h>
#include <cublas_v2.h>
const int num_streams = 4;
const int cal_mat_size = 16;
const int cal_mat_side = 4;
class dsp {
/* Pointer */
char* buffer;
/* Pointers to arrays with data */
Npp8s* gpu_buf[num_streams]; // buffers for loading data
Npp8s* gpu_buf2[num_streams]; // buffers for loading data
Npp32f* data[num_streams];
Npp32f* data_calibrated[num_streams];
Npp32f* noise[num_streams];
Npp32f* noise_calibrated[num_streams];
Npp32fc* data_complex[num_streams];
Npp32f* power[num_streams]; // arrays for storage of average power
Npp32f* field[num_streams]; // arrays for storage of average field
Npp32fc* out[num_streams];
int cnt = 0;
/* Min-max values */
Npp8u* minmaxbuffer;
Npp32f* minfield;
Npp32f* maxfield;
Npp32f min, max;
/* Filtering window */
Npp32fc* firwin;
/* Subtraction trace */
Npp32fc* subtraction_trace;
/* Downconversion coefficients */
Npp32fc* downconversion_coeffs;
private:
/* Useful variables */
int trace_length; // for keeping the length of a trace
int trace1_start, trace2_start, pitch;
int batch_size; // for keeping the number of segments in data array
int total_length; // batch_size * trace_length
int out_size;
int semaphore = 0; // for selecting the current stream
Npp32fc scale = Npp32fc{ 500.f / 128.f, 0.f }; // for conversion into mV
/* Streams' arrays */
cudaStream_t streams[num_streams];
NppStreamContext streamContexts[num_streams];
/* cuFFT required variables */
cufftHandle plans[num_streams];
/* cuBLAS required variables */
cublasHandle_t cublas_handles[num_streams];
cublasHandle_t cublas_handles2[num_streams];
/* Down-conversion calibration variables */
float* A_gpu;
Npp32fc* C_gpu;
int batch_count;
float alpha = 1.f;
float beta = 0.f;
public:
dsp(int len, int n, float part);
~dsp();
int getTraceLength();
int getTotalLength();
int getOutSize();
void setFirwin(float cutoff_l, float cutoff_r, int oversampling = 1);
void resetOutput();
int getCounter() { return cnt; }
float getMin()
{
cudaMemcpy(&min, minfield, sizeof(Npp32f) * 1, cudaMemcpyDeviceToHost);
return min;
}
float getMax()
{
cudaMemcpy(&max, maxfield, sizeof(Npp32f) * 1, cudaMemcpyDeviceToHost);
return max;
}
void compute(const char* buffer);
void getCumulativePower(std::vector <std::complex<float>>& result);
void getCumulativeField(std::vector <std::complex<float>>& result);
void getCorrelator(std::vector <std::complex<float>>& result);
void setDownConversionCalibrationParameters(float r, float phi, float offset_i, float offset_q);
void setSubtractionTrace(std::vector<std::complex<float>>& trace);
void getSubtractionTrace(std::vector <std::complex<float>>& trace);
void resetSubtractionTrace();
void createBuffer(size_t size);
void setIntermediateFrequency(float frequency, int oversampling);
char* getBufferPointer();
void setAmplitude(int ampl);
void deleteBuffer();
protected:
void handleError(cudaError_t error);
void switchStream() { semaphore = (semaphore < (num_streams - 1)) ? semaphore + 1 : 0; };
void loadDataToGPUwithPitchAndOffset(const char* buffer, Npp8s* gpu_buf, size_t pitch, size_t offset, int stream_num);
void convertDataToMilivolts(Npp32f* data, Npp8s* gpu_buf, int stream_num);
void downconvert(Npp32fc* data, int stream_num);
void applyDownConversionCalibration(Npp32f* data, Npp32f* data_calibrated, int stream_num);
void addDataToOutput(Npp32f* data, Npp32f* output, int stream_num);
void subtractDataFromOutput(Npp32f* data, Npp32f* output, int stream_num);
void applyFilter(Npp32fc* data, const Npp32fc* window, int stream_num);
void getMinMax(Npp32f* data, int stream_num);
void calculateField(int stream_num);
void calculatePower(int stream_num);
void calculateG1(int stream_num);
};
#endif //CPPMEASUREMENT_DSP_CUH