From 62965bf643f6eb13c714a35cd033842cdaca3579 Mon Sep 17 00:00:00 2001 From: n0thingNoob Date: Tue, 21 Oct 2025 22:00:32 -0400 Subject: [PATCH 1/3] Update histogram_kernel.mlir to use O3 with fno-vectorize and fno-unroll-loops --- test/e2e/histogram/histogram_kernel.mlir | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/e2e/histogram/histogram_kernel.mlir b/test/e2e/histogram/histogram_kernel.mlir index de7a1b3b..59f99947 100644 --- a/test/e2e/histogram/histogram_kernel.mlir +++ b/test/e2e/histogram/histogram_kernel.mlir @@ -1,20 +1,22 @@ // Compiles the original C kernel to mlir, then lowers it via Neura. // TODO: Got error when using -O3 -fno-vectorize -fno-slp-vectorize -mllvm -force-vector-width=1 // Issue: https://github.com/coredac/dataflow/issues/164 -// RUN: clang++ -S -emit-llvm -O2 -o %t-kernel-full.ll %S/../../benchmark/CGRA-Bench/kernels/histogram/histogram.cpp +// RUN: clang++ -S -emit-llvm -O3 -fno-vectorize -fno-unroll-loops -o %t-kernel-full.ll %S/../../benchmark/CGRA-Bench/kernels/histogram/histogram.cpp // RUN: llvm-extract --rfunc=".*kernel.*" %t-kernel-full.ll -o %t-kernel-only.ll // RUN: mlir-translate --import-llvm %t-kernel-only.ll -o %t-kernel.mlir // RUN: mlir-neura-opt %t-kernel.mlir \ // RUN: --assign-accelerator \ // RUN: --lower-llvm-to-neura \ +// RUN: --promote-func-arg-to-const \ +// RUN: --fold-constant \ // RUN: --canonicalize-live-in \ // RUN: --leverage-predicated-value \ // RUN: --transform-ctrl-to-data-flow \ -// RUN: --promote-func-arg-to-const \ +// RUN: --fold-constant \ // RUN: --insert-data-mov \ // RUN: --map-to-accelerator="mapping-strategy=heuristic" \ -// RUN: --architecture-spec=%S/../../arch_spec/architecture.yaml \ +// RUN: --architecture-spec=../../arch_spec/architecture.yaml \ // RUN: --generate-code -o %t-mapping.mlir // RUN: FileCheck %s --input-file=%t-mapping.mlir -check-prefix=MAPPING // RUN: FileCheck %s --input-file=tmp-generated-instructions.yaml --check-prefix=YAML @@ -23,14 +25,13 @@ // MAPPING: module // MAPPING: func @_Z6kernelPfPi -// MAPPING: neura.constant +// MAPPING: neura.grant_once // MAPPING: neura.fdiv // MAPPING: neura.cast // YAML: instructions: -// YAML: - opcode: "CONSTANT" +// YAML: - opcode: "GRANT_ONCE" // YAML: - opcode: "FDIV" // YAML: - opcode: "CAST" -// ASM: PE(0,0): -// ASM: CONSTANT +// ASM: GRANT_ONCE From 4aa1b8cbf4348bed34c8d2e7b6c1b579eb1166db Mon Sep 17 00:00:00 2001 From: n0thingNoob Date: Tue, 21 Oct 2025 22:07:13 -0400 Subject: [PATCH 2/3] Add detailed MAPPING checks to histogram_kernel.mlir --- test/e2e/histogram/histogram_kernel.mlir | 41 +++++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/test/e2e/histogram/histogram_kernel.mlir b/test/e2e/histogram/histogram_kernel.mlir index 59f99947..d4237ae6 100644 --- a/test/e2e/histogram/histogram_kernel.mlir +++ b/test/e2e/histogram/histogram_kernel.mlir @@ -24,14 +24,45 @@ // MAPPING: module -// MAPPING: func @_Z6kernelPfPi -// MAPPING: neura.grant_once -// MAPPING: neura.fdiv -// MAPPING: neura.cast +// MAPPING: func.func +// MAPPING-SAME: compiled_ii = 8 +// MAPPING-SAME: mapping_mode = "spatial-temporal" +// MAPPING-SAME: mapping_strategy = "heuristic" +// MAPPING-SAME: rec_mii = 5 +// MAPPING-SAME: res_mii = 2 +// MAPPING-SAME: x_tiles = 4 +// MAPPING-SAME: y_tiles = 4 +// +// MAPPING-NEXT: %0 = "neura.grant_once"() <{constant_value = 0 : i64}> {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 0 : i32, x = 2 : i32, y = 2 : i32}]} : () -> !neura.data +// MAPPING-NEXT: %1 = "neura.grant_once"() <{constant_value = 1.800000e+01 : f32}> {mapping_locs = [{id = 11 : i32, resource = "tile", time_step = 4 : i32, x = 3 : i32, y = 2 : i32}]} : () -> !neura.data +// MAPPING-NEXT: %2 = neura.reserve : !neura.data +// MAPPING-NEXT: %3 = "neura.data_mov"(%1) {mapping_locs = [{id = 35 : i32, resource = "link", time_step = 4 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %4 = "neura.phi"(%2, %3) {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 5 : i32, x = 2 : i32, y = 2 : i32}]} : (!neura.data, !neura.data) -> !neura.data +// MAPPING-NEXT: %5 = neura.reserve : !neura.data +// MAPPING-NEXT: %6 = "neura.data_mov"(%0) {mapping_locs = [{id = 320 : i32, resource = "register", time_step = 0 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %7 = "neura.phi"(%5, %6) {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 1 : i32, x = 2 : i32, y = 2 : i32}]} : (!neura.data, !neura.data) -> !neura.data +// MAPPING-NEXT: %8 = "neura.data_mov"(%7) {mapping_locs = [{id = 34 : i32, resource = "link", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %9 = "neura.gep"(%8) <{operandSegmentSizes = array}> {lhs_value = "%arg0", mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 2 : i32, x = 2 : i32, y = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %10 = "neura.data_mov"(%9) {mapping_locs = [{id = 448 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %11 = "neura.load"(%10) {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 3 : i32, x = 2 : i32, y = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %12 = "neura.data_mov"(%11) {mapping_locs = [{id = 448 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %13 = "neura.fadd"(%12) {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 4 : i32, x = 2 : i32, y = 3 : i32}], rhs_value = -1.000000e+00 : f32} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %14 = "neura.data_mov"(%13) {mapping_locs = [{id = 448 : i32, resource = "register", time_step = 4 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %15 = "neura.fmul"(%14) {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 5 : i32, x = 2 : i32, y = 3 : i32}], rhs_value = 5.000000e+00 : f32} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %16 = "neura.data_mov"(%15) {mapping_locs = [{id = 448 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %17 = "neura.data_mov"(%4) {mapping_locs = [{id = 34 : i32, resource = "link", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %18 = "neura.fdiv"(%16, %17) {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 6 : i32, x = 2 : i32, y = 3 : i32}]} : (!neura.data, !neura.data) -> !neura.data +// MAPPING-NEXT: %19 = "neura.data_mov"(%18) {mapping_locs = [{id = 448 : i32, resource = "register", time_step = 6 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %20 = "neura.cast"(%19) <{cast_type = "fptosi"}> {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 7 : i32, x = 2 : i32, y = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %21 = "neura.data_mov"(%20) {mapping_locs = [{id = 43 : i32, resource = "link", time_step = 7 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: neura.sext %21 {mapping_locs = [{id = 13 : i32, resource = "tile", time_step = 8 : i32, x = 1 : i32, y = 3 : i32}]} : !neura.data -> !neura.data // YAML: instructions: // YAML: - opcode: "GRANT_ONCE" // YAML: - opcode: "FDIV" // YAML: - opcode: "CAST" -// ASM: GRANT_ONCE +// ASM: PE(2,2): +// ASM-NEXT: { +// ASM-NEXT: GRANT_ONCE, [#0] -> [$320] +// ASM-NEXT: } (t=0) From 4a770a6a6b3acab02d764355fe49cdc1488cf05c Mon Sep 17 00:00:00 2001 From: n0thingNoob Date: Tue, 21 Oct 2025 22:21:29 -0400 Subject: [PATCH 3/3] Add complete IR mapping checks to histogram_kernel.mlir --- test/e2e/histogram/histogram_kernel.mlir | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/e2e/histogram/histogram_kernel.mlir b/test/e2e/histogram/histogram_kernel.mlir index d4237ae6..4d546124 100644 --- a/test/e2e/histogram/histogram_kernel.mlir +++ b/test/e2e/histogram/histogram_kernel.mlir @@ -16,7 +16,7 @@ // RUN: --fold-constant \ // RUN: --insert-data-mov \ // RUN: --map-to-accelerator="mapping-strategy=heuristic" \ -// RUN: --architecture-spec=../../arch_spec/architecture.yaml \ +// RUN: --architecture-spec=%S/../../arch_spec/architecture.yaml \ // RUN: --generate-code -o %t-mapping.mlir // RUN: FileCheck %s --input-file=%t-mapping.mlir -check-prefix=MAPPING // RUN: FileCheck %s --input-file=tmp-generated-instructions.yaml --check-prefix=YAML @@ -55,7 +55,31 @@ // MAPPING-NEXT: %19 = "neura.data_mov"(%18) {mapping_locs = [{id = 448 : i32, resource = "register", time_step = 6 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %20 = "neura.cast"(%19) <{cast_type = "fptosi"}> {mapping_locs = [{id = 14 : i32, resource = "tile", time_step = 7 : i32, x = 2 : i32, y = 3 : i32}]} : (!neura.data) -> !neura.data // MAPPING-NEXT: %21 = "neura.data_mov"(%20) {mapping_locs = [{id = 43 : i32, resource = "link", time_step = 7 : i32}]} : (!neura.data) -> !neura.data -// MAPPING-NEXT: neura.sext %21 {mapping_locs = [{id = 13 : i32, resource = "tile", time_step = 8 : i32, x = 1 : i32, y = 3 : i32}]} : !neura.data -> !neura.data +// MAPPING-NEXT: %22 = neura.sext %21 {mapping_locs = [{id = 13 : i32, resource = "tile", time_step = 8 : i32, x = 1 : i32, y = 3 : i32}]} : !neura.data -> !neura.data +// MAPPING-NEXT: %23 = "neura.data_mov"(%22) {mapping_locs = [{id = 40 : i32, resource = "link", time_step = 8 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %24 = "neura.gep"(%23) <{operandSegmentSizes = array}> {lhs_value = "%arg1", mapping_locs = [{id = 12 : i32, resource = "tile", time_step = 9 : i32, x = 0 : i32, y = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %25 = "neura.data_mov"(%24) {mapping_locs = [{id = 39 : i32, resource = "link", time_step = 9 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %26 = "neura.load"(%25) {mapping_locs = [{id = 8 : i32, resource = "tile", time_step = 10 : i32, x = 0 : i32, y = 2 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %27 = "neura.data_mov"(%26) {mapping_locs = [{id = 24 : i32, resource = "link", time_step = 10 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %28 = "neura.add"(%27) {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 11 : i32, x = 1 : i32, y = 2 : i32}], rhs_value = 1 : i32} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %29 = "neura.data_mov"(%28) {mapping_locs = [{id = 288 : i32, resource = "register", time_step = 11 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %30 = "neura.data_mov"(%24) {mapping_locs = [{id = 38 : i32, resource = "link", time_step = 9 : i32}, {id = 42 : i32, resource = "link", time_step = 10 : i32}, {id = 289 : i32, resource = "register", time_step = 11 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: "neura.store"(%29, %30) {mapping_locs = [{id = 9 : i32, resource = "tile", time_step = 12 : i32, x = 1 : i32, y = 2 : i32}]} : (!neura.data, !neura.data) -> () +// MAPPING-NEXT: %31 = "neura.data_mov"(%7) {mapping_locs = [{id = 320 : i32, resource = "register", time_step = 1 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %32 = "neura.add"(%31) {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 2 : i32, x = 2 : i32, y = 2 : i32}], rhs_value = 1 : i64} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %33 = "neura.data_mov"(%32) {mapping_locs = [{id = 320 : i32, resource = "register", time_step = 2 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %34 = "neura.icmp"(%33) <{cmpType = "eq"}> {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 3 : i32, x = 2 : i32, y = 2 : i32}], rhs_value = 20 : i64} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %35 = "neura.data_mov"(%34) {mapping_locs = [{id = 320 : i32, resource = "register", time_step = 3 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %36 = "neura.not"(%35) {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 4 : i32, x = 2 : i32, y = 2 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %37 = "neura.data_mov"(%32) {mapping_locs = [{id = 321 : i32, resource = "register", time_step = 2 : i32}, {id = 321 : i32, resource = "register", time_step = 3 : i32}, {id = 321 : i32, resource = "register", time_step = 4 : i32}, {id = 321 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %38 = "neura.data_mov"(%36) {mapping_locs = [{id = 320 : i32, resource = "register", time_step = 4 : i32}, {id = 320 : i32, resource = "register", time_step = 5 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %39 = neura.grant_predicate %37, %38 {mapping_locs = [{id = 10 : i32, resource = "tile", time_step = 6 : i32, x = 2 : i32, y = 2 : i32}]} : !neura.data, !neura.data -> !neura.data +// MAPPING-NEXT: neura.ctrl_mov %39 -> %5 {mapping_locs = [{id = 321 : i32, resource = "register", time_step = 6 : i32}, {id = 321 : i32, resource = "register", time_step = 7 : i32}, {id = 321 : i32, resource = "register", time_step = 8 : i32}]} : !neura.data !neura.data +// MAPPING-NEXT: %40 = "neura.data_mov"(%4) {mapping_locs = [{id = 33 : i32, resource = "link", time_step = 5 : i32}, {id = 192 : i32, resource = "register", time_step = 6 : i32}, {id = 192 : i32, resource = "register", time_step = 7 : i32}, {id = 192 : i32, resource = "register", time_step = 8 : i32}, {id = 192 : i32, resource = "register", time_step = 9 : i32}, {id = 192 : i32, resource = "register", time_step = 10 : i32}, {id = 192 : i32, resource = "register", time_step = 11 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %41 = "neura.data_mov"(%36) {mapping_locs = [{id = 33 : i32, resource = "link", time_step = 4 : i32}, {id = 193 : i32, resource = "register", time_step = 5 : i32}, {id = 193 : i32, resource = "register", time_step = 6 : i32}, {id = 193 : i32, resource = "register", time_step = 7 : i32}, {id = 193 : i32, resource = "register", time_step = 8 : i32}, {id = 193 : i32, resource = "register", time_step = 9 : i32}, {id = 193 : i32, resource = "register", time_step = 10 : i32}, {id = 193 : i32, resource = "register", time_step = 11 : i32}]} : (!neura.data) -> !neura.data +// MAPPING-NEXT: %42 = neura.grant_predicate %40, %41 {mapping_locs = [{id = 6 : i32, resource = "tile", time_step = 12 : i32, x = 2 : i32, y = 1 : i32}]} : !neura.data, !neura.data -> !neura.data +// MAPPING-NEXT: neura.ctrl_mov %42 -> %2 {mapping_locs = [{id = 20 : i32, resource = "link", time_step = 12 : i32}]} : !neura.data !neura.data +// MAPPING-NEXT: "neura.return"() {mapping_locs = [{id = 15 : i32, resource = "tile", time_step = 12 : i32, x = 3 : i32, y = 3 : i32}]} : () -> () // YAML: instructions: // YAML: - opcode: "GRANT_ONCE"