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
323 changes: 219 additions & 104 deletions lib/NeuraDialect/Transforms/GenerateCodePass.cpp

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions test/code_gen/test_code_generate.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - index_per_ii: 0
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 410001
// YAML-NEXT: id: 410000
// YAML-NEXT: time_step: 4
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -323,7 +323,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - operand: "$0"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 490002
// YAML-NEXT: id: 490001
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -375,7 +375,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - operand: "$0"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 490001
// YAML-NEXT: id: 490000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand All @@ -401,7 +401,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - operand: "EAST"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 430001
// YAML-NEXT: id: 430000
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand All @@ -427,7 +427,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - operand: "SOUTH"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 580002
// YAML-NEXT: id: 580001
// YAML-NEXT: time_step: 7
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -505,7 +505,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - operand: "SOUTH"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 580001
// YAML-NEXT: id: 580000
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -567,7 +567,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - index_per_ii: 2
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 440001
// YAML-NEXT: id: 440000
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -650,7 +650,7 @@ func.func @loop_test() -> f32 {
// YAML-NEXT: - index_per_ii: 1
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 500001
// YAML-NEXT: id: 500000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -809,4 +809,3 @@ func.func @loop_test() -> f32 {
// ASM-NEXT: GRANT_ONCE, [$0] -> [SOUTH, RED] (t=3, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=3)


11 changes: 5 additions & 6 deletions test/compiler_e2e/fir/fir_kernel.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
// YAML-NEXT: - index_per_ii: 4
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 180001
// YAML-NEXT: id: 180000
// YAML-NEXT: time_step: 4
// YAML-NEXT: invalid_iterations: 0
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -240,7 +240,7 @@
// YAML-NEXT: - operand: "WEST"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 100001
// YAML-NEXT: id: 100000
// YAML-NEXT: time_step: 2
// YAML-NEXT: invalid_iterations: 0
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -276,7 +276,7 @@
// YAML-NEXT: - index_per_ii: 0
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 280001
// YAML-NEXT: id: 280000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand All @@ -302,7 +302,7 @@
// YAML-NEXT: - index_per_ii: 2
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 110001
// YAML-NEXT: id: 110000
// YAML-NEXT: time_step: 2
// YAML-NEXT: invalid_iterations: 0
// YAML-NEXT: src_operands:
Expand All @@ -321,7 +321,7 @@
// YAML-NEXT: - index_per_ii: 4
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 190001
// YAML-NEXT: id: 190000
// YAML-NEXT: time_step: 4
// YAML-NEXT: invalid_iterations: 0
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -443,4 +443,3 @@
// YAML-NEXT: - operand: "WEST"
// YAML-NEXT: color: "RED"


10 changes: 5 additions & 5 deletions test/e2e/fir/fir_kernel.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
// YAML-NEXT: - index_per_ii: 1
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 310001
// YAML-NEXT: id: 310000
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -249,7 +249,7 @@
// YAML-NEXT: - index_per_ii: 3
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 180001
// YAML-NEXT: id: 180000
// YAML-NEXT: time_step: 3
// YAML-NEXT: invalid_iterations: 0
// YAML-NEXT: src_operands:
Expand All @@ -267,7 +267,7 @@
// YAML-NEXT: - index_per_ii: 1
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 290002
// YAML-NEXT: id: 290001
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -311,7 +311,7 @@
// YAML-NEXT: - index_per_ii: 0
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 120001
// YAML-NEXT: id: 120000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand All @@ -321,7 +321,7 @@
// YAML-NEXT: - operand: "SOUTH"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 290001
// YAML-NEXT: id: 290000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down
11 changes: 5 additions & 6 deletions test/e2e/fir/fir_kernel_vec.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
// YAML-NEXT: - index_per_ii: 1
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 310001
// YAML-NEXT: id: 310000
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -239,7 +239,7 @@
// YAML-NEXT: - index_per_ii: 3
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 180001
// YAML-NEXT: id: 180000
// YAML-NEXT: time_step: 3
// YAML-NEXT: invalid_iterations: 0
// YAML-NEXT: src_operands:
Expand All @@ -257,7 +257,7 @@
// YAML-NEXT: - index_per_ii: 1
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 290002
// YAML-NEXT: id: 290001
// YAML-NEXT: time_step: 6
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -301,7 +301,7 @@
// YAML-NEXT: - index_per_ii: 0
// YAML-NEXT: operations:
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 120001
// YAML-NEXT: id: 120000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand All @@ -311,7 +311,7 @@
// YAML-NEXT: - operand: "SOUTH"
// YAML-NEXT: color: "RED"
// YAML-NEXT: - opcode: "DATA_MOV"
// YAML-NEXT: id: 290001
// YAML-NEXT: id: 290000
// YAML-NEXT: time_step: 5
// YAML-NEXT: invalid_iterations: 1
// YAML-NEXT: src_operands:
Expand Down Expand Up @@ -577,4 +577,3 @@
// ASM-NEXT: RETURN_VALUE, [SOUTH, RED] (t=10, inv_iters=2)
// ASM-NEXT: } (idx_per_ii=0)


117 changes: 117 additions & 0 deletions test/e2e/gemm/gemm_kernel.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
// RUN: FileCheck %s --input-file=%t-mapping.mlir --check-prefix=MAPPING
// RUN: FileCheck %s --input-file=tmp-generated-instructions.yaml --check-prefix=YAML
// RUN: FileCheck %s --input-file=tmp-generated-instructions.asm --check-prefix=ASM
// RUN: FileCheck %s --input-file=tmp-generated-instructions.yaml --check-prefix=CHAIN-YAML
// RUN: FileCheck %s --input-file=tmp-generated-instructions.asm --check-prefix=CHAIN-ASM
// RUN: FileCheck %s --input-file=tmp-generated-dfg.yaml --check-prefix=CHAIN-DFG
//
// MAPPING: func.func @kernel_int(%arg0: i32 {llvm.noundef}, %arg1: i32 {llvm.noundef}, %arg2: i32 {llvm.noundef}, %arg3: !llvm.ptr {llvm.nocapture, llvm.noundef}, %arg4: !llvm.ptr {llvm.nocapture, llvm.noundef, llvm.readonly}, %arg5: !llvm.ptr {llvm.nocapture, llvm.noundef, llvm.readonly}) -> !llvm.void attributes {CConv = #llvm.cconv<ccc>, accelerator = "neura", dataflow_mode = "predicate", linkage = #llvm.linkage<external>, mapping_info = {compiled_ii = 17 : i32, mapping_mode = "spatial-temporal", mapping_strategy = "heuristic", rec_mii = 13 : i32, res_mii = 6 : i32, x_tiles = 4 : i32, y_tiles = 4 : i32}, memory_effects = #llvm.memory_effects<other = none, argMem = readwrite, inaccessibleMem = none>, no_unwind, passthrough = ["nofree", "norecurse", "nosync", ["uwtable", "2"], ["min-legal-vector-width", "0"], ["no-trapping-math", "true"], ["stack-protector-buffer-size", "8"], ["target-cpu", "x86-64"]], target_cpu = "x86-64", target_features = #llvm.target_features<["+cmov", "+cx8", "+fxsr", "+mmx", "+sse", "+sse2", "+x87"]>, tune_cpu = "generic", unnamed_addr = 1 : i64, visibility_ = 0 : i64} {
// MAPPING-NEXT: %0 = "neura.grant_once"() <{constant_value = "%arg0"}> {dfg_id = 0 : i32, mapping_locs = [{id = 0 : i32, index_per_ii = 8 : i32, invalid_iterations = 0 : i32, resource = "tile", time_step = 8 : i32, x = 0 : i32, y = 0 : i32}]} : () -> !neura.data<i32, i1>
Expand Down Expand Up @@ -380,3 +383,117 @@
// ASM-NEXT: GRANT_ONCE, [$0] -> [$0] (t=16, inv_iters=0)
// ASM-NEXT: } (idx_per_ii=16)
// ASM: PE(1,0):

// CHAIN-YAML-LABEL: core_id: "5"
// CHAIN-YAML: - index_per_ii: 11
// CHAIN-YAML: operations:
// CHAIN-YAML: - opcode: "NOT"
// CHAIN-YAML: id: 159
// CHAIN-YAML: dst_operands:
// CHAIN-YAML: - operand: "$3"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: - operand: "$8"
// CHAIN-YAML: - index_per_ii: 12
// CHAIN-YAML: operations:
// CHAIN-YAML: - opcode: "DATA_MOV"
// CHAIN-YAML: id: 1790000
// CHAIN-YAML: src_operands:
// CHAIN-YAML: - operand: "$8"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: dst_operands:
// CHAIN-YAML: - operand: "$1"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: - index_per_ii: 13
// CHAIN-YAML: operations:
// CHAIN-YAML: - opcode: "DATA_MOV"
// CHAIN-YAML: id: 1790001
// CHAIN-YAML: src_operands:
// CHAIN-YAML: - operand: "$1"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: dst_operands:
// CHAIN-YAML: - operand: "$0"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: - index_per_ii: 14
// CHAIN-YAML: operations:
// CHAIN-YAML: - opcode: "GRANT_PREDICATE"
// CHAIN-YAML: id: 190
// CHAIN-YAML: - opcode: "DATA_MOV"
// CHAIN-YAML: id: 1790002
// CHAIN-YAML: src_operands:
// CHAIN-YAML: - operand: "$0"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: dst_operands:
// CHAIN-YAML: - operand: "EAST"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML-LABEL: core_id: "6"
// CHAIN-YAML: - index_per_ii: 6
// CHAIN-YAML: operations:
// CHAIN-YAML: - opcode: "GRANT_PREDICATE"
// CHAIN-YAML: id: 189
// CHAIN-YAML: src_operands:
// CHAIN-YAML: - operand: "$7"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: - operand: "$8"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: - index_per_ii: 15
// CHAIN-YAML: operations:
// CHAIN-YAML: - opcode: "DATA_MOV"
// CHAIN-YAML: id: 179
// CHAIN-YAML: src_operands:
// CHAIN-YAML: - operand: "WEST"
// CHAIN-YAML: color: "RED"
// CHAIN-YAML: dst_operands:
// CHAIN-YAML: - operand: "$8"
// CHAIN-YAML: color: "RED"

// CHAIN-ASM-LABEL: PE(1,1):
// CHAIN-ASM: NOT, [$0] -> [$3], [$8], [$7], [$6], [NORTH, RED], [$5], [SOUTH, RED], [WEST, RED] (t=11, inv_iters=0)
// CHAIN-ASM: DATA_MOV, [$8] -> [$1] (t=12, inv_iters=0)
// CHAIN-ASM: DATA_MOV, [$1] -> [$0] (t=13, inv_iters=0)
// CHAIN-ASM: GRANT_PREDICATE, [$2], [$3] -> [$1] (t=14, inv_iters=0)
// CHAIN-ASM: DATA_MOV, [$0] -> [EAST, RED] (t=14, inv_iters=0)
// CHAIN-ASM-LABEL: PE(2,1):
// CHAIN-ASM: GRANT_PREDICATE, [$7], [$8] -> [$7] (t=23, inv_iters=1)
// CHAIN-ASM: DATA_MOV, [WEST, RED] -> [$8] (t=15, inv_iters=0)

// CHAIN-DFG: - id: 179
// CHAIN-DFG: opcode: "DATA_MOV"
// CHAIN-DFG: tile_x: 2
// CHAIN-DFG: tile_y: 1
// CHAIN-DFG: time_step: 15
// CHAIN-DFG: - id: 189
// CHAIN-DFG: opcode: "GRANT_PREDICATE"
// CHAIN-DFG: tile_x: 2
// CHAIN-DFG: tile_y: 1
// CHAIN-DFG: time_step: 23
// CHAIN-DFG: - id: 190
// CHAIN-DFG: opcode: "GRANT_PREDICATE"
// CHAIN-DFG: tile_x: 1
// CHAIN-DFG: tile_y: 1
// CHAIN-DFG: time_step: 14
// CHAIN-DFG: - id: 1790000
// CHAIN-DFG: opcode: "DATA_MOV"
// CHAIN-DFG: tile_x: 1
// CHAIN-DFG: tile_y: 1
// CHAIN-DFG: time_step: 12
// CHAIN-DFG: - id: 1790001
// CHAIN-DFG: opcode: "DATA_MOV"
// CHAIN-DFG: tile_x: 1
// CHAIN-DFG: tile_y: 1
// CHAIN-DFG: time_step: 13
// CHAIN-DFG: - id: 1790002
// CHAIN-DFG: opcode: "DATA_MOV"
// CHAIN-DFG: tile_x: 1
// CHAIN-DFG: tile_y: 1
// CHAIN-DFG: time_step: 14
// CHAIN-DFG: edges:
// CHAIN-DFG: - from: 159
// CHAIN-DFG-NEXT: to: 1790000
// CHAIN-DFG-NEXT: - from: 1790000
// CHAIN-DFG-NEXT: to: 1790001
// CHAIN-DFG-NEXT: - from: 1790001
// CHAIN-DFG-NEXT: to: 1790002
// CHAIN-DFG-NEXT: - from: 1790002
// CHAIN-DFG-NEXT: to: 179
// CHAIN-DFG-NEXT: - from: 179
// CHAIN-DFG-NEXT: to: 189
Loading
Loading