Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to MLIR 18 #222

Merged
merged 37 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
053efa4
add UnmanagedDenseResourceElementsAttrGetDeleteCallback
jackalcooper Nov 4, 2023
98d5ce6
fix tests
jackalcooper Nov 4, 2023
58e6310
Update CMakeLists.txt
jackalcooper Nov 4, 2023
2265758
ubuntu-20.04
jackalcooper Nov 4, 2023
ca7a49f
Revert "ubuntu-20.04"
jackalcooper Nov 4, 2023
b508897
Update dev-requirements.txt
jackalcooper Nov 4, 2023
6bd91e9
Refine note
jackalcooper Nov 4, 2023
0102ec1
try fix
jackalcooper Nov 4, 2023
63e42ee
Update CMakeLists.txt
jackalcooper Nov 4, 2023
4a24918
rm MlirPDLPatternModule
jackalcooper Nov 4, 2023
8a25772
Revert "Revert "ubuntu-20.04""
jackalcooper Nov 4, 2023
0609559
Update elixir.yml
jackalcooper Nov 4, 2023
a3e15a5
Update elixir.yml
jackalcooper Nov 4, 2023
3c77772
add_definitions(-U_GLIBCXX_ASSERTIONS)
jackalcooper Nov 4, 2023
ed37ff6
Revert "add_definitions(-U_GLIBCXX_ASSERTIONS)"
jackalcooper Nov 4, 2023
0c36e3b
Use Release
jackalcooper Nov 5, 2023
dd1a2f3
try fix
jackalcooper Nov 5, 2023
2be7502
try fix
jackalcooper Nov 5, 2023
3ba84eb
clean CXX11_ABI related config
jackalcooper Nov 5, 2023
ae0e430
explicit ubuntu-22.04
jackalcooper Nov 5, 2023
84255d0
opt 25.0
jackalcooper Nov 5, 2023
9ad3d61
Update dev-requirements.txt
jackalcooper Nov 9, 2023
1514b3e
Update elixir.yml
jackalcooper Nov 9, 2023
fadc05d
Revert "opt 25.0"
jackalcooper Nov 9, 2023
4b9c1d5
Revert "explicit ubuntu-22.04"
jackalcooper Nov 9, 2023
7bc8c7f
Update Makefile
jackalcooper Nov 9, 2023
452ef16
Update Makefile
jackalcooper Nov 9, 2023
d36ec92
Revert "Update Makefile"
jackalcooper Nov 9, 2023
7f042a8
-static-libgcc -static-libstdc++
jackalcooper Nov 9, 2023
1aeea8e
revert
jackalcooper Nov 15, 2023
3360ff8
set cxx standard
jackalcooper Nov 15, 2023
44ce9c7
gcc12
jackalcooper Nov 15, 2023
16ea7bd
install
jackalcooper Nov 15, 2023
ef58791
Revert "install"
jackalcooper Nov 15, 2023
bf966b6
Revert "gcc12"
jackalcooper Nov 15, 2023
c6713bd
use 24.2
jackalcooper Nov 15, 2023
a5c7c8b
fix
jackalcooper Nov 15, 2023
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
7 changes: 4 additions & 3 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ concurrency:
cancel-in-progress: true
jobs:
build:
name: Test OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
runs-on: ubuntu-latest
name: otp${{matrix.otp}}-ex${{matrix.elixir}} / ${{matrix.runs-on}}
runs-on: ${{matrix.runs-on}}
strategy:
fail-fast: false
matrix:
runs-on: ["ubuntu-latest"]
otp: ["24.2", "25.0"]
elixir: ["1.13.0", "1.14.0", "1.15.0"]
elixir: ["1.13.0", "1.15.0"]
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ jobs:
matrix:
nif: ["2.16"]
job:
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
steps:
- uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.14.0" # Define the elixir version [required]
otp-version: "24.1" # Define the OTP version [required]
otp-version: "24.2" # Define the OTP version [required]
- name: Set up Zig
uses: goto-bus-stop/setup-zig@v1
with:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
echo "==> before replace needed"
patchelf --print-needed $sofile

patchelf --replace-needed libMLIRBeaver.so.17 libMLIRBeaver.so $sofile
patchelf --replace-needed libMLIRBeaver.so.18 libMLIRBeaver.so $sofile

