GNSS-SDR  0.0.19
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", Birkhauser, 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  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
29  * This file is part of GNSS-SDR.
30  *
31  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
32  * SPDX-License-Identifier: GPL-3.0-or-later
33  *
34  * -----------------------------------------------------------------------------
35  */
36 
37 #ifndef GNSS_SDR_PCPS_OPENCL_ACQUISITION_CC_H
38 #define GNSS_SDR_PCPS_OPENCL_ACQUISITION_CC_H
39 
40 #define CL_SILENCE_DEPRECATION
41 #include "channel_fsm.h"
42 #include "gnss_block_interface.h"
43 #include "gnss_sdr_fft.h"
44 #include "gnss_synchro.h"
45 #include "opencl/fft_internal.h"
46 #include <gnuradio/block.h>
47 #include <gnuradio/gr_complex.h>
48 #include "opencl/cl.hpp"
49 #include <cstdint>
50 #include <fstream>
51 #include <memory> // for weak_ptr
52 #include <string>
53 #include <vector>
54 
55 /** \addtogroup Acquisition
56  * \{ */
57 /** \addtogroup Acq_gnuradio_blocks
58  * \{ */
59 
60 
62 
63 using pcps_opencl_acquisition_cc_sptr = gnss_shared_ptr<pcps_opencl_acquisition_cc>;
64 
65 pcps_opencl_acquisition_cc_sptr pcps_make_opencl_acquisition_cc(
66  uint32_t sampled_ms,
67  uint32_t max_dwells,
68  uint32_t doppler_max,
69  int64_t fs_in,
70  int samples_per_ms,
71  int samples_per_code,
72  bool bit_transition_flag,
73  bool dump,
74  const std::string& dump_filename,
75  bool enable_monitor_output);
76 
77 /*!
78  * \brief This class implements a Parallel Code Phase Search Acquisition.
79  *
80  * Check \ref Navitec2012 "An Open Source Galileo E1 Software Receiver",
81  * Algorithm 1, for a pseudocode description of this implementation.
82  */
83 class pcps_opencl_acquisition_cc : public gr::block
84 {
85 public:
86  /*!
87  * \brief Default destructor.
88  */
90 
91  /*!
92  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
93  * to exchange synchronization data between acquisition and tracking blocks.
94  * \param p_gnss_synchro Satellite information shared by the processing blocks.
95  */
96  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
97  {
98  d_gnss_synchro = p_gnss_synchro;
99  }
100 
101  /*!
102  * \brief Returns the maximum peak of grid search.
103  */
104  inline uint32_t mag() const
105  {
106  return d_mag;
107  }
108 
109  /*!
110  * \brief Initializes acquisition algorithm.
111  */
112  void init();
113 
114  /*!
115  * \brief Sets local code for PCPS acquisition algorithm.
116  * \param code - Pointer to the PRN code.
117  */
118  void set_local_code(std::complex<float>* code);
119 
120  /*!
121  * \brief Starts acquisition algorithm, turning from standby mode to
122  * active mode
123  * \param active - bool that activates/deactivates the block.
124  */
125  inline void set_active(bool active)
126  {
127  d_active = active;
128  }
129 
130  /*!
131  * \brief If set to 1, ensures that acquisition starts at the
132  * first available sample.
133  * \param state - int=1 forces start of acquisition
134  */
135  void set_state(int state);
136 
137  /*!
138  * \brief Set acquisition channel unique ID
139  * \param channel - receiver channel.
140  */
141  inline void set_channel(uint32_t channel)
142  {
143  d_channel = channel;
144  }
145 
146  /*!
147  * \brief Set channel fsm associated to this acquisition instance
148  */
149  inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm)
150  {
151  d_channel_fsm = channel_fsm;
152  }
153 
154  /*!
155  * \brief Set statistics threshold of PCPS algorithm.
156  * \param threshold - Threshold for signal detection (check \ref Navitec2012,
157  * Algorithm 1, for a definition of this threshold).
158  */
159  inline void set_threshold(float threshold)
160  {
161  d_threshold = threshold;
162  }
163 
164  /*!
165  * \brief Set maximum Doppler grid search
166  * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
167  */
168  inline void set_doppler_max(uint32_t doppler_max)
169  {
170  d_doppler_max = doppler_max;
171  }
172 
173  /*!
174  * \brief Set Doppler steps for the grid search
175  * \param doppler_step - Frequency bin of the search grid [Hz].
176  */
177  inline void set_doppler_step(uint32_t doppler_step)
178  {
179  d_doppler_step = doppler_step;
180  }
181 
182  inline bool opencl_ready() const
183  {
184  bool ready = false;
185  if (d_opencl == 0)
186  {
187  ready = true;
188  }
189  return ready;
190  }
191 
192  void acquisition_core_volk();
193 
194  void acquisition_core_opencl();
195 
196  /*!
197  * \brief Parallel Code Phase Search Acquisition signal processing.
198  */
199  int general_work(int noutput_items, gr_vector_int& ninput_items,
200  gr_vector_const_void_star& input_items,
201  gr_vector_void_star& output_items);
202 
203 private:
204  friend pcps_opencl_acquisition_cc_sptr
205  pcps_make_opencl_acquisition_cc(uint32_t sampled_ms, uint32_t max_dwells,
206  uint32_t doppler_max, int64_t fs_in,
207  int samples_per_ms, int samples_per_code,
208  bool bit_transition_flag,
209  bool dump,
210  const std::string& dump_filename,
211  bool enable_monitor_output);
212 
213  pcps_opencl_acquisition_cc(uint32_t sampled_ms, uint32_t max_dwells,
214  uint32_t doppler_max, int64_t fs_in,
215  int samples_per_ms, int samples_per_code,
216  bool bit_transition_flag,
217  bool dump,
218  const std::string& dump_filename,
219  bool enable_monitor_output);
220 
221  void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift,
222  int doppler_offset);
223 
224  int init_opencl_environment(const std::string& kernel_filename);
225 
226  cl::Platform d_cl_platform;
227  cl::Device d_cl_device;
228  cl::Context d_cl_context;
229  cl::Program d_cl_program;
230  cl::Buffer* d_cl_buffer_in;
231  cl::Buffer* d_cl_buffer_fft_codes;
232  cl::Buffer* d_cl_buffer_1;
233  cl::Buffer* d_cl_buffer_2;
234  cl::Buffer* d_cl_buffer_magnitude;
235  cl::Buffer** d_cl_buffer_grid_doppler_wipeoffs;
236  cl::CommandQueue* d_cl_queue;
237  clFFT_Plan d_cl_fft_plan;
238  cl_int d_cl_fft_batch_size;
239 
240  std::weak_ptr<ChannelFsm> d_channel_fsm;
241 
242  std::unique_ptr<gnss_fft_complex_fwd> d_fft_if;
243  std::unique_ptr<gnss_fft_complex_rev> d_ifft;
244 
245  std::vector<std::vector<gr_complex>> d_grid_doppler_wipeoffs;
246  std::vector<std::vector<gr_complex>> d_in_buffer;
247  std::vector<gr_complex> d_fft_codes;
248  std::vector<gr_complex> d_zero_vector;
249  std::vector<uint64_t> d_sample_counter_buffer;
250  std::vector<float> d_magnitude;
251 
252  std::string d_dump_filename;
253  std::string d_satellite_str;
254 
255  std::ofstream d_dump_file;
256 
257  Gnss_Synchro* d_gnss_synchro;
258 
259  int64_t d_fs_in;
260  uint64_t d_sample_counter;
261 
262  int* d_max_doppler_indexs;
263 
264  float d_threshold;
265  float d_doppler_freq;
266  float d_mag;
267  float d_input_power;
268  float d_test_statistics;
269 
270  int d_samples_per_ms;
271  int d_samples_per_code;
272  int d_state;
273  int d_opencl;
274 
275  uint32_t d_doppler_resolution;
276  uint32_t d_doppler_max;
277  uint32_t d_doppler_step;
278  uint32_t d_sampled_ms;
279  uint32_t d_max_dwells;
280  uint32_t d_well_count;
281  uint32_t d_fft_size;
282  uint32_t d_fft_size_pow2;
283  uint32_t d_num_doppler_bins;
284  uint32_t d_code_phase;
285  uint32_t d_channel;
286  uint32_t d_in_dwell_count;
287 
288  bool d_bit_transition_flag;
289  bool d_active;
290  bool d_core_working;
291  bool d_dump;
292  bool d_enable_monitor_output;
293 };
294 
295 
296 /** \} */
297 /** \} */
298 #endif // GNSS_SDR_PCPS_OPENCL_ACQUISITION_CC_H
Helper file for FFT interface.
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:38
This interface represents a GNSS block.
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.