USRP_Server  2.0
A flexible, GPU-accelerated radio-frequency readout software.
USRP_server_memory_management.cpp
Go to the documentation of this file.
2 
3 
5 
7  boost::unique_lock<boost::mutex> lock(ready_mutex);
8  while (!ready)
9  {
10  ready_cond.wait(lock);
11  }
12 
13 }
15  {
16  boost::unique_lock<boost::mutex> lock(ready_mutex);
17  ready = (bool)true;
18  }
19  ready_cond.notify_all();
20 }
22  {
23  boost::unique_lock<boost::mutex> lock(ready_mutex);
24  ready = (bool)false;
25  }
26  ready_cond.notify_all();
27 }
28 
29 
30 VNA_decimator_helper::VNA_decimator_helper(int init_ppt, int init_buffer_len){
31  ppt = init_ppt;
32  buffer_len = init_buffer_len;
33 
34 
35  total_len = buffer_len;
36 
37  valid_size = (total_len/ppt);
38 
39  new0 = total_len - ppt*valid_size;
40 
41  spare_begin = total_len - new0;
42 
43 }
44 
46 
47  total_len = buffer_len + new0;
48 
49  valid_size = (total_len/ppt);
50 
51  new0 = total_len - ppt*valid_size;
52 
53  spare_begin = total_len - new0;
54 
55  //std::cout<<"valid_size: "<< valid_size<<" total_len: "<<total_len << " new0: "<< new0<<std::endl;
56 }
57 
58 
59 gp_decimator_helper::gp_decimator_helper(int buffer_len_init, int decim_init){
60 
61  //if there is a nfft means we are decimating in steps of nfft
62  decim = decim_init;
63  buffer_len = buffer_len_init;
64 
65  //initially copy the buffer at the beginning of the pointer
66  new_0 = 0;
67 
68  //there is no reminder at the beginning
69  tot_buffer_len = buffer_len;
70 
71  //calculate the valid output size
72  out_size = calculate_outsize();
73 }
74 
75 
76 //update the values. in case of different buffer length on next interation use the arg
77 void gp_decimator_helper::update(int new_buffer_len){
78  if(new_buffer_len != 0)buffer_len = new_buffer_len;
79  tot_buffer_len = new_0 + buffer_len;
80  out_size = calculate_outsize();
81  new_0 = calculate_spare();
82 }
83 
84 int gp_decimator_helper::calculate_spare(){
85  return tot_buffer_len - out_size*decim;
86 }
87 
88 int gp_decimator_helper::calculate_outsize(){
89  return std::floor(tot_buffer_len/decim);
90 }
91 
92 pfb_decimator_helper::pfb_decimator_helper(int init_decim, int init_nfft){
93  decim = init_decim;
94  nfft = init_nfft;
95 }
96 
97 void pfb_decimator_helper::update(int current_batch){
98  buffer_len = current_batch * nfft;
99  out_size = std::floor( nfft* std::floor(buffer_len/(float)nfft)/(float)decim);
100  new_0 = buffer_len - out_size;
101 }
102 
103 
104 buffer_helper::buffer_helper (int _n_tones, int _buffer_len, int _average, int _n_eff_tones){
105 
106  //static settings
107  n_tones = _n_tones;
108  buffer_len = _buffer_len;
109  average = _average;
110  n_eff_tones = _n_eff_tones;
111 
112  //initially the effective length is the buffer
113  eff_length = _buffer_len;
114 
115  current_batch = simulate_batching();
116  spare_samples = eff_length - current_batch*n_tones;
117  spare_begin = eff_length - spare_samples;
118 
119  //initially the new buffer from USRP has to be copied in the 0 position
120  new_0 = 0;
121 
122  copy_size = n_eff_tones * current_batch;
123 
124 }
125 
127 
128  //the buffer has to be copied after the reminder from las buffer
129  new_0 = spare_samples;
130 
131  //the new effective length will be the reminder + the new buffer
132  eff_length = spare_samples + buffer_len;
133 
134  //the effective batch size has to be adapted to the new effective length
135  current_batch = simulate_batching();
136 
137  copy_size = n_eff_tones * current_batch;
138  spare_samples = eff_length - current_batch*n_tones;
139  spare_begin = eff_length - spare_samples;
140 
141 
142 }
143 
144 //the formula I wrote had a defect for certain number combinations so..
145 int buffer_helper::simulate_batching(){
146 
147  int offset = 0;
148  int batching = 0;
149  while(offset + average*n_tones < eff_length){
150  offset += n_tones;
151  batching++;
152  }
153 
154  return batching;
155 
156 }
void update(int new_buffer_len=0)
gp_decimator_helper(int buffer_len_init, int decim_init)
VNA_decimator_helper(int init_ppt, int init_buffer_len)
pfb_decimator_helper(int init_decim, int init_nfft)
buffer_helper(int _n_tones, int _buffer_len, int _average, int _n_eff_tones)