Skip to content

Commit

Permalink
Merge branch 'wip/llvm-15'
Browse files Browse the repository at this point in the history
Builds and tests successfully using LLVM-15 on x86-64, aarch64, and nvptx64
  • Loading branch information
tmcdonell committed Aug 22, 2023
2 parents efa58dc + 2348390 commit 54c3554
Show file tree
Hide file tree
Showing 46 changed files with 654 additions and 381 deletions.
4 changes: 0 additions & 4 deletions .ghci

This file was deleted.

273 changes: 273 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
name: CI

# Trigger the workflow on push or pull request
on:
# workflow_dispatch:
pull_request:
# branches: [master]
types: [synchronize, opened, reopened]
push:
# branches: [main]
paths:
- '.github/workflows/ci.yml'
- 'cabal.project'
- 'stack.yaml'
- '*/src/**'
- '*/test/**'
- '*/cbits/**'
schedule:
# additionally run once per week (At 00:00 on Sunday) to maintain cache
- cron: '0 0 * * 0'

jobs:
cabal:
name: cabal | ${{ matrix.sys.os }}-${{ matrix.arch }} ghc-${{ matrix.ghc }} ${{ matrix.mode }}
runs-on: ${{ matrix.sys.os }}
strategy:
fail-fast: false
matrix:
sys:
- { os: 'ubuntu-latest', shell: 'bash' }
- { os: 'macOS-latest', shell: 'bash' }
- { os: 'windows-latest', shell: 'msys2 {0}' }
arch:
- 'x64'
- 'ARM64'
ghc:
- 'latest'
- '9.6'
- '9.4'
- '9.2'
mode:
- 'debug'
- 'release'
exclude:
- sys:
- os: 'windows-latest'
mode: 'debug'
- arch: 'ARM64'
defaults:
run:
shell: ${{ matrix.sys.shell }}

steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: actions/cache
path: .github/actions/cache-always
ref: v3

# Tweak `action.yml` of `actions/cache@v3` to remove the `post-if`
# condition, making it default to `post-if: always ()`.
- name: Run actions/cache-always@v3
run: |
sed -i'~' -e '/ post-if: /d' .github/actions/cache-always/action.yml
shell: bash

- uses: msys2/setup-msys2@v2
if: matrix.sys.os == 'windows-latest'
with:
path-type: inherit
msystem: clang64

- uses: haskell/actions/setup@v2
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: latest

- name: Set up environment (ubuntu)
if: matrix.sys.os == 'ubuntu-latest'
run: |
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install llvm-15-dev libpolly-15-dev cuda-11-8
echo "LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:/usr/local/cuda-11.8/nvvm/lib64:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
echo "/usr/local/cuda-11.8/bin" >> $GITHUB_PATH
echo "package accelerate" >> cabal.project
if [ ${{ matrix.mode }} == 'release' ]; then
echo " flags: +nofib" >> cabal.project
else
echo " flags: +nofib +debug" >> cabal.project
echo " ghc-options: -optc=-DTRACY_TIMER_FALLBACK -optcxx=-DTRACY_TIMER_FALLBACK" >> cabal.project
sudo apt-get -y install pkg-config libcapstone-dev libfreetype-dev libglfw3-dev libgtk-3-dev libtbb-dev
fi
- name: Set up environment (macOS)
if: matrix.sys.os == 'macOS-latest'
run: |
brew install llvm@15
mkdir -p $HOME/.local/bin
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/llvm-config-15
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/
echo "$HOME/.local/bin" >> $GITHUB_PATH
echo "package accelerate" >> cabal.project
if [ ${{ matrix.mode }} == 'release' ]; then
echo " flags: +nofib" >> cabal.project
else
echo " flags: +nofib +debug" >> cabal.project
echo " ghc-options: -optc=-DTRACY_TIMER_FALLBACK -optcxx=-DTRACY_TIMER_FALLBACK" >> cabal.project
brew install pkg-config capstone freetype glfw
fi
- name: Set up environment (windows)
if: matrix.sys.os == 'windows-latest'
run: |
# https://stackoverflow.com/questions/33969803/how-to-obtain-older-versions-of-packages-using-msys2
# https://packages.msys2.org/package/mingw-w64-clang-x86_64-llvm
curl -LO https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst
choco install cuda --version=11.8.0.52206
echo "package accelerate" >> cabal.project
echo " flags: +nofib" >> cabal.project
- name: Configure
run: cabal configure --enable-tests --test-show-details=direct --test-option="--num-threads=1"

