diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index d37a7efa5..fd206db1c 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cbfa60d1e..7c39b6057 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 diff --git a/dev-requirements.txt b/dev-requirements.txt index 5206a54f1..6977ccc7d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -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 diff --git a/lib/beaver/mlir/capi_codegen.ex b/lib/beaver/mlir/capi_codegen.ex index 034a40911..fb2c9534d 100644 --- a/lib/beaver/mlir/capi_codegen.ex +++ b/lib/beaver/mlir/capi_codegen.ex @@ -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, diff --git a/lib/beaver/mlir/pattern.ex b/lib/beaver/mlir/pattern.ex index 4dcb91095..c390f272e 100644 --- a/lib/beaver/mlir/pattern.ex +++ b/lib/beaver/mlir/pattern.ex @@ -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 """ diff --git a/lib/beaver/mlir/pattern_set.ex b/lib/beaver/mlir/pattern_set.ex index 09f4852e2..dce37c471 100644 --- a/lib/beaver/mlir/pattern_set.ex +++ b/lib/beaver/mlir/pattern_set.ex @@ -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 diff --git a/native/mlir-c/CMakeLists.txt b/native/mlir-c/CMakeLists.txt index d6a2a6d19..41c795eb3 100644 --- a/native/mlir-c/CMakeLists.txt +++ b/native/mlir-c/CMakeLists.txt @@ -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() diff --git a/native/mlir-c/aggregate/MLIR/CMakeLists.txt b/native/mlir-c/aggregate/MLIR/CMakeLists.txt index 5ebb1855d..20153d3da 100644 --- a/native/mlir-c/aggregate/MLIR/CMakeLists.txt +++ b/native/mlir-c/aggregate/MLIR/CMakeLists.txt @@ -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 diff --git a/native/mlir-c/include/mlir-c/Beaver/PDL.h b/native/mlir-c/include/mlir-c/Beaver/PDL.h index 0f468eda6..44dd1946f 100644 --- a/native/mlir-c/include/mlir-c/Beaver/PDL.h +++ b/native/mlir-c/include/mlir-c/Beaver/PDL.h @@ -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); diff --git a/native/mlir-c/include/mlir/CAPI/Beaver.h b/native/mlir-c/include/mlir/CAPI/Beaver.h index 6c535b9a3..07fc4066a 100644 --- a/native/mlir-c/include/mlir/CAPI/Beaver.h +++ b/native/mlir-c/include/mlir/CAPI/Beaver.h @@ -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) diff --git a/native/mlir-c/lib/CAPI/Beaver.cpp b/native/mlir-c/lib/CAPI/Beaver.cpp index 8539a9c45..2d28eb3b5 100644 --- a/native/mlir-c/lib/CAPI/Beaver.cpp +++ b/native/mlir-c/lib/CAPI/Beaver.cpp @@ -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); } diff --git a/native/mlir-c/pre-built-llvm.cmake b/native/mlir-c/pre-built-llvm.cmake index 6e3396fc7..eea599096 100644 --- a/native/mlir-c/pre-built-llvm.cmake +++ b/native/mlir-c/pre-built-llvm.cmake @@ -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}") diff --git a/native/mlir-zig-proj/src/prelude.zig b/native/mlir-zig-proj/src/prelude.zig index 84a740cbc..0312e8d39 100644 --- a/native/mlir-zig-proj/src/prelude.zig +++ b/native/mlir-zig-proj/src/prelude.zig @@ -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; diff --git a/test/dialect_registry_test.exs b/test/dialect_registry_test.exs index 9b749f98f..3b8c56e44 100644 --- a/test/dialect_registry_test.exs +++ b/test/dialect_registry_test.exs @@ -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"}, @@ -39,6 +39,7 @@ defmodule DialectRegistryTest do {"llvm", "LLVM"}, {"math", "Math"}, {"memref", "MemRef"}, + {"mesh", "Mesh"}, {"ml_program", "MLProgram"}, {"nvgpu", "NVGPU"}, {"nvvm", "NVVM"}, @@ -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"} ]) diff --git a/test/memref_test.exs b/test/memref_test.exs index 8d62803fe..c6b10a052 100644 --- a/test/memref_test.exs +++ b/test/memref_test.exs @@ -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 diff --git a/test/pdl_test.exs b/test/pdl_test.exs index 716c7ec0c..1f17965bb 100644 --- a/test/pdl_test.exs +++ b/test/pdl_test.exs @@ -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 @@ -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) @@ -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 diff --git a/test/tosa_test.exs b/test/tosa_test.exs index 55d49137b..0d41af5ef 100644 --- a/test/tosa_test.exs +++ b/test/tosa_test.exs @@ -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) >>> []