This is an archive of the discontinued LLVM Phabricator instance.

Add an MLIR example of some mimimal example of MLIR setup
ClosedPublic

Authored by mehdi_amini on Jul 25 2023, 2:06 AM.

Details

Summary

These may serve as example and showcase of the MLIR binary footprint.

Right now a release build of these tools on a linux machine shows:

  • mlir-cat: 2MB This includes the Core IR, the builtin dialect, the textual parser/printer, the support for bytecode.
  • mlir-minimal-opt: 3MB This adds all the tooling for an mlir-opt tool: the pass infrastructure and all the instrumentation associated with it.
  • mlir-miminal-opt-canonicalize: 4.8MB This add the canonicalizer pass, which pulls in all the pattern/rewrite machinery, including the PDL compiler and intepreter.

Diff Detail

Event Timeline

mehdi_amini created this revision.Jul 25 2023, 2:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 2:06 AM
mehdi_amini requested review of this revision.Jul 25 2023, 2:06 AM

update readme

mehdi_amini edited the summary of this revision. (Show Details)

Tweak readme

Mogball accepted this revision.Jul 25 2023, 8:23 AM

Nice. This looks useful

This revision is now accepted and ready to land.Jul 25 2023, 8:23 AM
rriddle accepted this revision.Jul 25 2023, 11:22 AM
rriddle added inline comments.
mlir/examples/minimal-opt/mlir-minimal-opt-canonicalize.cpp
1

Missed an update here?

mlir/examples/minimal-opt/mlir-minimal-opt.cpp
2

Missed an update here?

jpienaar accepted this revision.Jul 25 2023, 11:23 AM

What compile config were used in measured sizes?

mehdi_amini marked 2 inline comments as done.Jul 25 2023, 11:37 AM
mehdi_amini added inline comments.
mlir/examples/minimal-opt/mlir-cat.cpp
1

You missed this one River ;)

I think this broke the Windows build: https://lab.llvm.org/buildbot/#/builders/172/builds/29434. To investigate the issue, I took the buildbot offline to investigate. The error is:

[1/2] Building RC object tools\mlir\examples\minimal-opt\CMakeFiles\mlir-minimal-opt-can...zen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc.res
FAILED: tools/mlir/examples/minimal-opt/CMakeFiles/mlir-minimal-opt-canonicalize.dir/C_/Users/buildbot-worker/minipc-ryzen-win/flang-x86_64-windows/llvm-project/llvm/resources/windows_version_resource.rc.res
C:/PROGRA~1/CMake/bin/cmcldeps.exe RC C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc tools\mlir\examples\minimal-opt\CMakeFiles\mlir-minimal-opt-canonicalize.dir\C_\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc.res.d tools\mlir\examples\minimal-opt\CMakeFiles\mlir-minimal-opt-canonicalize.dir\C_\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc.res "Note: including file: " "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe" C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe -DGTEST_HAS_RTTI=0 -DMLIR_CUDA_CONVERSIONS_ENABLED=0 -DMLIR_INCLUDE_TESTS -DMLIR_ROCM_CONVERSIONS_ENABLED=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_LIBCPP_ENABLE_HARDENED_MODE -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DRC_FILE_VERSION=\"0\" -DRC_INTERNAL_NAME=\"mlir-minimal-opt-canonicalize\" -DRC_PRODUCT_NAME=\"LLVM\" -DRC_PRODUCT_VERSION=\"0\" -DRC_VERSION_FIELD_1=18 -DRC_VERSION_FIELD_2=0 -DRC_VERSION_FIELD_3=0 -DRC_VERSION_FIELD_4=0 -I C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\tools\mlir\examples\minimal-opt -I C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\mlir\examples\minimal-opt -I C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\include -I C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\include -I C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\mlir\include -I C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\tools\mlir\include -DWIN32 /nologo /fo tools\mlir\examples\minimal-opt\CMakeFiles\mlir-minimal-opt-canonicalize.dir\C_\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc.res C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc
C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.rc: fatal error C1083: Cannot open compiler generated file: 'windows_version_resource.i': No such file or directory
ninja: build stopped: subcommand failed.`

The issue is that C:\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\build\tools\mlir\examples\minimal-opt\CMakeFiles\mlir-minimal-opt-canonicalize.dir\C_\Users\buildbot-worker\minipc-ryzen-win\flang-x86_64-windows\llvm-project\llvm\resources\windows_version_resource.i exceeds MAX_PATH and msvc cl.exe seems to not support long paths yet.

CMake appends the full path of source files if they do not lie in the CMakeLists.txt's source directory (at other times it is a relative path with __ for ..) so you get the LLVM source directory twice in the build directory. CMake has a workaround CMAKE_OBJECT_PATH_MAX. That seems to work when sufficiently low (to account for appended filenames such as windows_version_resource.i), but I also get lots of CMake warnings:

CMake Warning in examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/CMakeLists.txt:
  The object file directory

    C:/Users/buildbot-worker/minipc-ryzen-win/flang-x86_64-windows/build/examples/OrcV2Examples/LLJITWithObjectLinkingLayerPlugin/CMakeFiles/LLJITWithObjectLinkingLayerPlugin.dir/./

  has 177 characters.  The maximum full path to an object file is 200
  characters (see CMAKE_OBJECT_PATH_MAX).  Object file

    LLJITWithObjectLinkingLayerPlugin.cpp.obj

  cannot be safely placed under this directory.  The build may not work
  correctly.

At the moment if feels safest/easiest to shorten the build directory for my buildbot. Putting the report here for others to find.


NB. minimal-opt/CMakeLists.txt compiles three executables in the same directory, all of them get the same llvm/resources/windows_version_resource.rc added to it. That's itself not a problem, but AddLLVM.txt also set set_property(SOURCE ${resource_file} COMPILE_DEFINITIONS RC_INTERNAL_NAME=${name}) with different ${name} for each executable, but CMake only stores one COMPILE_DEFINITIONS per source file and add_subdirectory. Therefore, all but one executable get incorrect version information.