GNSS-SDR  0.0.13
An Open Source GNSS Software Defined Receiver
pcps_opencl_acquisition_cc.h
Go to the documentation of this file.
1 /*!
2  * \file pcps_opencl_acquisition_cc.h
3  * \brief This class implements a Parallel Code Phase Search Acquisition
4  * using OpenCL to offload some functions to the GPU.
5  *
6  * Acquisition strategy (Kay Borre book + CFAR threshold).
7  * <ol>
8  * <li> Compute the input signal power estimation
9  * <li> Doppler serial search loop
10  * <li> Perform the FFT-based circular convolution (parallel time search)
11  * <li> Record the maximum peak and the associated synchronization parameters
12  * <li> Compute the test statistics and compare to the threshold
13  * <li> Declare positive or negative acquisition using a message port
14  * </ol>
15  *
16  * Kay Borre book: K.Borre, D.M.Akos, N.Bertelsen, P.Rinder, and S.H.Jensen,
17  * "A Software-Defined GPS and Galileo Receiver. A Single-Frequency
18  * Approach", Birkha user, 2007. pp 81-84
19  *
20  * \authors <ul>
21  * <li> Javier Arribas, 2011. jarribas(at)cttc.es
22  * <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com
23  * <li> Marc Molina, 2013. marc.molina.pena@gmail.com
24  * </ul>
25  *
26  * -----------------------------------------------------------------------------
27  *
28  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
29  *
30  * GNSS-SDR is a software defined Global Navigation
31  * Satellite Systems receiver
32  *
33  * This file is part of GNSS-SDR.
34  *
35  * SPDX-License-Identifier: GPL-3.0-or-later
36  *
37  * -----------------------------------------------------------------------------
38  */
39 
40 #ifndef GNSS_SDR_PCPS_OPENCL_ACQUISITION_CC_H
41 #define GNSS_SDR_PCPS_OPENCL_ACQUISITION_CC_H
42 
43 #define CL_SILENCE_DEPRECATION
44 #include "channel_fsm.h"
45 #include "gnss_synchro.h"
46 #include "opencl/fft_internal.h"
47 #include <gnuradio/block.h>
48 #include <gnuradio/fft/fft.h>
49 #include <gnuradio/gr_complex.h>
50 #include "opencl/cl.hpp"
51 #include <cstdint>
52 #include <fstream>
53 #include <memory> // for weak_ptr
54 #include <string>
55 #include <vector>
56 #if GNURADIO_USES_STD_POINTERS
57 #else
58 #include <boost/shared_ptr.hpp>
59 #endif
60 
62 
63 #if GNURADIO_USES_STD_POINTERS
64 typedef std::shared_ptr<pcps_opencl_acquisition_cc> pcps_opencl_acquisition_cc_sptr;
65 #else
66 typedef boost::shared_ptr<pcps_opencl_acquisition_cc> pcps_opencl_acquisition_cc_sptr;
67 #endif
68 
69 pcps_opencl_acquisition_cc_sptr pcps_make_opencl_acquisition_cc(
70  uint32_t sampled_ms,
71  uint32_t max_dwells,
72  uint32_t doppler_max,
73  int64_t fs_in,
74  int samples_per_ms,
75  int samples_per_code,
76  bool bit_transition_flag,
77  bool dump,
78  const std::string& dump_filename);
79 
80 /*!
81  * \brief This class implements a Parallel Code Phase Search Acquisition.
82  *
83  * Check \ref Navitec2012 "An Open Source Galileo E1 Software Receiver",
84  * Algorithm 1, for a pseudocode description of this implementation.
85  */
86 class pcps_opencl_acquisition_cc : public gr::block
87 {
88 public:
89  /*!
90  * \brief Default destructor.
91  */
93 
94  /*!
95  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
96  * to exchange synchronization data between acquisition and tracking blocks.
97  * \param p_gnss_synchro Satellite information shared by the processing blocks.
98  */
99  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
100  {
101  d_gnss_synchro = p_gnss_synchro;
102  }
103 
104  /*!
105  * \brief Returns the maximum peak of grid search.
106  */
107  inline uint32_t mag() const
108  {
109  return d_mag;
110  }
111 
112  /*!
113  * \brief Initializes acquisition algorithm.
114  */
115  void init();
116 
117  /*!
118  * \brief Sets local code for PCPS acquisition algorithm.
119  * \param code - Pointer to the PRN code.
120  */
121  void set_local_code(std::complex<float>* code);
122 
123  /*!
124  * \brief Starts acquisition algorithm, turning from standby mode to
125  * active mode
126  * \param active - bool that activates/deactivates the block.
127  */
128  inline void set_active(bool active)
129  {
130  d_active = active;
131  }
132 
133  /*!
134  * \brief If set to 1, ensures that acquisition starts at the
135  * first available sample.
136  * \param state - int=1 forces start of acquisition
137  */
138  void set_state(int state);
139 
140  /*!
141  * \brief Set acquisition channel unique ID
142  * \param channel - receiver channel.
143  */
144  inline void set_channel(uint32_t channel)
145  {
146  d_channel = channel;
147  }
148 
149  /*!
150  * \brief Set channel fsm associated to this acquisition instance
151  */
152  inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm)
153  {
154  d_channel_fsm = channel_fsm;
155  }
156 
157  /*!
158  * \brief Set statistics threshold of PCPS algorithm.
159  * \param threshold - Threshold for signal detection (check \ref Navitec2012,
160  * Algorithm 1, for a definition of this threshold).
161  */
162  inline void set_threshold(float threshold)
163  {
164  d_threshold = threshold;
165  }
166 
167  /*!
168  * \brief Set maximum Doppler grid search
169  * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
170  */
171  inline void set_doppler_max(uint32_t doppler_max)
172  {
173  d_doppler_max = doppler_max;
174  }
175 
176  /*!
177  * \brief Set Doppler steps for the grid search
178  * \param doppler_step - Frequency bin of the search grid [Hz].
179  */
180  inline void set_doppler_step(uint32_t doppler_step)
181  {
182  d_doppler_step = doppler_step;
183  }
184 
185  inline bool opencl_ready() const
186  {
187  bool ready = false;
188  if (d_opencl == 0)
189  {
190  ready = true;
191  }
192  return ready;
193  }
194 
195  void acquisition_core_volk();
196 
197  void acquisition_core_opencl();
198 
199  /*!
200  * \brief Parallel Code Phase Search Acquisition signal processing.
201  */
202  int general_work(int noutput_items, gr_vector_int& ninput_items,
203  gr_vector_const_void_star& input_items,
204  gr_vector_void_star& output_items);
205 
206 private:
207  friend pcps_opencl_acquisition_cc_sptr
208  pcps_make_opencl_acquisition_cc(uint32_t sampled_ms, uint32_t max_dwells,
209  uint32_t doppler_max, int64_t fs_in,
210  int samples_per_ms, int samples_per_code,
211  bool bit_transition_flag,
212  bool dump,
213  const std::string& dump_filename);
214 
215  pcps_opencl_acquisition_cc(uint32_t sampled_ms, uint32_t max_dwells,
216  uint32_t doppler_max, int64_t fs_in,
217  int samples_per_ms, int samples_per_code,
218  bool bit_transition_flag,
219  bool dump,
220  const std::string& dump_filename);
221 
222  void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift,
223  int doppler_offset);
224 
225  int init_opencl_environment(const std::string& kernel_filename);
226 
227  cl::Platform d_cl_platform;
228  cl::Device d_cl_device;
229  cl::Context d_cl_context;
230  cl::Program d_cl_program;
231  cl::Buffer* d_cl_buffer_in;
232  cl::Buffer* d_cl_buffer_fft_codes;
233  cl::Buffer* d_cl_buffer_1;
234  cl::Buffer* d_cl_buffer_2;
235  cl::Buffer* d_cl_buffer_magnitude;
236  cl::Buffer** d_cl_buffer_grid_doppler_wipeoffs;
237  cl::CommandQueue* d_cl_queue;
238  clFFT_Plan d_cl_fft_plan;
239  cl_int d_cl_fft_batch_size;
240 
241  std::weak_ptr<ChannelFsm> d_channel_fsm;
242 
243  std::unique_ptr<gr::fft::fft_complex> d_fft_if;
244  std::unique_ptr<gr::fft::fft_complex> d_ifft;
245 
246  std::vector<std::vector<gr_complex>> d_grid_doppler_wipeoffs;
247  std::vector<std::vector<gr_complex>> d_in_buffer;
248  std::vector<gr_complex> d_fft_codes;
249  std::vector<gr_complex> d_zero_vector;
250  std::vector<uint64_t> d_sample_counter_buffer;
251  std::vector<float> d_magnitude;
252 
253  std::string d_dump_filename;
254  std::string d_satellite_str;
255 
256  std::ofstream d_dump_file;
257 
258  Gnss_Synchro* d_gnss_synchro;
259 
260  int64_t d_fs_in;
261  uint64_t d_sample_counter;
262 
263  int* d_max_doppler_indexs;
264 
265  float d_threshold;
266  float d_doppler_freq;
267  float d_mag;
268  float d_input_power;
269  float d_test_statistics;
270 
271  int d_samples_per_ms;
272  int d_samples_per_code;
273  int d_state;
274  int d_opencl;
275 
276  uint32_t d_doppler_resolution;
277  uint32_t d_doppler_max;
278  uint32_t d_doppler_step;
279  uint32_t d_sampled_ms;
280  uint32_t d_max_dwells;
281  uint32_t d_well_count;
282  uint32_t d_fft_size;
283  uint32_t d_fft_size_pow2;
284  uint32_t d_num_doppler_bins;
285  uint32_t d_code_phase;
286  uint32_t d_channel;
287  uint32_t d_in_dwell_count;
288 
289  bool d_bit_transition_flag;
290  bool d_active;
291  bool d_core_working;
292  bool d_dump;
293 };
294 
295 #endif
void set_gnss_synchro(Gnss_Synchro *p_gnss_synchro)
Set acquisition/tracking common Gnss_Synchro object pointer to exchange synchronization data between ...
Internals of FFT for OpenCL.
void set_channel_fsm(std::weak_ptr< ChannelFsm > channel_fsm)
Set channel fsm associated to this acquisition instance.
uint32_t mag() const
Returns the maximum peak of grid search.
Interface of the State Machine for channel.
void set_doppler_step(uint32_t doppler_step)
Set Doppler steps for the grid search.
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:33
void set_channel(uint32_t channel)
Set acquisition channel unique ID.
void set_state(int state)
If set to 1, ensures that acquisition starts at the first available sample.
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Parallel Code Phase Search Acquisition signal processing.
void init()
Initializes acquisition algorithm.
void set_doppler_max(uint32_t doppler_max)
Set maximum Doppler grid search.
This class implements a Parallel Code Phase Search Acquisition.
void set_local_code(std::complex< float > *code)
Sets local code for PCPS acquisition algorithm.
void set_active(bool active)
Starts acquisition algorithm, turning from standby mode to active mode.
~pcps_opencl_acquisition_cc()
Default destructor.
void set_threshold(float threshold)
Set statistics threshold of PCPS algorithm.
Interface of the Gnss_Synchro class.