{"id":13831329,"url":"https://github.com/j2kun/mlir-tutorial","last_synced_at":"2025-05-15T02:03:35.574Z","repository":{"id":172260201,"uuid":"606225969","full_name":"j2kun/mlir-tutorial","owner":"j2kun","description":"MLIR For Beginners tutorial","archived":false,"fork":false,"pushed_at":"2025-02-07T22:13:14.000Z","size":149,"stargazers_count":972,"open_issues_count":5,"forks_count":86,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-05-15T02:03:20.696Z","etag":null,"topics":["compilers","mlir","tutorial"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/j2kun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-24T22:18:51.000Z","updated_at":"2025-05-14T13:32:06.000Z","dependencies_parsed_at":"2024-02-24T20:40:29.862Z","dependency_job_id":"2107772c-d948-4f33-bd17-ed11cbe66a59","html_url":"https://github.com/j2kun/mlir-tutorial","commit_stats":null,"previous_names":["j2kun/mlir-tutorial"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2kun%2Fmlir-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2kun%2Fmlir-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2kun%2Fmlir-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/j2kun%2Fmlir-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/j2kun","download_url":"https://codeload.github.com/j2kun/mlir-tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259369,"owners_count":22040819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compilers","mlir","tutorial"],"created_at":"2024-08-04T10:01:24.739Z","updated_at":"2025-05-15T02:03:35.550Z","avatar_url":"https://github.com/j2kun.png","language":"C++","readme":"# MLIR For Beginners\n\nThis is the code repository for a series of articles on the\n[MLIR framework](https://mlir.llvm.org/) for building compilers.\n\n## Articles\n\n1.  [Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/)\n2.  [Running and Testing a Lowering](https://jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/)\n3.  [Writing Our First Pass](https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/)\n4.  [Using Tablegen for Passes](https://jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/)\n5.  [Defining a New Dialect](https://jeremykun.com/2023/08/21/mlir-defining-a-new-dialect/)\n6.  [Using Traits](https://jeremykun.com/2023/09/07/mlir-using-traits/)\n7.  [Folders and Constant Propagation](https://jeremykun.com/2023/09/11/mlir-folders/)\n8.  [Verifiers](https://jeremykun.com/2023/09/13/mlir-verifiers/)\n9.  [Canonicalizers and Declarative Rewrite Patterns](https://jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/)\n10. [Dialect Conversion](https://jeremykun.com/2023/10/23/mlir-dialect-conversion/)\n11. [Lowering through LLVM](https://jeremykun.com/2023/11/01/mlir-lowering-through-llvm/)\n12. [A Global Optimization and Dataflow Analysis](https://jeremykun.com/2023/11/15/mlir-a-global-optimization-and-dataflow-analysis/)\n12. [Defining Patterns with PDLL](https://www.jeremykun.com/2024/08/04/mlir-pdll/)\n\n## Bazel build\n\nBazel is one of two supported build systems for this tutorial. The other is\nCMake. If you're unfamiliar with Bazel, you can read the tutorials at\n[https://bazel.build/start](https://bazel.build/start). Familiarity with Bazel\nis not required to build or test, but it is required to follow the articles in\nthe tutorial series and explained in the first article,\n[Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/).\nThe CMake build is maintained, but was added at article 10 (Dialect Conversion)\nand will not be explained in the articles.\n\n### Prerequisites\n\nInstall Bazelisk via instructions at\n[https://github.com/bazelbuild/bazelisk#installation](https://github.com/bazelbuild/bazelisk#installation).\nThis should create the `bazel` command on your system.\n\nYou should also have a modern C++ compiler on your system, either `gcc` or\n`clang`, which Bazel will detect.\n\n### Build and test\n\nRun\n\n```bash\nbazel build ...:all\nbazel test ...:all\n```\n\n## CMake build\n\nCMake is one of two supported build systems for this tutorial. The other is\nBazel. If you're unfamiliar with CMake, you can read the tutorials at\n[https://cmake.org/getting-started/](https://cmake.org/getting-started/). The\nCMake build is maintained, but was added at article 10 (Dialect Conversion) and\nwill not be explained in the articles.\n\n### Prerequisites\n\n*   Make sure you have installed everything needed to build LLVM\n    https://llvm.org/docs/GettingStarted.html#software\n*   For this recipe Ninja is used so be sure to have it as well installed\n    https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages\n\n### Checking out the code\n\nCheckout the tutorial including the LLVM dependency (submodules):\n\n```bash\ngit clone --recurse-submodules https://github.com/j2kun/mlir-tutorial.git\ncd mlir-tutorial\n```\n\n### Building dependencies\n\nNote: The following steps are suitable for macOs and use ninja as building\nsystem, they should not be hard to adapt for your environment.\n\n*Build LLVM/MLIR*\n\n```bash\n#!/bin/sh\n\nBUILD_SYSTEM=Ninja\nBUILD_TAG=ninja\nTHIRDPARTY_LLVM_DIR=$PWD/externals/llvm-project\nBUILD_DIR=$THIRDPARTY_LLVM_DIR/build\nINSTALL_DIR=$THIRDPARTY_LLVM_DIR/install\n\nmkdir -p $BUILD_DIR\nmkdir -p $INSTALL_DIR\n\npushd $BUILD_DIR\n\ncmake ../llvm -G $BUILD_SYSTEM \\\n      -DCMAKE_CXX_COMPILER=\"$(xcrun --find clang++)\" \\\n      -DCMAKE_C_COMPILER=\"$(xcrun --find clang)\" \\\n      -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \\\n      -DLLVM_LOCAL_RPATH=$INSTALL_DIR/lib \\\n      -DLLVM_PARALLEL_COMPILE_JOBS=7 \\\n      -DLLVM_PARALLEL_LINK_JOBS=1 \\\n      -DLLVM_BUILD_EXAMPLES=OFF \\\n      -DLLVM_INSTALL_UTILS=ON \\\n      -DCMAKE_OSX_ARCHITECTURES=\"$(uname -m)\" \\\n      -DCMAKE_BUILD_TYPE=Release \\\n      -DLLVM_ENABLE_ASSERTIONS=ON \\\n      -DLLVM_CCACHE_BUILD=ON \\\n      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \\\n      -DLLVM_ENABLE_PROJECTS='mlir' \\\n      -DDEFAULT_SYSROOT=\"$(xcrun --show-sdk-path)\" \\\n      -DCMAKE_OSX_SYSROOT=\"$(xcrun --show-sdk-path)\"\n\ncmake --build . --target check-mlir\n\npopd\n```\n\n### Build and test\n\n```bash\n#!/bin/sh\n\nBUILD_SYSTEM=\"Ninja\"\nBUILD_DIR=./build-`echo ${BUILD_SYSTEM}| tr '[:upper:]' '[:lower:]'`\n\nrm -rf $BUILD_DIR\nmkdir $BUILD_DIR\npushd $BUILD_DIR\n\nLLVM_BUILD_DIR=externals/llvm-project/build\ncmake -G $BUILD_SYSTEM .. \\\n    -DLLVM_DIR=\"$LLVM_BUILD_DIR/lib/cmake/llvm\" \\\n    -DMLIR_DIR=\"$LLVM_BUILD_DIR/lib/cmake/mlir\" \\\n    -DBUILD_DEPS=\"ON\" \\\n    -DBUILD_SHARED_LIBS=\"OFF\" \\\n    -DCMAKE_BUILD_TYPE=Debug\n\npopd\n\ncmake --build $BUILD_DIR --target MLIRAffineFullUnrollPasses\ncmake --build $BUILD_DIR --target MLIRMulToAddPasses\ncmake --build $BUILD_DIR --target MLIRNoisyPasses\ncmake --build $BUILD_DIR --target mlir-headers\ncmake --build $BUILD_DIR --target mlir-doc\ncmake --build $BUILD_DIR --target tutorial-opt\ncmake --build $BUILD_DIR --target check-mlir-tutorial\n```\n","funding_links":[],"categories":["Starchart","C++","Uncategorized","Summary","Learning Resources"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj2kun%2Fmlir-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj2kun%2Fmlir-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj2kun%2Fmlir-tutorial/lists"}