Skip to content

Commit

Permalink
Merge pull request #1265 from WoutLegiest:arith-to-cggi-quart
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 716281540
  • Loading branch information
copybara-github committed Jan 16, 2025
2 parents bcab230 + c3a3f0b commit 3917e51
Show file tree
Hide file tree
Showing 15 changed files with 552 additions and 595 deletions.
414 changes: 414 additions & 0 deletions lib/Dialect/Arith/Conversions/ArithToCGGIQuart/ArithToCGGIQuart.cpp

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions lib/Dialect/Arith/Conversions/ArithToCGGIQuart/ArithToCGGIQuart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef LIB_DIALECT_ARITH_CONVERSIONS_ARITHTOCGGIQUART_ARITHTOCGGIQUART_H_
#define LIB_DIALECT_ARITH_CONVERSIONS_ARITHTOCGGIQUART_ARITHTOCGGIQUART_H_

#include "mlir/include/mlir/Pass/Pass.h" // from @llvm-project

namespace mlir::heir::arith {

#define GEN_PASS_DECL
#include "lib/Dialect/Arith/Conversions/ArithToCGGIQuart/ArithToCGGIQuart.h.inc"

#define GEN_PASS_REGISTRATION
#include "lib/Dialect/Arith/Conversions/ArithToCGGIQuart/ArithToCGGIQuart.h.inc"

} // namespace mlir::heir::arith

#endif // LIB_DIALECT_ARITH_CONVERSIONS_ARITHTOCGGIQUART_ARITHTOCGGIQUART_H_
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#ifndef LIB_DIALECT_ARITH_TRANSFORMS_PASSES_TD_
#define LIB_DIALECT_ARITH_TRANSFORMS_PASSES_TD_
#ifndef LIB_DIALECT_ARITH_CONVERSIONS_ARITHTOCGGIQUART_TD_
#define LIB_DIALECT_ARITH_CONVERSIONS_ARITHTOCGGIQUART_TD_

include "mlir/Pass/PassBase.td"

def QuarterWideInt : Pass<"arith-quarter-wide-int"> {

let summary = "Convert high precision arithmetic operations to a sequence of lower precision operations";
let description = [{
def ArithToCGGIQuart : Pass<"arith-to-cggi-quart"> {
let summary = "Lower `arith` to `cggi` dialect and divide each operation into smaller parts.";
let description = [{
This pass converts high precision arithmetic operations, i.e. operations on 32 bit integer,
into a sequence of lower precision operations, i.e 8b operations.
Currently, the pass splits the 32b integer into four 8b integers, using the tensor dialect.
These smaller integers are stored in an 16b integer, so that we don't lose the carry information.
This pass converts the `arith` dialect to the `cggi` dialect.

Based on the `arith-emulate-wide-int` pass from the MLIR arith dialect.

General assumption: the first element in the tensor is also the LSB element.
}];
let dependentDialects = [
"mlir::arith::ArithDialect",
"mlir::memref::MemRefDialect",
"mlir::tensor::TensorDialect",
"mlir::heir::cggi::CGGIDialect",
];
}

#endif // LIB_DIALECT_ARITH_TRANSFORMS_PASSES_TD_
#endif // LIB_DIALECT_ARITH_CONVERSIONS_ARITHTOCGGIQUART_ARITHTOCGGIQUART_TD_
49 changes: 49 additions & 0 deletions lib/Dialect/Arith/Conversions/ArithToCGGIQuart/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library")

package(
default_applicable_licenses = ["@heir//:license"],
default_visibility = ["//visibility:public"],
)

cc_library(
name = "ArithToCGGIQuart",
srcs = ["ArithToCGGIQuart.cpp"],
hdrs = ["ArithToCGGIQuart.h"],
deps = [
":pass_inc_gen",
"@heir//lib/Dialect/CGGI/IR:Dialect",
"@heir//lib/Dialect/LWE/IR:Dialect",
"@heir//lib/Utils:ConversionUtils",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:AffineDialect",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:TensorDialect",
"@llvm-project//mlir:TransformUtils",
],
)

gentbl_cc_library(
name = "pass_inc_gen",
tbl_outs = [
(
[
"-gen-pass-decls",
"-name=ArithToCGGIQuart",
],
"ArithToCGGIQuart.h.inc",
),
(
["-gen-pass-doc"],
"ArithToCGGIQuart.md",
),
],
tblgen = "@llvm-project//mlir:mlir-tblgen",
td_file = "ArithToCGGIQuart.td",
deps = [
"@llvm-project//mlir:OpBaseTdFiles",
"@llvm-project//mlir:PassBaseTdFiles",
],
)
41 changes: 0 additions & 41 deletions lib/Dialect/Arith/Transforms/BUILD

This file was deleted.

17 changes: 0 additions & 17 deletions lib/Dialect/Arith/Transforms/Passes.h

This file was deleted.

Loading

0 comments on commit 3917e51

Please sign in to comment.