- name: Freeze
run: |
cabal freeze
sed -i'~' -e '/^index-state:/d' cabal.project.freeze
- name: Run actions/cache-always@v3
uses: ./.github/actions/cache-always
with:
path: |
${{ steps.setup-haskell.outputs.cabal-store }}
dist-newstyle
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}
restore-keys: |
${{ runner.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}
${{ runner.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-cabal-
- name: Build accelerate-llvm
run: cabal build accelerate-llvm

- name: Build accelerate-llvm-native
run: cabal build accelerate-llvm-native

- name: Build accelerate-llvm-ptx
run: cabal build accelerate-llvm-ptx
if: matrix.sys.os != 'macOS-latest'

- name: Test accelerate-llvm-native
run: cabal test accelerate-llvm-native

# Behaviour of cabal haddock has changed: https://github.com/haskell/cabal/issues/8725
- name: Haddock accelerate-llvm
run: cabal haddock accelerate-llvm --disable-documentation

- name: Haddock accelerate-llvm-native
run: cabal haddock accelerate-llvm-native --disable-documentation

- name: Haddock accelerate-llvm-ptx
run: cabal haddock accelerate-llvm-ptx --disable-documentation
if: matrix.sys.os != 'macOS-latest'

stack:
name: stack | ${{ matrix.sys.os }}-${{ matrix.arch }}
runs-on: ${{ matrix.sys.os }}
strategy:
fail-fast: false
matrix:
sys:
- { os: 'ubuntu-latest', shell: 'bash' }
- { os: 'macOS-latest', shell: 'bash' }
- { os: 'windows-latest', shell: 'msys2 {0}' }
arch:
- 'x64'
- 'ARM64'
exclude:
- arch: 'ARM64'
defaults:
run:
shell: ${{ matrix.sys.shell }}

steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: actions/cache
path: .github/actions/cache-always
ref: v3

# Tweak `action.yml` of `actions/cache@v3` to remove the `post-if`
# condition, making it default to `post-if: always ()`.
- name: Run actions/cache-always@v3
run: |
sed -i'~' -e '/ post-if: /d' .github/actions/cache-always/action.yml
shell: bash

- uses: msys2/setup-msys2@v2
if: matrix.sys.os == 'windows-latest'
with:
path-type: inherit
msystem: clang64

- uses: haskell/actions/setup@v2
id: setup-haskell
with:
enable-stack: true
stack-no-global: true

- name: actions/cache-always@v3
uses: ./.github/actions/cache-always
with:
path: |
${{ steps.setup-haskell.outputs.stack-root }}
.stack-work
key: ${{ runner.os }}-${{ matrix.arch }}-stack-${{ hashFiles('stack.yaml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.arch }}-stack-${{ hashFiles('stack.yaml') }}
${{ runner.os }}-${{ matrix.arch }}-stack-
- name: Set up environment (ubuntu)
if: matrix.sys.os == 'ubuntu-latest'
run: |
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install llvm-15-dev libpolly-15-dev cuda-11-8
echo "LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:/usr/local/cuda-11.8/nvvm/lib64:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
echo "/usr/local/cuda-11.8/bin" >> $GITHUB_PATH
- name: Set up environment (macOS)
if: matrix.sys.os == 'macOS-latest'
run: |
brew install llvm@15
mkdir -p $HOME/.local/bin
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/llvm-config-15
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Set up environment (windows)
if: matrix.sys.os == 'windows-latest'
run: |
# https://stackoverflow.com/questions/33969803/how-to-obtain-older-versions-of-packages-using-msys2
# https://packages.msys2.org/package/mingw-w64-clang-x86_64-llvm
curl -LO https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst
choco install cuda --version=11.8.0.52206
- name: Setup
run: stack setup

- name: Build accelerate-llvm
run: stack build accelerate-llvm

- name: Build accelerate-llvm-native
run: stack build accelerate-llvm-native

- name: Build accelerate-llvm-ptx
run: stack build accelerate-llvm-ptx
if: matrix.sys.os != 'macOS-latest'

# vi: nospell
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ cabal-dev/
cabal.project.local*
cabal.sandbox.config
.stack-work
stack.yaml
tags
local/
/stack.yaml.lock
.ipynb_checkpoints
/accelerate-llvm-native/accelerate-llvm-native.buildinfo
/cabal.project.freeze
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

# LLVM backends for the Accelerate array language

[![CI-Linux](https://github.com/tmcdonell/accelerate-llvm/workflows/ci-linux/badge.svg)](https://github.com/tmcdonell/accelerate-llvm/actions?query=workflow%3Aci-linux)
[![CI-MacOS](https://github.com/tmcdonell/accelerate-llvm/workflows/ci-macos/badge.svg)](https://github.com/tmcdonell/accelerate-llvm/actions?query=workflow%3Aci-macos)
[![CI](https://github.com/tmcdonell/accelerate-llvm/actions/workflows/ci.yml/badge.svg)](https://github.com/tmcdonell/accelerate-llvm/actions/workflows/ci.yml)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/AccelerateHS/Lobby)
<br>
[![Stackage LTS](https://stackage.org/package/accelerate-llvm/badge/lts)](https://stackage.org/lts/package/accelerate-llvm)
[![Stackage Nightly](https://stackage.org/package/accelerate-llvm/badge/nightly)](https://stackage.org/nightly/package/accelerate-llvm)
[![Hackage](https://img.shields.io/hackage/v/accelerate-llvm.svg)](https://hackage.haskell.org/package/accelerate-llvm)
<br>
[![Docker Automated build](https://img.shields.io/docker/automated/tmcdonell/accelerate-llvm.svg)](https://hub.docker.com/r/tmcdonell/accelerate-llvm/)
[![Docker status](https://images.microbadger.com/badges/image/tmcdonell/accelerate-llvm.svg)](https://microbadger.com/images/tmcdonell/accelerate-llvm)

Expand Down Expand Up @@ -74,7 +69,7 @@ you install (or build) LLVM with the 'nvptx' target.
Example using [Homebrew](http://brew.sh) on macOS:

```sh
$ brew install llvm-hs/llvm/llvm-9
$ brew install llvm@15
```

## Debian/Ubuntu
Expand All @@ -85,17 +80,17 @@ instructions for adding the correct package database for your OS version, and
then:

```sh
$ apt-get install llvm-9-dev
$ apt-get install llvm-15-dev
```

## Building from source

If your OS does not have an appropriate LLVM distribution available, you can also build from source. Detailed build instructions are available on the [LLVM.org website](http://releases.llvm.org/6.0.0/docs/CMake.html). Note that you will require at least [CMake 3.4.3](http://www.cmake.org/cmake/resources/software.html) and a recent C++ compiler; at least Clang 3.1, GCC 4.8, or Visual Studio 2015 (update 3).

1. Download and unpack the [LLVM-9 source code](https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/llvm-9.0.1.src.tar.xz). We'll refer to
1. Download and unpack the [LLVM source code](https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/llvm-15.0.7.src.tar.xz). We'll refer to
the path that the source tree was unpacked to as `LLVM_SRC`. Only the main
LLVM source tree is required, but you can optionally add other components
such as the Clang compiler or Polly loop optimiser. See the [LLVM releases](http://releases.llvm.org/download.html#9.0.1)
such as the Clang compiler or Polly loop optimiser. See the [LLVM releases](https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7)
page for the complete list.

2. Create a temporary build directory and `cd` into it, for example:
Expand Down Expand Up @@ -123,7 +118,7 @@ If your OS does not have an appropriate LLVM distribution available, you can als
to [System Integrity Protection](https://en.wikipedia.org/wiki/System_Integrity_Protection):
```sh
cd $INSTALL_PREFIX/lib
ln -s libLLVM.dylib libLLVM-9.dylib
ln -s libLLVM.dylib libLLVM-15.dylib
install_name_tool -id $PWD/libLTO.dylib libLTO.dylib
install_name_tool -id $PWD/libLLVM.dylib libLLVM.dylib
install_name_tool -change '@rpath/libLLVM.dylib' $PWD/libLLVM.dylib libLTO.dylib
Expand All @@ -138,13 +133,12 @@ Once the dependencies are installed, we are ready to install `accelerate-llvm`.
For example, installation using [`stack`](http://docs.haskellstack.org/en/stable/README.html)
just requires you to point it to the appropriate configuration file:
```sh
$ ln -s stack-8.8.yaml stack.yaml
$ stack setup
$ stack install
```

Note that the version of [`llvm-hs`](https://hackage.haskell.org/package/llvm-hs)
used must match the installed version of LLVM, which is currently 9.0.
used must match the installed version of LLVM, which is currently 15.


## libNVVM
Expand Down
6 changes: 4 additions & 2 deletions accelerate-llvm-native/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import Distribution.Simple.Setup as Setup
import Distribution.Verbosity
import qualified Distribution.InstalledPackageInfo as Installed

#if MIN_VERSION_Cabal(2,2,0)
#if MIN_VERSION_Cabal(3,8,0)
import Distribution.Simple.PackageDescription
#elif MIN_VERSION_Cabal(2,2,0)
import Distribution.PackageDescription.Parsec
#else
import Distribution.PackageDescription.Parse
Expand Down Expand Up @@ -43,7 +45,7 @@ main = defaultMainWithHooks simpleUserHooks
_ -> error "accelerate package was not found or is ambiguous"

dyld_library_name = mkSharedLibName (hostPlatform lbi) (compilerId (compiler lbi)) (installedUnitId accelerate_pkg)
[dyld_install_dir] = case Installed.libraryDynDirs accelerate_pkg of
dyld_install_dir:_ = case Installed.libraryDynDirs accelerate_pkg of
[] -> Installed.libraryDirs accelerate_pkg
ds -> ds

Expand Down
Loading

0 comments on commit 54c3554

Please sign in to comment.