From 3929d39dc055980e27e382a63b0438e17997fb09 Mon Sep 17 00:00:00 2001 From: Anderson Truong Date: Mon, 5 May 2025 12:16:37 -0700 Subject: [PATCH 1/2] Reapply "Remove multidim/dynamic size checks from memref to Handshake" This reverts commit 1e601a53a50cacaa06ecfebb9f4cbe173907715a. --- .../CFToHandshake/CFToHandshake.cpp | 6 ++-- lib/Dialect/Handshake/HandshakeOps.cpp | 10 +++---- test/Conversion/CFToHandshake/invalid.mlir | 29 ------------------- test/Dialect/Handshake/errors.mlir | 16 ---------- 4 files changed, 8 insertions(+), 53 deletions(-) diff --git a/lib/Conversion/CFToHandshake/CFToHandshake.cpp b/lib/Conversion/CFToHandshake/CFToHandshake.cpp index 33c728d94f..3412dae24a 100644 --- a/lib/Conversion/CFToHandshake/CFToHandshake.cpp +++ b/lib/Conversion/CFToHandshake/CFToHandshake.cpp @@ -268,9 +268,9 @@ void removeBasicBlocks(handshake::FuncOp funcOp) { } static LogicalResult isValidMemrefType(Location loc, mlir::MemRefType type) { - if (type.getNumDynamicDims() != 0 || type.getShape().size() != 1) - return emitError(loc) << "memref's must be both statically sized and " - "unidimensional."; + // if (type.getNumDynamicDims() != 0 || type.getShape().size() != 1) + // return emitError(loc) << "memref's must be both statically sized and " + // "unidimensional."; return success(); } diff --git a/lib/Dialect/Handshake/HandshakeOps.cpp b/lib/Dialect/Handshake/HandshakeOps.cpp index b20a666810..ca7a69d109 100644 --- a/lib/Dialect/Handshake/HandshakeOps.cpp +++ b/lib/Dialect/Handshake/HandshakeOps.cpp @@ -986,11 +986,11 @@ std::string handshake::MemoryOp::getResultName(unsigned int idx) { LogicalResult MemoryOp::verify() { auto memrefType = getMemRefType(); - if (memrefType.getNumDynamicDims() != 0) - return emitOpError() - << "memref dimensions for handshake.memory must be static."; - if (memrefType.getShape().size() != 1) - return emitOpError() << "memref must have only a single dimension."; + // if (memrefType.getNumDynamicDims() != 0) + // return emitOpError() + // << "memref dimensions for handshake.memory must be static."; + // if (memrefType.getShape().size() != 1) + // return emitOpError() << "memref must have only a single dimension."; unsigned opStCount = getStCount(); unsigned opLdCount = getLdCount(); diff --git a/test/Conversion/CFToHandshake/invalid.mlir b/test/Conversion/CFToHandshake/invalid.mlir index b0b04b0505..136d758f58 100644 --- a/test/Conversion/CFToHandshake/invalid.mlir +++ b/test/Conversion/CFToHandshake/invalid.mlir @@ -1,34 +1,5 @@ // RUN: circt-opt -lower-cf-to-handshake %s -split-input-file -verify-diagnostics -func.func @multidim() -> i32 { - // expected-error @+1 {{memref's must be both statically sized and unidimensional.}} - %0 = memref.alloc() : memref<2x2xi32> - %idx = arith.constant 0 : index - %1 = memref.load %0[%idx, %idx] : memref<2x2xi32> - return %1 : i32 -} - -// ----- - -func.func @dynsize(%dyn : index) -> i32{ - // expected-error @+1 {{memref's must be both statically sized and unidimensional.}} - %0 = memref.alloc(%dyn) : memref - %idx = arith.constant 0 : index - %1 = memref.load %0[%idx] : memref - return %1 : i32 -} - -// ----- - -func.func @singleton() -> (){ - // expected-error @+1 {{memref's must be both statically sized and unidimensional.}} - %0 = memref.alloc() : memref - %1 = memref.load %0[] : memref - return -} - -// ----- - func.func @non_canon_loop(%arg0 : memref<100xi32>, %arg1 : i32) -> i32 { // expected-error @below {{expected cmerges to have two operands}} %c0_i32 = arith.constant 0 : i32 diff --git a/test/Dialect/Handshake/errors.mlir b/test/Dialect/Handshake/errors.mlir index ab9a861b2a..b371ccfe26 100644 --- a/test/Dialect/Handshake/errors.mlir +++ b/test/Dialect/Handshake/errors.mlir @@ -103,14 +103,6 @@ handshake.func @invalid_instance_op(%ctrl : none) -> none { // ----- -handshake.func @invalid_multidim_memory(%ctrl : none) -> none { - // expected-error @+1 {{'handshake.memory' op memref must have only a single dimension.}} - memory [ld = 0, st = 0] () {id = 0 : i32, lsq = false} : memref<10x10xi8>, () -> () - return %ctrl : none -} - -// ----- - handshake.func @invalid_missing_lsq(%ctrl : none) -> none { // expected-error @+1 {{'handshake.memory' op requires attribute 'lsq'}} memory [ld = 0, st = 0] () {id = 0 : i32} : memref<10xi8>, () -> () @@ -119,14 +111,6 @@ handshake.func @invalid_missing_lsq(%ctrl : none) -> none { // ----- -handshake.func @invalid_dynamic_memory(%ctrl : none) -> none { - // expected-error @+1 {{'handshake.memory' op memref dimensions for handshake.memory must be static.}} - memory [ld = 0, st = 0] () {id = 0 : i32, lsq = false} : memref, () -> () - return %ctrl : none -} - -// ----- - // expected-error @+1 {{'handshake.func' op attribute 'argNames' has 2 entries but is expected to have 3.}} handshake.func @invalid_num_argnames(%a : i32, %b : i32, %c : none) -> none attributes {argNames = ["a", "b"]} { return %c : none From 02cdf372c25250005e18a9f7e949849c729e8f46 Mon Sep 17 00:00:00 2001 From: Anderson Truong Date: Thu, 8 May 2025 19:05:34 -0700 Subject: [PATCH 2/2] Add arith.select support for Handshake runner --- tools/handshake-runner/Simulation.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/handshake-runner/Simulation.cpp b/tools/handshake-runner/Simulation.cpp index 9e7a34b7ee..7a0af0283c 100644 --- a/tools/handshake-runner/Simulation.cpp +++ b/tools/handshake-runner/Simulation.cpp @@ -269,6 +269,8 @@ class HandshakeExecuter { std::vector &); LogicalResult execute(mlir::arith::ExtSIOp, std::vector &, std::vector &); + LogicalResult execute(mlir::arith::SelectOp, std::vector &, + std::vector &); LogicalResult execute(mlir::arith::ExtUIOp, std::vector &, std::vector &); LogicalResult execute(memref::LoadOp, std::vector &, std::vector &); @@ -452,6 +454,18 @@ LogicalResult HandshakeExecuter::execute(mlir::arith::ExtUIOp op, return success(); } +LogicalResult HandshakeExecuter::execute(mlir::arith::SelectOp op, + std::vector &in, + std::vector &out) { + APInt condition = any_cast(in[0]); + if (condition != 0) { + out[0] = in[1]; + } else { + out[0] = in[2]; + } + return success(); +} + LogicalResult HandshakeExecuter::execute(mlir::memref::LoadOp op, std::vector &in, std::vector &out) { @@ -725,7 +739,8 @@ HandshakeExecuter::HandshakeExecuter( mlir::arith::MulIOp, mlir::arith::MulFOp, mlir::arith::DivSIOp, mlir::arith::DivUIOp, mlir::arith::DivFOp, mlir::arith::IndexCastOp, - mlir::arith::ExtSIOp, mlir::arith::ExtUIOp, memref::AllocOp, + mlir::arith::SelectOp, mlir::arith::ExtSIOp, + mlir::arith::ExtUIOp, memref::AllocOp, memref::LoadOp, memref::StoreOp>([&](auto op) { strat = ExecuteStrategy::Default; return execute(op, inValues, outValues); @@ -876,8 +891,9 @@ HandshakeExecuter::HandshakeExecuter( mlir::arith::MulIOp, mlir::arith::MulFOp, mlir::arith::DivSIOp, mlir::arith::DivUIOp, mlir::arith::DivFOp, mlir::arith::IndexCastOp, - mlir::arith::ExtSIOp, mlir::arith::ExtUIOp, - mlir::arith::XOrIOp, handshake::InstanceOp>([&](auto op) { + mlir::arith::SelectOp, mlir::arith::ExtSIOp, + mlir::arith::ExtUIOp, mlir::arith::XOrIOp, + handshake::InstanceOp>([&](auto op) { strat = ExecuteStrategy::Default; return execute(op, inValues, outValues); })