echo "==> after"
patchelf --print-needed $sofile
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mlir==17.0.0+ffbca7e9
mlir==18.0.0.2023110801+c86d35a
--find-links https://github.com/makslevental/mlir-wheels/releases/expanded_assets/latest
59 changes: 59 additions & 0 deletions lib/beaver/mlir/capi_codegen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,65 @@ defmodule Beaver.MLIR.CAPI.CodeGen do
{:ok, %KindDecl{zig_t: type, module_name: Beaver.MLIR.GenericCallback}}
end

def type_gen(
_root_module,
{:optional_type,
{:ref,
[
:*,
:const,
{:fn,
%Zig.Parser.FnOptions{
position: nil,
doc_comment: nil,
block: nil,
align: nil,
linksection: nil,
callconv: {:enum_literal, :C},
extern: false,
export: false,
pub: false,
inline: :maybe
},
[
params: [
{:_,
%Zig.Parser.ParamDeclOption{
doc_comment: nil,
noalias: false,
comptime: false
}, {:optional_type, {:ref, [:*, :anyopaque]}}},
{:_,
%Zig.Parser.ParamDeclOption{
doc_comment: nil,
noalias: false,
comptime: false
}, {:optional_type, {:ref, [:*, :const, :anyopaque]}}},
{:_,
%Zig.Parser.ParamDeclOption{
doc_comment: nil,
noalias: false,
comptime: false
}, :usize},
{:_,
%Zig.Parser.ParamDeclOption{
doc_comment: nil,
noalias: false,
comptime: false
}, :usize}
],
type: :void
]}
]}} =
type
) do
{:ok,
%KindDecl{
zig_t: type,
module_name: Beaver.MLIR.UnmanagedDenseResourceElementsAttrGetDeleteCallback
}}
end

