diff --git a/lib/NeuraDialect/Mapping/mapping_util.cpp b/lib/NeuraDialect/Mapping/mapping_util.cpp index 0a0ea45a..ff188acb 100644 --- a/lib/NeuraDialect/Mapping/mapping_util.cpp +++ b/lib/NeuraDialect/Mapping/mapping_util.cpp @@ -417,6 +417,44 @@ bool mlir::neura::tryRouteDataMove(Operation *mov_op, MappingLoc src_loc, std::vector &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(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 { diff --git a/test/controflow_fuse/simple_loop/simple_loop.mlir b/test/controflow_fuse/simple_loop/simple_loop.mlir index 4752c2f1..4ad24c8f 100644 --- a/test/controflow_fuse/simple_loop/simple_loop.mlir +++ b/test/controflow_fuse/simple_loop/simple_loop.mlir @@ -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 // 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 // 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) -> !neura.data -// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%6) {mapping_locs = []} : (!neura.data) -> !neura.data +// 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) -> !neura.data // 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) -> !neura.data // 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) -> !neura.data // 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, !neura.data, !neura.data, !neura.data -> !neura.data, !neura.data -// FUSE-MAPPING-NEXT: %12 = "neura.data_mov"(%valid) {mapping_locs = []} : (!neura.data) -> !neura.data +// 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) -> !neura.data // 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) -> !neura.data // 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, i1>) -> !neura.data, i1> // FUSE-MAPPING-NEXT: %15 = "neura.data_mov"(%valid) {mapping_locs = [{id = 18 : i32, resource = "link", time_step = 2 : i32}]} : (!neura.data) -> !neura.data @@ -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) -> !neura.data // 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, i1>, !neura.data -> !neura.data, i1> // FUSE-MAPPING-NEXT: %26 = "neura.data_mov"(%16) {mapping_locs = [{id = 21 : i32, resource = "link", time_step = 3 : i32}]} : (!neura.data, i1>) -> !neura.data, i1> -// FUSE-MAPPING-NEXT: %27 = "neura.data_mov"(%nextindex) {mapping_locs = []} : (!neura.data) -> !neura.data +// 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) -> !neura.data // FUSE-MAPPING-NEXT: %28 = neura.load_indexed %26[%27 : !neura.data] !neura.data, i1> {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 4 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data // FUSE-MAPPING-NEXT: %29 = "neura.data_mov"(%28) {mapping_locs = [{id = 17 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data) -> !neura.data // FUSE-MAPPING-NEXT: %30 = "neura.data_mov"(%19) {mapping_locs = [{id = 4 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data) -> !neura.data @@ -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) -> !neura.data // 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, !neura.data) -> !neura.data // 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) -> !neura.data -// 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, i1>) -> !neura.data, i1> -// FUSE-MAPPING-NEXT: %37 = "neura.data_mov"(%nextindex) {mapping_locs = []} : (!neura.data) -> !neura.data +// 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, i1>) -> !neura.data, 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) -> !neura.data // FUSE-MAPPING-NEXT: neura.store_indexed %35 to %36[%37 : !neura.data] !neura.data, i1> {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 8 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data // 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: } \ No newline at end of file diff --git a/test/controflow_fuse/simple_loop_reduction/simple_loop_reduction.mlir b/test/controflow_fuse/simple_loop_reduction/simple_loop_reduction.mlir index 8b4044f6..6567ad57 100644 --- a/test/controflow_fuse/simple_loop_reduction/simple_loop_reduction.mlir +++ b/test/controflow_fuse/simple_loop_reduction/simple_loop_reduction.mlir @@ -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) -> !neura.data // 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) -> !neura.data // 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, !neura.data, !neura.data, !neura.data -> !neura.data, !neura.data -// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%valid) {mapping_locs = []} : (!neura.data) -> !neura.data +// FUSE-MAPPING-NEXT: %9 = "neura.data_mov"(%valid) {mapping_locs = [{id = 32 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data) -> !neura.data // 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) -> !neura.data // FUSE-MAPPING-NEXT: %11 = neura.reserve : !neura.data // 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) -> !neura.data @@ -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, !neura.data -> !neura.data // 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) -> !neura.data // 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) -> !neura.data -// FUSE-MAPPING-NEXT: %22 = "neura.data_mov"(%16) {mapping_locs = []} : (!neura.data) -> !neura.data +// FUSE-MAPPING-NEXT: %22 = "neura.data_mov"(%16) {mapping_locs = [{id = 20 : i32, resource = "register", time_step = 4 : i32}]} : (!neura.data) -> !neura.data // FUSE-MAPPING-NEXT: %23 = "neura.data_mov"(%21) {mapping_locs = [{id = 10 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data) -> !neura.data // 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, !neura.data) -> !neura.data // FUSE-MAPPING-NEXT: neura.ctrl_mov %24 -> %11 {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 5 : i32}]} : !neura.data !neura.data diff --git a/test/mapping_quality/branch_for.mlir b/test/mapping_quality/branch_for.mlir index 4817c572..89b30f3e 100644 --- a/test/mapping_quality/branch_for.mlir +++ b/test/mapping_quality/branch_for.mlir @@ -271,14 +271,14 @@ func.func @loop_test() -> f32 { // MAPPING-NEXT: %23 = "neura.data_mov"(%19) {mapping_locs = [{id = 4 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %24 = "neura.data_mov"(%10) {mapping_locs = [{id = 17 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %25 = "neura.add"(%23, %24) {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 2 : i32, x = 1 : i32, y = 1 : i32}]} : (!neura.data, !neura.data) -> !neura.data -// MAPPING-NEXT: %26 = "neura.data_mov"(%25) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %26 = "neura.data_mov"(%25) {mapping_locs = [{id = 20 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %27 = "neura.data_mov"(%7) {mapping_locs = [{id = 4 : i32, resource = "link", time_step = 2 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %28 = "neura.icmp"(%26, %27) <{cmpType = "slt"}> {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 3 : i32, x = 1 : i32, y = 1 : i32}]} : (!neura.data, !neura.data) -> !neura.data -// MAPPING-NEXT: %29 = "neura.data_mov"(%25) {mapping_locs = []} : (!neura.data) -> !neura.data -// MAPPING-NEXT: %30 = "neura.data_mov"(%28) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %29 = "neura.data_mov"(%25) {mapping_locs = [{id = 21 : i32, resource = "register", time_step = 2 : i32}, {id = 21 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %30 = "neura.data_mov"(%28) {mapping_locs = [{id = 20 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %31 = neura.grant_predicate %29, %30 {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 4 : i32, x = 1 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data // MAPPING-NEXT: neura.ctrl_mov %31 -> %17 {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 4 : i32}, {id = 4 : i32, resource = "register", time_step = 5 : i32}, {id = 4 : i32, resource = "register", time_step = 6 : i32}]} : !neura.data !neura.data -// MAPPING-NEXT: %32 = "neura.data_mov"(%22) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %32 = "neura.data_mov"(%22) {mapping_locs = [{id = 36 : i32, resource = "register", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %33 = "neura.data_mov"(%28) {mapping_locs = [{id = 16 : i32, resource = "link", time_step = 3 : i32}, {id = 37 : i32, resource = "register", time_step = 4 : i32}, {id = 37 : i32, resource = "register", time_step = 5 : i32}, {id = 37 : i32, resource = "register", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %34 = neura.grant_predicate %32, %33 {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 7 : i32, x = 1 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data // MAPPING-NEXT: neura.ctrl_mov %34 -> %14 {mapping_locs = [{id = 28 : i32, resource = "link", time_step = 7 : i32}, {id = 32 : i32, resource = "link", time_step = 8 : i32}]} : !neura.data !neura.data @@ -289,9 +289,9 @@ func.func @loop_test() -> f32 { // MAPPING-NEXT: %38 = "neura.data_mov"(%2) {mapping_locs = [{id = 6 : i32, resource = "link", time_step = 0 : i32}, {id = 9 : i32, resource = "link", time_step = 1 : i32}, {id = 21 : i32, resource = "link", time_step = 2 : i32}, {id = 24 : i32, resource = "register", time_step = 3 : i32}, {id = 24 : i32, resource = "register", time_step = 4 : i32}, {id = 24 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %39 = "neura.data_mov"(%28) {mapping_locs = [{id = 14 : i32, resource = "link", time_step = 3 : i32}, {id = 25 : i32, resource = "register", time_step = 4 : i32}, {id = 25 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %40 = neura.grant_predicate %38, %39 {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 6 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data -// MAPPING-NEXT: neura.ctrl_mov %40 -> %8 {mapping_locs = []} : !neura.data !neura.data -// MAPPING-NEXT: %41 = "neura.data_mov"(%0) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 1 : i32}, {id = 10 : i32, resource = "link", time_step = 2 : i32}, {id = 20 : i32, resource = "register", time_step = 3 : i32}, {id = 20 : i32, resource = "register", time_step = 4 : i32}, {id = 20 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data -// MAPPING-NEXT: %42 = "neura.data_mov"(%28) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: neura.ctrl_mov %40 -> %8 {mapping_locs = [{id = 24 : i32, resource = "register", time_step = 6 : i32}]} : !neura.data !neura.data +// MAPPING-NEXT: %41 = "neura.data_mov"(%0) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 1 : i32}, {id = 10 : i32, resource = "link", time_step = 2 : i32}, {id = 22 : i32, resource = "register", time_step = 3 : i32}, {id = 22 : i32, resource = "register", time_step = 4 : i32}, {id = 22 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %42 = "neura.data_mov"(%28) {mapping_locs = [{id = 23 : i32, resource = "register", time_step = 3 : i32}, {id = 23 : i32, resource = "register", time_step = 4 : i32}, {id = 23 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %43 = neura.grant_predicate %41, %42 {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 6 : i32, x = 1 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data // MAPPING-NEXT: neura.ctrl_mov %43 -> %5 {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 6 : i32}, {id = 4 : i32, resource = "register", time_step = 7 : i32}]} : !neura.data !neura.data // MAPPING-NEXT: %44 = "neura.data_mov"(%28) {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 3 : i32}]} : (!neura.data) -> !neura.data @@ -299,7 +299,7 @@ func.func @loop_test() -> f32 { // MAPPING-NEXT: %46 = "neura.data_mov"(%22) {mapping_locs = [{id = 27 : i32, resource = "link", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %47 = "neura.data_mov"(%45) {mapping_locs = [{id = 2 : i32, resource = "link", time_step = 4 : i32}, {id = 1 : i32, resource = "link", time_step = 5 : i32}, {id = 12 : i32, resource = "link", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %48 = neura.grant_predicate %46, %47 {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 7 : i32, x = 0 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data -// MAPPING-NEXT: %49 = "neura.data_mov"(%48) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %49 = "neura.data_mov"(%48) {mapping_locs = [{id = 32 : i32, resource = "register", time_step = 7 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: "neura.return"(%49) {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 8 : i32, x = 0 : i32, y = 2 : i32}]} : (!neura.data) -> () // MAPPING-NEXT: } diff --git a/test/mapping_quality/tiny_loop.mlir b/test/mapping_quality/tiny_loop.mlir index 87aae182..9add83fb 100644 --- a/test/mapping_quality/tiny_loop.mlir +++ b/test/mapping_quality/tiny_loop.mlir @@ -103,32 +103,32 @@ module { // SPATIAL-NEXT: "neura.return"(%23) {mapping_locs = [{id = 15 : i32, resource = "tile", time_step = 10 : i32, x = 3 : i32, y = 3 : i32}]} : (!neura.data) -> () // SPATIAL-NEXT: } -// SPATIAL-TEMPORAL: func.func @simple_add_loop() -> i64 attributes {accelerator = "neura", mapping_info = {compiled_ii = 3 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 3 : i32, res_mii = 1 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32}} { -// SPATIAL-TEMPORAL-NEXT: %0 = "neura.grant_always"() <{constant_value = 16 : i64}> {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 1 : i32}]} : () -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %1 = "neura.grant_always"() <{constant_value = 1 : i64}> {mapping_locs = [{id = 12 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 3 : i32}]} : () -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %2 = "neura.grant_once"() <{constant_value = 1 : i64}> {mapping_locs = [{id = 0 : i32, resource = "tile", time_step = 1 : i32, x = 0 : i32, y = 0 : i32}]} : () -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %3 = "neura.grant_once"() <{constant_value = 0 : i64}> {mapping_locs = [{id = 0 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 0 : i32}]} : () -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %4 = "neura.grant_always"() <{constant_value = true}> {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 0 : i32, x = 1 : i32, y = 2 : i32}]} : () -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %5 = "neura.data_mov"(%4) {mapping_locs = [{id = 27 : i32, resource = "link", time_step = 0 : i32}, {id = 32 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %6 = "neura.data_mov"(%3) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 0 : i32}, {id = 12 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %7 = "neura.data_mov"(%0) {mapping_locs = [{id = 12 : i32, resource = "link", time_step = 0 : i32}, {id = 33 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %8 = "neura.data_mov"(%1) {mapping_locs = [{id = 39 : i32, resource = "link", time_step = 0 : i32}, {id = 34 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-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, !neura.data, !neura.data, !neura.data -> !neura.data, !neura.data -// SPATIAL-TEMPORAL-NEXT: %9 = "neura.data_mov"(%valid) {mapping_locs = [{id = 25 : i32, resource = "link", time_step = 2 : i32}, {id = 16 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %10 = "neura.not"(%9) {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 4 : i32, x = 0 : i32, y = 1 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %11 = neura.reserve : !neura.data -// SPATIAL-TEMPORAL-NEXT: %12 = "neura.data_mov"(%2) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %13 = "neura.phi"(%11, %12) {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 2 : i32, x = 0 : i32, y = 1 : i32}]} : (!neura.data, !neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %14 = "neura.data_mov"(%13) {mapping_locs = [{id = 12 : i32, resource = "link", time_step = 2 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %15 = "neura.data_mov"(%valid) {mapping_locs = []} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %16 = neura.grant_predicate %14, %15 {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 3 : i32, x = 0 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %17 = "neura.data_mov"(%13) {mapping_locs = [{id = 11 : i32, resource = "link", time_step = 2 : i32}, {id = 0 : i32, resource = "register", time_step = 3 : i32}, {id = 0 : i32, resource = "register", time_step = 4 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %18 = "neura.data_mov"(%10) {mapping_locs = [{id = 11 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-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, !neura.data -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %20 = "neura.data_mov"(%16) {mapping_locs = []} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %21 = "neura.data_mov"(%16) {mapping_locs = []} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: %22 = "neura.add"(%20, %21) {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 4 : i32, x = 0 : i32, y = 2 : i32}]} : (!neura.data, !neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: neura.ctrl_mov %22 -> %11 {mapping_locs = [{id = 25 : i32, resource = "link", time_step = 4 : i32}]} : !neura.data !neura.data -// SPATIAL-TEMPORAL-NEXT: %23 = "neura.data_mov"(%19) {mapping_locs = [{id = 0 : i32, resource = "link", time_step = 5 : i32}]} : (!neura.data) -> !neura.data -// SPATIAL-TEMPORAL-NEXT: "neura.return"(%23) {mapping_locs = [{id = 1 : i32, resource = "tile", time_step = 6 : i32, x = 1 : i32, y = 0 : i32}]} : (!neura.data) -> () -// SPATIAL-TEMPORAL-NEXT: } \ No newline at end of file +// SPATIAL-TEMPORAL: func.func @simple_add_loop() -> i64 attributes {accelerator = "neura", mapping_info = {compiled_ii = 3 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 3 : i32, res_mii = 1 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32}} { +// SPATIAL-TEMPORAL-NEXT: %0 = "neura.grant_always"() <{constant_value = 16 : i64}> {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 1 : i32}]} : () -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %1 = "neura.grant_always"() <{constant_value = 1 : i64}> {mapping_locs = [{id = 12 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 3 : i32}]} : () -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %2 = "neura.grant_once"() <{constant_value = 1 : i64}> {mapping_locs = [{id = 0 : i32, resource = "tile", time_step = 1 : i32, x = 0 : i32, y = 0 : i32}]} : () -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %3 = "neura.grant_once"() <{constant_value = 0 : i64}> {mapping_locs = [{id = 0 : i32, resource = "tile", time_step = 0 : i32, x = 0 : i32, y = 0 : i32}]} : () -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %4 = "neura.grant_always"() <{constant_value = true}> {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 0 : i32, x = 1 : i32, y = 2 : i32}]} : () -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %5 = "neura.data_mov"(%4) {mapping_locs = [{id = 27 : i32, resource = "link", time_step = 0 : i32}, {id = 32 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %6 = "neura.data_mov"(%3) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 0 : i32}, {id = 12 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %7 = "neura.data_mov"(%0) {mapping_locs = [{id = 12 : i32, resource = "link", time_step = 0 : i32}, {id = 33 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %8 = "neura.data_mov"(%1) {mapping_locs = [{id = 39 : i32, resource = "link", time_step = 0 : i32}, {id = 34 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-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, !neura.data, !neura.data, !neura.data -> !neura.data, !neura.data +// SPATIAL-TEMPORAL-NEXT: %9 = "neura.data_mov"(%valid) {mapping_locs = [{id = 25 : i32, resource = "link", time_step = 2 : i32}, {id = 16 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %10 = "neura.not"(%9) {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 4 : i32, x = 0 : i32, y = 1 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %11 = neura.reserve : !neura.data +// SPATIAL-TEMPORAL-NEXT: %12 = "neura.data_mov"(%2) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %13 = "neura.phi"(%11, %12) {mapping_locs = [{id = 4 : i32, resource = "tile", time_step = 2 : i32, x = 0 : i32, y = 1 : i32}]} : (!neura.data, !neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %14 = "neura.data_mov"(%13) {mapping_locs = [{id = 12 : i32, resource = "link", time_step = 2 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %15 = "neura.data_mov"(%valid) {mapping_locs = [{id = 32 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %16 = neura.grant_predicate %14, %15 {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 3 : i32, x = 0 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %17 = "neura.data_mov"(%13) {mapping_locs = [{id = 11 : i32, resource = "link", time_step = 2 : i32}, {id = 0 : i32, resource = "register", time_step = 3 : i32}, {id = 0 : i32, resource = "register", time_step = 4 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %18 = "neura.data_mov"(%10) {mapping_locs = [{id = 11 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-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, !neura.data -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %20 = "neura.data_mov"(%16) {mapping_locs = [{id = 32 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %21 = "neura.data_mov"(%16) {mapping_locs = [{id = 33 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: %22 = "neura.add"(%20, %21) {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 4 : i32, x = 0 : i32, y = 2 : i32}]} : (!neura.data, !neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: neura.ctrl_mov %22 -> %11 {mapping_locs = [{id = 25 : i32, resource = "link", time_step = 4 : i32}]} : !neura.data !neura.data +// SPATIAL-TEMPORAL-NEXT: %23 = "neura.data_mov"(%19) {mapping_locs = [{id = 0 : i32, resource = "link", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// SPATIAL-TEMPORAL-NEXT: "neura.return"(%23) {mapping_locs = [{id = 1 : i32, resource = "tile", time_step = 6 : i32, x = 1 : i32, y = 0 : i32}]} : (!neura.data) -> () +// SPATIAL-TEMPORAL-NEXT: } \ No newline at end of file diff --git a/test/neura/ctrl/branch_for.mlir b/test/neura/ctrl/branch_for.mlir index b7196a5a..ebc65a42 100644 --- a/test/neura/ctrl/branch_for.mlir +++ b/test/neura/ctrl/branch_for.mlir @@ -271,14 +271,14 @@ func.func @loop_test() -> f32 { // MAPPING-NEXT: %23 = "neura.data_mov"(%19) {mapping_locs = [{id = 4 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %24 = "neura.data_mov"(%10) {mapping_locs = [{id = 17 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %25 = "neura.add"(%23, %24) {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 2 : i32, x = 1 : i32, y = 1 : i32}]} : (!neura.data, !neura.data) -> !neura.data -// MAPPING-NEXT: %26 = "neura.data_mov"(%25) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %26 = "neura.data_mov"(%25) {mapping_locs = [{id = 20 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %27 = "neura.data_mov"(%7) {mapping_locs = [{id = 4 : i32, resource = "link", time_step = 2 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %28 = "neura.icmp"(%26, %27) <{cmpType = "slt"}> {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 3 : i32, x = 1 : i32, y = 1 : i32}]} : (!neura.data, !neura.data) -> !neura.data -// MAPPING-NEXT: %29 = "neura.data_mov"(%25) {mapping_locs = []} : (!neura.data) -> !neura.data -// MAPPING-NEXT: %30 = "neura.data_mov"(%28) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %29 = "neura.data_mov"(%25) {mapping_locs = [{id = 21 : i32, resource = "register", time_step = 2 : i32}, {id = 21 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %30 = "neura.data_mov"(%28) {mapping_locs = [{id = 20 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %31 = neura.grant_predicate %29, %30 {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 4 : i32, x = 1 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data // MAPPING-NEXT: neura.ctrl_mov %31 -> %17 {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 4 : i32}, {id = 4 : i32, resource = "register", time_step = 5 : i32}, {id = 4 : i32, resource = "register", time_step = 6 : i32}]} : !neura.data !neura.data -// MAPPING-NEXT: %32 = "neura.data_mov"(%22) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %32 = "neura.data_mov"(%22) {mapping_locs = [{id = 36 : i32, resource = "register", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %33 = "neura.data_mov"(%28) {mapping_locs = [{id = 16 : i32, resource = "link", time_step = 3 : i32}, {id = 37 : i32, resource = "register", time_step = 4 : i32}, {id = 37 : i32, resource = "register", time_step = 5 : i32}, {id = 37 : i32, resource = "register", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %34 = neura.grant_predicate %32, %33 {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 7 : i32, x = 1 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data // MAPPING-NEXT: neura.ctrl_mov %34 -> %14 {mapping_locs = [{id = 28 : i32, resource = "link", time_step = 7 : i32}, {id = 32 : i32, resource = "link", time_step = 8 : i32}]} : !neura.data !neura.data @@ -289,9 +289,9 @@ func.func @loop_test() -> f32 { // MAPPING-NEXT: %38 = "neura.data_mov"(%2) {mapping_locs = [{id = 6 : i32, resource = "link", time_step = 0 : i32}, {id = 9 : i32, resource = "link", time_step = 1 : i32}, {id = 21 : i32, resource = "link", time_step = 2 : i32}, {id = 24 : i32, resource = "register", time_step = 3 : i32}, {id = 24 : i32, resource = "register", time_step = 4 : i32}, {id = 24 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %39 = "neura.data_mov"(%28) {mapping_locs = [{id = 14 : i32, resource = "link", time_step = 3 : i32}, {id = 25 : i32, resource = "register", time_step = 4 : i32}, {id = 25 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %40 = neura.grant_predicate %38, %39 {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 6 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data -// MAPPING-NEXT: neura.ctrl_mov %40 -> %8 {mapping_locs = []} : !neura.data !neura.data -// MAPPING-NEXT: %41 = "neura.data_mov"(%0) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 1 : i32}, {id = 10 : i32, resource = "link", time_step = 2 : i32}, {id = 20 : i32, resource = "register", time_step = 3 : i32}, {id = 20 : i32, resource = "register", time_step = 4 : i32}, {id = 20 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data -// MAPPING-NEXT: %42 = "neura.data_mov"(%28) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: neura.ctrl_mov %40 -> %8 {mapping_locs = [{id = 24 : i32, resource = "register", time_step = 6 : i32}]} : !neura.data !neura.data +// MAPPING-NEXT: %41 = "neura.data_mov"(%0) {mapping_locs = [{id = 1 : i32, resource = "link", time_step = 1 : i32}, {id = 10 : i32, resource = "link", time_step = 2 : i32}, {id = 22 : i32, resource = "register", time_step = 3 : i32}, {id = 22 : i32, resource = "register", time_step = 4 : i32}, {id = 22 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %42 = "neura.data_mov"(%28) {mapping_locs = [{id = 23 : i32, resource = "register", time_step = 3 : i32}, {id = 23 : i32, resource = "register", time_step = 4 : i32}, {id = 23 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %43 = neura.grant_predicate %41, %42 {mapping_locs = [{id = 5 : i32, resource = "tile", time_step = 6 : i32, x = 1 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data // MAPPING-NEXT: neura.ctrl_mov %43 -> %5 {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 6 : i32}, {id = 4 : i32, resource = "register", time_step = 7 : i32}]} : !neura.data !neura.data // MAPPING-NEXT: %44 = "neura.data_mov"(%28) {mapping_locs = [{id = 15 : i32, resource = "link", time_step = 3 : i32}]} : (!neura.data) -> !neura.data @@ -299,7 +299,7 @@ func.func @loop_test() -> f32 { // MAPPING-NEXT: %46 = "neura.data_mov"(%22) {mapping_locs = [{id = 27 : i32, resource = "link", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %47 = "neura.data_mov"(%45) {mapping_locs = [{id = 2 : i32, resource = "link", time_step = 4 : i32}, {id = 1 : i32, resource = "link", time_step = 5 : i32}, {id = 12 : i32, resource = "link", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %48 = neura.grant_predicate %46, %47 {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 7 : i32, x = 0 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data -// MAPPING-NEXT: %49 = "neura.data_mov"(%48) {mapping_locs = []} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %49 = "neura.data_mov"(%48) {mapping_locs = [{id = 32 : i32, resource = "register", time_step = 7 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: "neura.return"(%49) {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 8 : i32, x = 0 : i32, y = 2 : i32}]} : (!neura.data) -> () // MAPPING-NEXT: }