Changeset 8332
- Timestamp:
- 05/08/08 19:51:32
- Files:
-
- gnuradio/branches/releases/3.1/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc (modified) (6 diffs)
- gnuradio/branches/releases/3.1/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h (modified) (1 diff)
- gnuradio/branches/releases/3.1/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gnuradio/branches/releases/3.1/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.cc
r6207 r8332 63 63 64 64 gr_block_detail_sptr 65 gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block , gr_block_detail_sptr old_detail)65 gr_flat_flowgraph::allocate_block_detail(gr_basic_block_sptr block) 66 66 { 67 67 int ninputs = calc_used_ports(block, true).size(); … … 72 72 std::cout << "Creating block detail for " << block << std::endl; 73 73 74 // Re-use or allocate output buffers75 74 for (int i = 0; i < noutputs; i++) { 76 gr_buffer_sptr buffer; 77 78 if (!old_detail || i >= old_detail->noutputs()) { 79 if (GR_FLAT_FLOWGRAPH_DEBUG) 80 std::cout << "Allocating new buffer for output " << i << std::endl; 81 buffer = allocate_buffer(block, i); 82 } 83 else { 84 if (GR_FLAT_FLOWGRAPH_DEBUG) 85 std::cout << "Reusing old buffer for output " << i << std::endl; 86 buffer = old_detail->output(i); 87 } 88 75 gr_buffer_sptr buffer = allocate_buffer(block, i); 76 if (GR_FLAT_FLOWGRAPH_DEBUG) 77 std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; 89 78 detail->set_output(i, buffer); 90 79 } … … 157 146 gr_flat_flowgraph::merge_connections(gr_flat_flowgraph_sptr old_ffg) 158 147 { 159 std::map<gr_block_sptr, gr_block_detail_sptr> old_details;160 161 // Allocate or reuse output buffers148 // Allocate block details if needed. Only new blocks that aren't pruned out 149 // by flattening will need one; existing blocks still in the new flowgraph will 150 // already have one. 162 151 for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { 163 152 gr_block_sptr block = make_gr_block_sptr(*p); 164 165 gr_block_detail_sptr old_detail = block->detail(); 166 block->set_detail(allocate_block_detail(block, old_detail)); 167 168 // Save old detail for use in next step 169 old_details[block] = old_detail; 170 } 171 153 154 if (!block->detail()) { 155 if (GR_FLAT_FLOWGRAPH_DEBUG) 156 std::cout << "merge: allocating new detail for block " << (*p) << std::endl; 157 block->set_detail(allocate_block_detail(block)); 158 } 159 else 160 if (GR_FLAT_FLOWGRAPH_DEBUG) 161 std::cout << "merge: reusing original detail for block " << (*p) << std::endl; 162 } 163 164 // Calculate the old edges that will be going away, and clear the buffer readers 165 // on the RHS. 166 for (gr_edge_viter_t old_edge = old_ffg->d_edges.begin(); old_edge != old_ffg->d_edges.end(); old_edge++) { 167 if (GR_FLAT_FLOWGRAPH_DEBUG) 168 std::cout << "merge: testing old edge " << (*old_edge) << "..."; 169 170 gr_edge_viter_t new_edge; 171 for (new_edge = d_edges.begin(); new_edge != d_edges.end(); new_edge++) 172 if (new_edge->src() == old_edge->src() && 173 new_edge->dst() == old_edge->dst()) 174 break; 175 176 if (new_edge == d_edges.end()) { // not found in new edge list 177 if (GR_FLAT_FLOWGRAPH_DEBUG) 178 std::cout << "not in new edge list" << std::endl; 179 // zero the buffer reader on RHS of old edge 180 gr_block_sptr block(make_gr_block_sptr(old_edge->dst().block())); 181 int port = old_edge->dst().port(); 182 block->detail()->set_input(port, gr_buffer_reader_sptr()); 183 } 184 else { 185 if (GR_FLAT_FLOWGRAPH_DEBUG) 186 std::cout << "found in new edge list" << std::endl; 187 } 188 } 189 190 // Now connect inputs to outputs, reusing old buffer readers if they exist 172 191 for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { 173 192 gr_block_sptr block = make_gr_block_sptr(*p); 174 193 175 194 if (GR_FLAT_FLOWGRAPH_DEBUG) 176 std::cout << "merge: testing " << (*p) << "...";195 std::cout << "merge: merging " << (*p) << "..."; 177 196 178 197 if (old_ffg->has_block_p(*p)) { … … 181 200 std::cout << "used in old flow graph" << std::endl; 182 201 gr_block_detail_sptr detail = block->detail(); 183 202 184 203 // Iterate through the inputs and see what needs to be done 185 for (int i = 0; i < detail->ninputs(); i++) { 204 int ninputs = calc_used_ports(block, true).size(); // Might be different now 205 for (int i = 0; i < ninputs; i++) { 186 206 if (GR_FLAT_FLOWGRAPH_DEBUG) 187 std::cout << "Checking input " << i << "...";207 std::cout << "Checking input " << block << ":" << i << "..."; 188 208 gr_edge edge = calc_upstream_edge(*p, i); 189 209 … … 193 213 gr_buffer_sptr src_buffer = src_detail->output(edge.src().port()); 194 214 gr_buffer_reader_sptr old_reader; 195 gr_block_detail_sptr old_detail = old_details[block]; 196 if (old_detail && i < old_detail->ninputs()) 197 old_reader = old_detail->input(i); 215 if (i < detail->ninputs()) // Don't exceed what the original detail has 216 old_reader = detail->input(i); 198 217 199 218 // If there's a match, use it 200 219 if (old_reader && (src_buffer == old_reader->buffer())) { 201 220 if (GR_FLAT_FLOWGRAPH_DEBUG) 202 std::cout << "matched" << std::endl; 203 detail->set_input(i, old_reader); 204 221 std::cout << "matched, reusing" << std::endl; 205 222 } 206 223 else { … … 219 236 connect_block_inputs(block); 220 237 } 238 239 // Now deal with the fact that the block details might have changed numbers of 240 // inputs and outputs vs. in the old flowgraph. 221 241 } 222 242 } 223 243 244 void gr_flat_flowgraph::dump() 245 { 246 for (gr_edge_viter_t e = d_edges.begin(); e != d_edges.end(); e++) 247 std::cout << " edge: " << (*e) << std::endl; 248 249 for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { 250 std::cout << " block: " << (*p) << std::endl; 251 gr_block_detail_sptr detail = make_gr_block_sptr(*p)->detail(); 252 std::cout << " detail @" << detail << ":" << std::endl; 253 254 int ni = detail->ninputs(); 255 int no = detail->noutputs(); 256 for (int i = 0; i < no; i++) { 257 gr_buffer_sptr buffer = detail->output(i); 258 std::cout << " output " << i << ": " << buffer 259 << " space=" << buffer->space_available() << std::endl; 260 } 261 262 for (int i = 0; i < ni; i++) { 263 gr_buffer_reader_sptr reader = detail->input(i); 264 std::cout << " reader " << i << ": " << reader 265 << " reading from buffer=" << reader->buffer() 266 << " avail=" << reader->items_available() << " items" 267 << std::endl; 268 } 269 } 270 271 } gnuradio/branches/releases/3.1/gnuradio-core/src/lib/runtime/gr_flat_flowgraph.h
r7517 r8332 54 54 void merge_connections(gr_flat_flowgraph_sptr sfg); 55 55 56 void dump(); 57 56 58 private: 57 59 gr_flat_flowgraph(); 58 60 59 61 static const unsigned int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE; 60 gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block, 61 gr_block_detail_sptr old_detail=gr_block_detail_sptr()); 62 gr_block_detail_sptr allocate_block_detail(gr_basic_block_sptr block); 62 63 gr_buffer_sptr allocate_buffer(gr_basic_block_sptr block, int port); 63 64 void connect_block_inputs(gr_basic_block_sptr block); gnuradio/branches/releases/3.1/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
r8054 r8332 216 216 gr_flat_flowgraph_sptr new_ffg = d_owner->flatten(); 217 217 new_ffg->validate(); // check consistency, sanity, etc 218 219 if (GR_TOP_BLOCK_IMPL_DEBUG) { 220 std::cout << std::endl << "*** Existing flat flowgraph @" << d_ffg << ":" << std::endl; 221 d_ffg->dump(); 222 } 218 223 new_ffg->merge_connections(d_ffg); // reuse buffers, etc 219 224 220 if (GR_TOP_BLOCK_IMPL_DEBUG) 221 std::cout << "restart: replacing old flow graph with new" << std::endl; 225 if (GR_TOP_BLOCK_IMPL_DEBUG) { 226 std::cout << std::endl << "*** New flat flowgraph after merge @" << new_ffg << ":" << std::endl; 227 new_ffg->dump(); 228 } 229 222 230 d_ffg = new_ffg; 223 231
