Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/NeuraDialect/Mapping/mapping_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,44 @@ bool mlir::neura::tryRouteDataMove(Operation *mov_op, MappingLoc src_loc,
std::vector<MappingLoc> &path_out) {
// Specially handles the case where src and dst are the same tile.
if (src_loc.resource == dst_loc.resource) {
// When the source and destination are on the same tile, we still need to
// allocate registers for data movement.
Tile *tile = dyn_cast<Tile>(src_loc.resource);
if (!tile) {
llvm::errs() << "[tryRouteDataMove] Source is not a tile\n";
return false;
}

// Defines the time window for the register allocation.
int start_time = src_loc.time_step;
int exclusive_end_time = dst_loc.time_step;

// For backward moves, we need to adjust the end time.
if (is_backward_move) {
exclusive_end_time += state.getII();
}

// Finds a register that is available during start_time to
// exclusive_end_time.
Register *reg =
getAvailableRegister(state, tile, start_time, exclusive_end_time);
if (!reg) {
llvm::errs() << "[tryRouteDataMove] No available register found for "
<< "tile: " << tile->getId()
<< " from time step: " << start_time
<< " to time step: " << exclusive_end_time << "\n";
return false;
}

// Adds the register locations to the path.
for (int t = start_time; t < exclusive_end_time; ++t) {
MappingLoc reg_loc{reg, t};
path_out.push_back(reg_loc);
}

llvm::errs() << "[tryRouteDataMove] Allocated register " << reg->getId()
<< " for same-tile data movement from t=" << start_time
<< " to t=" << exclusive_end_time << "\n";
return true;
}
struct QueueEntry {
Expand Down
10 changes: 5 additions & 5 deletions test/controflow_fuse/simple_loop/simple_loop.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ module attributes {} {
// FUSE-MAPPING-NEXT: %6 = "neura.grant_once"() <{constant_value = 0 : i64}> {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 0 : i32, x = 2 : i32, y = 1 : i32}]} : () -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %7 = "neura.grant_always"() <{constant_value = true}> {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 1 : i32}]} : () -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %8 = "neura.data_mov"(%7) {mapping_locs = [{id = 10 : i32, resource = "link", time_step = 0 : i32}, {id = 14 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%6) {mapping_locs = []} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%6) {mapping_locs = [{id = 24 : i32, resource = "register", time_step = 0 : i32}, {id = 24 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %10 = "neura.data_mov"(%3) {mapping_locs = [{id = 28 : i32, resource = "link", time_step = 0 : i32}, {id = 33 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %11 = "neura.data_mov"(%2) {mapping_locs = [{id = 36 : i32, resource = "link", time_step = 0 : i32}, {id = 21 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %nextindex, %valid = neura.loop_control(parent_valid = %8, start = %9, end = %10, step = %11) {iterationType = "increment", mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 2 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data<i1, i1>, !neura.data<i64, i1>, !neura.data<i64, i1>, !neura.data<i64, i1> -> !neura.data<i64, i1>, !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %12 = "neura.data_mov"(%valid) {mapping_locs = []} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %12 = "neura.data_mov"(%valid) {mapping_locs = [{id = 25 : i32, resource = "register", time_step = 2 : i32}, {id = 25 : i32, resource = "register", time_step = 3 : i32}, {id = 25 : i32, resource = "register", time_step = 4 : i32}, {id = 25 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %13 = "neura.not"(%12) {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 6 : i32, x = 2 : i32, y = 1 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %14 = "neura.data_mov"(%0) {mapping_locs = [{id = 36 : i32, resource = "link", time_step = 1 : i32}, {id = 28 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data<memref<?xi32>, i1>) -> !neura.data<memref<?xi32>, i1>
// FUSE-MAPPING-NEXT: %15 = "neura.data_mov"(%valid) {mapping_locs = [{id = 18 : i32, resource = "link", time_step = 2 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
Expand All @@ -212,7 +212,7 @@ module attributes {} {
// FUSE-MAPPING-NEXT: %24 = "neura.data_mov"(%valid) {mapping_locs = [{id = 19 : i32, resource = "link", time_step = 2 : i32}, {id = 6 : i32, resource = "link", time_step = 3 : i32}, {id = 9 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %25 = neura.grant_predicate %23, %24 {mapping_locs = [{id = 7 : i32, resource = "tile", time_step = 5 : i32, x = 3 : i32, y = 1 : i32}]} : !neura.data<memref<?xi32>, i1>, !neura.data<i1, i1> -> !neura.data<memref<?xi32>, i1>
// FUSE-MAPPING-NEXT: %26 = "neura.data_mov"(%16) {mapping_locs = [{id = 21 : i32, resource = "link", time_step = 3 : i32}]} : (!neura.data<memref<?xi32>, i1>) -> !neura.data<memref<?xi32>, i1>
// FUSE-MAPPING-NEXT: %27 = "neura.data_mov"(%nextindex) {mapping_locs = []} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %27 = "neura.data_mov"(%nextindex) {mapping_locs = [{id = 24 : i32, resource = "register", time_step = 2 : i32}, {id = 24 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %28 = neura.load_indexed %26[%27 : !neura.data<i64, i1>] !neura.data<memref<?xi32>, i1> {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 4 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %29 = "neura.data_mov"(%28) {mapping_locs = [{id = 17 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %30 = "neura.data_mov"(%19) {mapping_locs = [{id = 4 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
Expand All @@ -221,8 +221,8 @@ module attributes {} {
// FUSE-MAPPING-NEXT: %33 = "neura.data_mov"(%22) {mapping_locs = [{id = 31 : i32, resource = "link", time_step = 4 : i32}, {id = 36 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %34 = "neura.add"(%32, %33) {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 6 : i32, x = 1 : i32, y = 2 : i32}]} : (!neura.data<i32, i1>, !neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %35 = "neura.data_mov"(%34) {mapping_locs = [{id = 28 : i32, resource = "link", time_step = 6 : i32}, {id = 33 : i32, resource = "link", time_step = 7 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %36 = "neura.data_mov"(%25) {mapping_locs = [{id = 21 : i32, resource = "link", time_step = 5 : i32}, {id = 24 : i32, resource = "register", time_step = 6 : i32}, {id = 24 : i32, resource = "register", time_step = 7 : i32}]} : (!neura.data<memref<?xi32>, i1>) -> !neura.data<memref<?xi32>, i1>
// FUSE-MAPPING-NEXT: %37 = "neura.data_mov"(%nextindex) {mapping_locs = []} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %36 = "neura.data_mov"(%25) {mapping_locs = [{id = 21 : i32, resource = "link", time_step = 5 : i32}, {id = 26 : i32, resource = "register", time_step = 6 : i32}, {id = 26 : i32, resource = "register", time_step = 7 : i32}]} : (!neura.data<memref<?xi32>, i1>) -> !neura.data<memref<?xi32>, i1>
// FUSE-MAPPING-NEXT: %37 = "neura.data_mov"(%nextindex) {mapping_locs = [{id = 27 : i32, resource = "register", time_step = 2 : i32}, {id = 27 : i32, resource = "register", time_step = 3 : i32}, {id = 27 : i32, resource = "register", time_step = 4 : i32}, {id = 27 : i32, resource = "register", time_step = 5 : i32}, {id = 27 : i32, resource = "register", time_step = 6 : i32}, {id = 27 : i32, resource = "register", time_step = 7 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: neura.store_indexed %35 to %36[%37 : !neura.data<i64, i1>] !neura.data<memref<?xi32>, i1> {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 8 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: "neura.return"() {mapping_locs = [{id = 0 : i32, resource = "tile", time_step = 6 : i32, x = 0 : i32, y = 0 : i32}]} : () -> ()
// FUSE-MAPPING-NEXT: }
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module attributes {} {
// FUSE-MAPPING-NEXT: %7 = "neura.data_mov"(%1) {mapping_locs = [{id = 39 : i32, resource = "link", time_step = 0 : i32}, {id = 33 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %8 = "neura.data_mov"(%0) {mapping_locs = [{id = 12 : i32, resource = "link", time_step = 0 : i32}, {id = 34 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %nextindex, %valid = neura.loop_control(parent_valid = %5, start = %6, end = %7, step = %8) {iterationType = "increment", mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 2 : i32, x = 0 : i32, y = 2 : i32}]} : !neura.data<i1, i1>, !neura.data<i64, i1>, !neura.data<i64, i1>, !neura.data<i64, i1> -> !neura.data<i64, i1>, !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%valid) {mapping_locs = []} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%valid) {mapping_locs = [{id = 32 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %10 = "neura.not"(%9) {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 3 : i32, x = 0 : i32, y = 2 : i32}]} : (!neura.data<i1, i1>) -> !neura.data<i1, i1>
// FUSE-MAPPING-NEXT: %11 = neura.reserve : !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %12 = "neura.data_mov"(%2) {mapping_locs = [{id = 0 : i32, resource = "link", time_step = 1 : i32}, {id = 4 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
Expand All @@ -185,7 +185,7 @@ module attributes {} {
// FUSE-MAPPING-NEXT: %19 = neura.grant_predicate %17, %18 {mapping_locs = [{id = 0 : i32, resource = "tile", time_step = 5 : i32, x = 0 : i32, y = 0 : i32}]} : !neura.data<i32, i1>, !neura.data<i1, i1> -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %20 = "neura.data_mov"(%nextindex) {mapping_locs = [{id = 25 : i32, resource = "link", time_step = 2 : i32}, {id = 16 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i64, i1>
// FUSE-MAPPING-NEXT: %21 = "neura.cast"(%20) <{cast_type = "i64_to_i32"}> {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 4 : i32, x = 0 : i32, y = 1 : i32}]} : (!neura.data<i64, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %22 = "neura.data_mov"(%16) {mapping_locs = []} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %22 = "neura.data_mov"(%16) {mapping_locs = [{id = 20 : i32, resource = "register", time_step = 4 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %23 = "neura.data_mov"(%21) {mapping_locs = [{id = 10 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: %24 = "neura.add"(%22, %23) {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 5 : i32, x = 1 : i32, y = 1 : i32}]} : (!neura.data<i32, i1>, !neura.data<i32, i1>) -> !neura.data<i32, i1>
// FUSE-MAPPING-NEXT: neura.ctrl_mov %24 -> %11 {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 5 : i32}]} : !neura.data<i32, i1> !neura.data<i32, i1>
Expand Down
Loading