def type_gen(_root_module, type)
when type in [
:MlirPass,
Expand Down
22 changes: 0 additions & 22 deletions lib/beaver/mlir/pattern.ex
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
defmodule Beaver.MLIR.Pattern do
alias Beaver.MLIR
import MLIR.Sigils
alias Beaver.MLIR.CAPI

@moduledoc """
Although this module is `MLIR.Pattern`, at this point it is a synonym of PDL patterns.
Pattern-matching is done by MLIR which works in a different way from Erlang pattern-matching.
The major difference is that MLIR pattern-matching will greedily match the patterns and maximize the benefit.
Compiled patterns will be saved as module attributes in MLIR assembly format.
"""

def from_string(pdl_pattern_str, opts \\ []) when is_binary(pdl_pattern_str) do
Beaver.Deferred.from_opts(
opts,
fn ctx ->
pattern_module = ~m{#{pdl_pattern_str}}.(ctx)
if MLIR.is_null(pattern_module), do: raise("fail to parse module")
MLIR.Operation.verify!(pattern_module)
pdl_pattern = CAPI.beaverPDLPatternGet(pattern_module)
pdl_pattern
end
)
end

@apply_default_opts [debug: false]
@doc """
Expand Down
7 changes: 1 addition & 6 deletions lib/beaver/mlir/pattern_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ defmodule Beaver.MLIR.PatternSet do
CAPI.beaverRewritePatternSetGet(ctx)
end

def insert(pattern_set, %Beaver.MLIR.Module{} = module) do
pattern_module = CAPI.beaverPDLPatternGet(module)
insert(pattern_set, pattern_module)
end

def insert(pattern_set, %Beaver.MLIR.CAPI.MlirPDLPatternModule{} = pattern_module) do
def insert(pattern_set, %Beaver.MLIR.Module{} = pattern_module) do
CAPI.beaverPatternSetAddOwnedPDLPattern(pattern_set, pattern_module)
pattern_set
end
Expand Down
6 changes: 5 additions & 1 deletion native/mlir-c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
cmake_minimum_required(VERSION 3.13.4)
set(CMAKE_BUILD_TYPE
RelWithDebInfo
Release
CACHE STRING "")
project(mlir-beaver)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

if(POLICY CMP0116)
cmake_policy(SET CMP0116 OLD)
endif()
Expand Down
2 changes: 1 addition & 1 deletion native/mlir-c/aggregate/MLIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(LIBS

message(STATUS "MLIR libs: ${LIBS}")

# This lib is for dlopen
# This lib is for dlopen or being linked by Zig/Rust
add_mlir_aggregate(
MLIRBeaver
SHARED
Expand Down
5 changes: 1 addition & 4 deletions native/mlir-c/include/mlir-c/Beaver/PDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ extern "C" {
}; \
typedef struct name name

DEFINE_C_API_STRUCT(MlirPDLPatternModule, void);
DEFINE_C_API_STRUCT(MlirRewritePatternSet, void);

#undef DEFINE_C_API_STRUCT

MLIR_CAPI_EXPORTED MlirPDLPatternModule beaverPDLPatternGet(MlirModule module);

MLIR_CAPI_EXPORTED MlirRewritePatternSet
beaverRewritePatternSetGet(MlirContext context);

MLIR_CAPI_EXPORTED MlirRewritePatternSet beaverPatternSetAddOwnedPDLPattern(
MlirRewritePatternSet patternList, MlirPDLPatternModule pdlPattern);
MlirRewritePatternSet patternList, MlirModule module);

MLIR_CAPI_EXPORTED MlirLogicalResult beaverApplyOwnedPatternSetOnRegion(
MlirRegion region, MlirRewritePatternSet patternList);
Expand Down
1 change: 0 additions & 1 deletion native/mlir-c/include/mlir/CAPI/Beaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

DEFINE_C_API_PTR_METHODS(MlirPDLPatternModule, mlir::PDLPatternModule)
DEFINE_C_API_PTR_METHODS(MlirRewritePatternSet, mlir::RewritePatternSet)
DEFINE_C_API_PTR_METHODS(MlirOperand, mlir::Value::use_iterator)
DEFINE_C_API_METHODS(MlirRegisteredOperationName, mlir::RegisteredOperationName)
Expand Down
15 changes: 3 additions & 12 deletions native/mlir-c/lib/CAPI/Beaver.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
// include otherwise on linux it can't find the symbol
#define _GLIBCXX_USE_CXX11_ABI 0
#include "mlir/CAPI/Beaver.h"
#include "mlir/CAPI/Pass.h"
#include "mlir/CAPI/Registration.h"

#include "mlir/CAPI/Beaver.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"

using namespace mlir;

MLIR_CAPI_EXPORTED MlirPDLPatternModule beaverPDLPatternGet(MlirModule module) {
// should this module be removed from parent?
auto *pdlPattern = new PDLPatternModule(unwrap(module));
return wrap(pdlPattern);
}

MLIR_CAPI_EXPORTED MlirRewritePatternSet
beaverRewritePatternSetGet(MlirContext context) {
return wrap(new RewritePatternSet(unwrap(context)));
}

MLIR_CAPI_EXPORTED MlirRewritePatternSet beaverPatternSetAddOwnedPDLPattern(
MlirRewritePatternSet patternList, MlirPDLPatternModule pdlPattern) {
auto &set = unwrap(patternList)->add(std::move(*(unwrap(pdlPattern))));
MlirRewritePatternSet patternList, MlirModule module) {
auto &set = unwrap(patternList)->add(PDLPatternModule(unwrap(module)));
return wrap(&set);
}

Expand Down
5 changes: 0 additions & 5 deletions native/mlir-c/pre-built-llvm.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

set(CMAKE_CXX_STANDARD
17
CACHE STRING "C++ standard to conform to")

find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
Expand Down
1 change: 1 addition & 0 deletions native/mlir-zig-proj/src/prelude.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub const DiagnosticHandlerDeleteUserData = ?*const fn (?*anyopaque) callconv(.C
pub const ExternalPassConstruct = ?*const fn (?*anyopaque) callconv(.C) ?*anyopaque;
pub const ExternalPassRun = ?*const fn (c.MlirOperation, c.MlirExternalPass, ?*anyopaque) callconv(.C) void;
pub const GenericCallback = ?*const fn (c.MlirContext, ?*anyopaque) callconv(.C) c.MlirLogicalResult;
pub const UnmanagedDenseResourceElementsAttrGetDeleteCallback = ?*const fn (?*anyopaque, ?*const anyopaque, usize, usize) callconv(.C) void;
pub const AffineMapCompressUnusedSymbolsPopulateResult = ?*const fn (?*anyopaque, isize, c.MlirAffineMap) callconv(.C) void;
pub const SymbolTableWalkSymbolTablesCallback = ?*const fn (c.MlirOperation, bool, ?*anyopaque) callconv(.C) void;
pub usingnamespace c;
5 changes: 4 additions & 1 deletion test/dialect_registry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ defmodule DialectRegistryTest do
{"amx", "AMX"},
{"arith", "Arith"},
{"arm_neon", "ArmNeon"},
{"arm_sve", "ArmSVE"},
{"arm_sme", "ArmSME"},
{"arm_sve", "ArmSVE"},
{"async", "Async"},
{"bufferization", "Bufferization"},
{"builtin", "Builtin"},
Expand All @@ -39,6 +39,7 @@ defmodule DialectRegistryTest do
{"llvm", "LLVM"},
{"math", "Math"},
{"memref", "MemRef"},
{"mesh", "Mesh"},
{"ml_program", "MLProgram"},
{"nvgpu", "NVGPU"},
{"nvvm", "NVVM"},
Expand All @@ -52,8 +53,10 @@ defmodule DialectRegistryTest do
{"sparse_tensor", "SparseTensor"},
{"spirv", "SPIRV"},
{"tensor", "Tensor"},
{"test_dyn", "TestDyn"},
{"tosa", "TOSA"},
{"transform", "Transform"},
{"ub", "Ub"},
{"vector", "Vector"},
{"x86vector", "X86Vector"}
])
Expand Down
1 change: 0 additions & 1 deletion test/memref_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ defmodule MemRefTest do
~w{finalizing-bufferize buffer-deallocation convert-linalg-to-loops}
)
|> convert_scf_to_cf
|> convert_linalg_to_llvm()
|> MLIR.Pass.Composer.append("finalize-memref-to-llvm")
|> convert_func_to_llvm
|> reconcile_unrealized_casts
Expand Down
21 changes: 2 additions & 19 deletions test/pdl_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ defmodule PDLTest do
ir_module = MLIR.Module.create(ctx, @apply_rewrite_op_ir)
MLIR.Operation.verify!(pattern_module)
MLIR.Operation.verify!(ir_module)
pdl_pattern = CAPI.beaverPDLPatternGet(pattern_module)
pattern_set = CAPI.beaverRewritePatternSetGet(ctx)
pattern_set = CAPI.beaverPatternSetAddOwnedPDLPattern(pattern_set, pdl_pattern)
pattern_set = CAPI.beaverPatternSetAddOwnedPDLPattern(pattern_set, pattern_module)

region =
ir_module
Expand Down Expand Up @@ -159,9 +158,8 @@ defmodule PDLTest do
pattern_string = MLIR.to_string(pattern_module)
assert String.contains?(pattern_string, "test.op")
assert String.contains?(pattern_string, "test.success2")
pdl_pattern = CAPI.beaverPDLPatternGet(pattern_module)
pattern_set = CAPI.beaverRewritePatternSetGet(ctx)
pattern_set = CAPI.beaverPatternSetAddOwnedPDLPattern(pattern_set, pdl_pattern)
pattern_set = CAPI.beaverPatternSetAddOwnedPDLPattern(pattern_set, pattern_module)
region = ir_module |> MLIR.Operation.from_module() |> CAPI.mlirOperationGetFirstRegion()
result = CAPI.beaverApplyOwnedPatternSetOnRegion(region, pattern_set)

Expand All @@ -173,21 +171,6 @@ defmodule PDLTest do
CAPI.mlirContextDestroy(ctx)
end

test "load from string", test_context do
%MLIR.CAPI.MlirPDLPatternModule{} =
"""
module @erase {
pdl.pattern : benefit(1) {
%root = operation "foo.op"
rewrite %root {
erase %root
}
}
}
"""
|> MLIR.Pattern.from_string(ctx: test_context[:ctx])
end

test "replace tosa", test_context do
defmodule TestTOSAPatterns do
def gen_ir_module(ctx) do
Expand Down
2 changes: 1 addition & 1 deletion test/tosa_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule TosaTest do
v0 = TOSA.add(arg0, arg1) >>> Type.ranked_tensor([2, 3], Type.f32())

v0 =
TOSA.mul(v0, arg1, {:shift, ~a{0 : i32}}) >>>
TOSA.mul(v0, arg1, {:shift, ~a{0 : i8}}) >>>
Type.ranked_tensor([2, 3], Type.f32())

Func.return(v0) >>> []
Expand Down
Loading