@@ -293,22 +293,13 @@ bool mlir::neura::tryRouteBackwardMove(Operation *mov_op, MappingLoc src_loc,
293293Register *mlir::neura::getAvailableRegister (
294294 const MappingState &state, Tile *tile, int start_time, int exclusive_end_time) {
295295 for (Register *reg : tile->getRegisters ()) {
296+ // FIXME: We may need constrain the register availability to the conflicting
297+ // input channel (either the input channel or a register file on the same input
298+ // direction could be active at one time).
296299 if (state.isAvailableAcrossTimeInRange (reg, start_time, exclusive_end_time)) {
297- llvm::errs () << " [getAvailableRegister] Found available register: "
298- << reg->getId () << " in register_file: " << reg->getRegisterFile ()->getId ()
299- << " in register_file_cluster: "
300- << reg->getRegisterFile ()->getRegisterFileCluster ()->getId ()
301- << " at tile: " << tile->getId ()
302- << " from time step: " << start_time
303- << " to end time step: " << exclusive_end_time << " \n " ;
304300 return reg;
305301 }
306302 }
307- // llvm::errs() << "[getAvailableRegister] No available register found in tile: "
308- // << tile->getId() << " from time step: " << start_time
309- // << " to end time step: " << exclusive_end_time << "\n";
310- // llvm::errs() << "[cheng] tile->getRegisters() size: "
311- // << tile->getRegisters().size() << "\n";
312303 return nullptr ;
313304}
314305
@@ -355,50 +346,9 @@ bool mlir::neura::tryRouteDataMove(Operation *mov_op, MappingLoc src_loc,
355346 return true ;
356347 }
357348
358- // // The last link can be held from arrival_time to dst_time - 1.
359- // // TODO: We actually don't need to occupy the last link if the registers
360- // // within the tile can be explicitly represented.
361- // // https://github.com/coredac/dataflow/issues/52.
362349 assert (!current_path.empty () &&
363350 " Path should not be empty when checking last link" );
364351
365- // bool all_free = true;
366- // MappingLoc last_link_loc = current_path.back();
367- // // llvm::errs() << "[cheng] checking Last link loc: "
368- // // << last_link_loc.resource->getType() << "#"
369- // // << last_link_loc.resource->getId()
370- // // << " @t=" << last_link_loc.time_step << "\n";
371- // std::vector<MappingLoc> last_link_occupying;
372- // for (int t = current_step; t < deadline_step; ++t) {
373- // MappingLoc repeated{last_link_loc.resource, t};
374- // last_link_occupying.push_back(repeated);
375- // if (!state.isAvailableAcrossTime(repeated)) {
376- // all_free = false;
377- // // llvm::errs() << "[CHENG] target repeated: " << repeated.resource->getType() << "#"
378- // // << repeated.resource->getId() << " @t=" << repeated.time_step << "\n";
379- // // Operation *culprit_op = state.getOpAtLocAcrossTime(repeated).value();
380- // // llvm::errs() << "[DEBUG] who is occupying the last link: "
381- // // << *culprit_op << "\n";
382- // // for (auto ll : state.getAllLocsOfOp(culprit_op)) {
383- // // llvm::errs() << "[DEBUG] Occupying loc: "
384- // // << ll.resource->getType() << "#" << ll.resource->getId()
385- // // << " @t=" << ll.time_step << "\n";
386- // // }
387- // break;
388- // }
389- // }
390- // if (all_free) {
391- // path_out = current_path;
392- // path_out.insert(path_out.end(), last_link_occupying.begin(),
393- // last_link_occupying.end());
394- // return true;
395- // } else {
396- // llvm::errs() << "[tryRouteDataMove] Last link [" <<
397- // dyn_cast<Link>(last_link_loc.resource)->getSrcTile()->getId() << ","
398- // << dyn_cast<Link>(last_link_loc.resource)->getDstTile()->getId() << "] is not available from "
399- // << current_step << " to " << deadline_step << "\n";
400- // }
401-
402352 Register *available_register =
403353 getAvailableRegister (state, dst_tile, current_step, deadline_step);
404354 if (!available_register) {
@@ -468,48 +418,6 @@ Operation *mlir::neura::getMaterializedProducer(Value operand) {
468418 return materialized_producer;
469419}
470420
471- bool mlir::neura::tryHeuristicMapping (std::vector<Operation *> &sorted_ops,
472- const Architecture &architecture,
473- MappingState &mapping_state) {
474- DenseSet<Operation *> visited;
475-
476- for (Operation *op : sorted_ops) {
477- // TODO: Build up util func to distinguish materialized and non-materialized
478- // ops.
479- if (isa<neura::DataMovOp, neura::CtrlMovOp, neura::ReserveOp>(op)) {
480- continue ;
481- }
482-
483- std::vector<MappingLoc> sorted_locs =
484- calculateAward (op, architecture, mapping_state);
485- // auto target_loc = getLocWithMinCost(loc_with_cost);
486- if (sorted_locs.empty ()) {
487- llvm::errs () << " [DEBUG] No locations found for op: " << *op << " \n " ;
488- return false ; // No locations available for this operation.
489- }
490- assert (!sorted_locs.empty () &&
491- " No locations found for the operation to map" );
492- MappingLoc target_loc = sorted_locs.front ();
493- if (placeAndRoute (op, target_loc, mapping_state)) {
494- llvm::errs () << " [DEBUG] Successfully scheduled op: " << *op
495- << " at loc: " << target_loc.resource ->getType () << " #"
496- << target_loc.resource ->getId ()
497- << " @t=" << target_loc.time_step << " \n " ;
498- continue ;
499- } else {
500- llvm::errs () << " [DEBUG] Failed to schedule op: " << *op
501- << " ; target loc: " << target_loc.resource ->getType () << " #"
502- << target_loc.resource ->getId ()
503- << " @t=" << target_loc.time_step << " \n " ;
504- }
505- // TODO: Optimization -- backtrack a few times if failed to schedule the op.
506- // https://github.com/coredac/dataflow/issues/59
507- return false ;
508- }
509-
510- return true ;
511- }
512-
513421bool mlir::neura::canReachLocInTime (const std::vector<Operation *> &producers,
514422 const MappingLoc &target_loc,
515423 int deadline_step,
@@ -760,11 +668,6 @@ bool mlir::neura::placeAndRoute(Operation *op, const MappingLoc &target_loc,
760668 std::vector<MappingLoc> route_path;
761669 if (tryRouteForwardMove (data_move, src_loc, target_loc, mapping_state,
762670 route_path)) {
763- // for (const MappingLoc &loc : route_path) {
764- // llvm::errs() << "[DEBUG] Route path loc: " << loc.resource->getType()
765- // << "#" << loc.resource->getId() << " @t=" << loc.time_step
766- // << "\n";
767- // }
768671 // Reserves the route for the data move operation.
769672 mapping_state.reserveRoute (data_move, route_path);
770673 routed_operands.push_back (data_move);
@@ -815,6 +718,8 @@ bool mlir::neura::placeAndRoute(Operation *op, const MappingLoc &target_loc,
815718 continue ;
816719 }
817720 llvm::errs () << " [DEBUG] Failed to route ctrl_mov: " << *ctrl_mov
721+ << " from " << target_loc.resource ->getType () << " #"
722+ << target_loc.resource ->getId () << " @t=" << target_loc.time_step
818723 << " to " << backward_loc.resource ->getType () << " #"
819724 << backward_loc.resource ->getId ()
820725 << " @t=" << backward_loc.time_step << " ; so unschedule op\n " ;
0 commit comments