MLIR Bindings for Swift

Related tags

Utility MLIRSwift
Overview

MLIR Bindings for Swift

This project intends to make MLIR APIs accessible from Swift via the MLIR C Bindings.

Usage

The best reference for how to use this package is currently the tests (Module Tests is probably the most interesting).

If you are looking for an example of using MLIRSwift to bind MLIR dialects, check out Edith which uses MLIRSwift to bind dialects from CIRCT.

MLIR

Installation

MLIR is build using the LLVM build infrastructure which uses cmake. This is incompatible with Swift Package Manager, so for now developers will need to install MLIR separately in order for this project to work. Once the MLIR C API settles and Swift Package Manager get better support for binary targets on Linux, we will likely make this dependency available as a precompiled binary.

In the meantime, you can manually install MLIR using the Tools/build-dependencies script. This script requires recent versions of cmake and ninja to be present on your macine. These can be installed on macOS using Homebrew (brew install cmake ninja) or on Ubuntu via apt-get (apt-get install cmake ninja-build). Linux systems might also require the libncurses5-dev and python3 packages.

Troubleshooting

Insufficient permissions to create pkg-config file

One error you may run into is not having sufficient permissions to create LLVM-for-Swift.pc in /usr/local/lib/pkgconfig. This can be solved by making sure that folder exists and granting the correct user read/write permissions to that folder (an aggressive way to accomplish this is sudo chmod -R 777 /usr/local/lib/pkgconfig, which grants all users very open permissions to that folder). The reason this is necessary is that the only cross-platform way to include a precompiled binary in a Swift project is to have that binary installed on the system and accessible via a pkg-config (.pc) file. Tools/build-dependencies works by creating this file for you, and pointing it to the version of CIRCT it built. Unfortunately, Xcode seems to only check certain well known locations for .pc files, the main one being /usr/local/lib/pkgconfig. If we are using SwiftPM from the command line (via a command like swift test) we can modify this behavior using PKG_CONFIG_PATH (the Linux CI uses this approach).

Stale caches when updating pkg-config file

Sometimes, if you change the contents of the pkg-config file (creating it for the first time, or switching between install directories) Xcode will not pick up this change, even after quitting and re-opening. The solution to this is to delete Xcode's "DerivedData" directory, which can be located by going to "Preferences" > "Locations" (an arrow by the path will open that location in Finder). An advanced approach is to store DerivedData "Relative" to the project (I use ".build/DerivedData" as the path). This way, it is easier to delete from the command line.

Updating

We do not include MLIR (llvm) as a submodule, because this would cause Swift Package Manager to pull in all of LLVM in any project depending on MLIRSwift. Instead, we store the hash we care about in Tools/llvm-commit file, update this file to a new commit to update MLIR. Note that this file must be a hash and not a branch like main, since the contents of this file is used to cache the LLVM build on GitHub Actions.

Using an external MLIR checkout

You can point use your own local version of MLIR in a number of ways, the most flexible is simply to install a custom "LLVM-for-Swift.pc" file that points to your locally built version (consult Tools/build-dependencies for an example). A simpler option may be to run Tools/build-dependencies with the environment variable LLVM_REPO set to "local", and LLVM_REPO_PATH set to the path to the repo you want to use. There are a number of other knobs you can turn in Tools/build-dependencies to customize this approach.

You might also like...
Swift-HorizontalPickerView - Customizable horizontal picker view component written in Swift for UIKit/iOS

Horizontal Picker View Customizable horizontal picker view component written in

swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

Sovran-Swift: Small, efficient, easy. State Management for Swift

Sovran-Swift: Small, efficient, easy. State Management for Swift

Approximate is a Swift package that provides implementations of floating point comparisons for the Swift ecosystem

Approximate Approximate floating point equality comparisons for the Swift Programming Language. Introduction Approximate is a Swift package that provi

A Swift app, named 'iPose', for iPhone's pose measurement based on Swift.

iPhone's pose measurement based on Swift. This is a Swift app, named 'iPose', for iPhone's pose measurement based on Swift. This is a side project to

Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway
Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway

Swift Server Implementation - RESTful APIs, AWS Lambda Serverless For Swift Runtime amazonlinux: AWS Lambda + API Gateway deployed on Graviton arm64 build swift:5.6.2-amazonlinux2-docker image

A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

 Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Owner
CIRCT
Circuit IR Compilers and Tools
CIRCT
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Jiwon 0 Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Alessio Nossa 12 Dec 29, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022
Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Gordan Glavaš 7 Nov 24, 2022
Swift-compute-runtime - Swift runtime for Fastly Compute@Edge

swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea

Andrew Barba 57 Dec 24, 2022