GNSS-SDR  0.0.21
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 "acq_conf.h"
43 #include "channel_fsm.h"
44 #include "gnss_block_interface.h"
45 #include "gnss_sdr_fft.h"
46 #include "gnss_synchro.h"
47 #include "opencl/fft_internal.h"
48 #include <gnuradio/block.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 
57 /** \addtogroup Acquisition
58  * \{ */
59 /** \addtogroup Acq_gnuradio_blocks
60  * \{ */
61 
62 
64 
65 using pcps_opencl_acquisition_cc_sptr = gnss_shared_ptr<pcps_opencl_acquisition_cc>;
66 
67 pcps_opencl_acquisition_cc_sptr pcps_make_opencl_acquisition_cc(const Acq_Conf& conf, uint32_t max_dwells);
68 
69 /*!
70  * \brief This class implements a Parallel Code Phase Search Acquisition.
71  *
72  * Check \ref Navitec2012 "An Open Source Galileo E1 Software Receiver",
73  * Algorithm 1, for a pseudocode description of this implementation.
74  */
76 {
77 public:
78  /*!
79  * \brief Default destructor.
80  */
82 
83  /*!
84  * \brief Set acquisition/tracking common Gnss_Synchro object pointer
85  * to exchange synchronization data between acquisition and tracking blocks.
86  * \param p_gnss_synchro Satellite information shared by the processing blocks.
87  */
88  inline void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) override
89  {
90  d_gnss_synchro = p_gnss_synchro;
91  }
92 
93  /*!
94  * \brief Returns the maximum peak of grid search.
95  */
96  inline uint32_t mag() const override
97  {
98  return d_mag;
99  }
100 
101  /*!
102  * \brief Sets local code for PCPS acquisition algorithm.
103  * \param code - Pointer to the PRN code.
104  */
105  void set_local_code(std::complex<float>* code) override;
106 
107  /*!
108  * \brief Starts acquisition algorithm, turning from standby mode to
109  * active mode
110  * \param active - bool that activates/deactivates the block.
111  */
112  inline void set_active(bool active) override
113  {
114  if (!active)
115  {
116  d_state = 0;
117  }
118 
119  d_active = active;
120  }
121 
122  /*!
123  * \brief Set acquisition channel unique ID
124  * \param channel - receiver channel.
125  */
126  inline void set_channel(uint32_t channel) override
127  {
128  d_channel = channel;
129  }
130 
131  /*!
132  * \brief Set channel fsm associated to this acquisition instance
133  */
134  inline void set_channel_fsm(std::weak_ptr<ChannelFsm> channel_fsm) override
135  {
136  d_channel_fsm = channel_fsm;
137  }
138 
139  inline bool opencl_ready() const
140  {
141  bool ready = false;
142  if (d_opencl == 0)
143  {
144  ready = true;
145  }
146  return ready;
147  }
148 
149  void acquisition_core_volk();
150 
151  void acquisition_core_opencl();
152 
153  /*!
154  * \brief Parallel Code Phase Search Acquisition signal processing.
155  */
156  int general_work(int noutput_items, gr_vector_int& ninput_items,
157  gr_vector_const_void_star& input_items,
158  gr_vector_void_star& output_items) override;
159 
160 private:
161  friend pcps_opencl_acquisition_cc_sptr
162  pcps_make_opencl_acquisition_cc(const Acq_Conf& conf, uint32_t max_dwells);
163 
164  explicit pcps_opencl_acquisition_cc(const Acq_Conf& conf, uint32_t max_dwells);
165 
166  void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, int doppler_offset);
167 
168  int init_opencl_environment(const std::string& kernel_filename);
169 
170  cl::Platform d_cl_platform;
171  cl::Device d_cl_device;
172  cl::Context d_cl_context;
173  cl::Program d_cl_program;
174  cl::Buffer* d_cl_buffer_in;
175  cl::Buffer* d_cl_buffer_fft_codes;
176  cl::Buffer* d_cl_buffer_1;
177  cl::Buffer* d_cl_buffer_2;
178  cl::Buffer* d_cl_buffer_magnitude;
179  cl::Buffer** d_cl_buffer_grid_doppler_wipeoffs;
180  cl::CommandQueue* d_cl_queue;
181  clFFT_Plan d_cl_fft_plan;
182  cl_int d_cl_fft_batch_size;
183 
184  std::string d_satellite_str;
185  const Acq_Conf d_acq_params;
186 
187  std::ofstream d_dump_file;
188 
189  Gnss_Synchro* d_gnss_synchro;
190 
191  uint64_t d_sample_counter;
192 
193  int* d_max_doppler_indexs;
194 
195  float d_mag;
196  float d_input_power;
197  float d_test_statistics;
198 
199  int d_state;
200  int d_opencl;
201 
202  uint32_t d_max_dwells;
203  uint32_t d_well_count;
204  const uint32_t d_fft_size;
205  uint32_t d_fft_size_pow2;
206  uint32_t d_num_doppler_bins;
207  uint32_t d_code_phase;
208  uint32_t d_channel;
209  uint32_t d_in_dwell_count;
210 
211  bool d_active;
212  bool d_core_working;
213 
214  std::weak_ptr<ChannelFsm> d_channel_fsm;
215 
216  std::unique_ptr<gnss_fft_complex_fwd> d_fft_if;
217  std::unique_ptr<gnss_fft_complex_rev> d_ifft;
218 
219  std::vector<std::vector<gr_complex>> d_grid_doppler_wipeoffs;
220  std::vector<std::vector<gr_complex>> d_in_buffer;
221  std::vector<gr_complex> d_fft_codes;
222  std::vector<gr_complex> d_zero_vector;
223  std::vector<uint64_t> d_sample_counter_buffer;
224  std::vector<float> d_magnitude;
225 };
226 
227 
228 /** \} */
229 /** \} */
230 #endif // GNSS_SDR_PCPS_OPENCL_ACQUISITION_CC_H
Helper file for FFT interface.
Header file of the interface to an acquisition implementation GNSS block.
void set_active(bool active) override
Starts acquisition algorithm, turning from standby mode to active mode.
void set_gnss_synchro(Gnss_Synchro *p_gnss_synchro) override
Set acquisition/tracking common Gnss_Synchro object pointer to exchange synchronization data between ...
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
Parallel Code Phase Search Acquisition signal processing.
Internals of FFT for OpenCL.
Class that contains all the configuration parameters for generic acquisition block based on the PCPS ...
Interface of the State Machine for channel.
uint32_t mag() const override
Returns the maximum peak of grid search.
This is the class that contains the information that is shared by the processing blocks.
Definition: gnss_synchro.h:38
void set_channel(uint32_t channel) override
Set acquisition channel unique ID.
This interface represents a GNSS block.
void set_local_code(std::complex< float > *code) override
Sets local code for PCPS acquisition algorithm.
This class implements a Parallel Code Phase Search Acquisition.
~pcps_opencl_acquisition_cc()
Default destructor.
This abstract class represents an interface to an acquisition GNSS block.
Interface of the Gnss_Synchro class.
void set_channel_fsm(std::weak_ptr< ChannelFsm > channel_fsm) override
Set channel fsm associated to this acquisition instance.