From 33e3cf751d635ad07fb2ef72b4e9e903b00d58da Mon Sep 17 00:00:00 2001 From: Joel Berkeley <16429957+joelberkeley@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:09:11 +0000 Subject: [PATCH] support Darwin Aarch64/ARM (#427) --- .github/workflows/checks.yml | 150 +++++++++++++++++++++------ .github/workflows/release-c-xla.yml | 22 +++- .github/workflows/release-xla.yml | 32 ++++-- .gitignore | 1 + README.md | 4 +- XLA_VERSION | 2 +- pjrt-plugins/xla-cpu/README.md | 2 +- pjrt-plugins/xla-cpu/build.sh | 22 +++- pjrt-plugins/xla-cpu/postinstall.sh | 24 +++-- pjrt-plugins/xla-cuda/build.sh | 12 ++- pjrt-plugins/xla-cuda/postinstall.sh | 16 +-- spidr/backend/.bazelrc | 3 +- spidr/backend/VERSION | 2 +- spidr/backend/build.sh | 24 ++++- spidr/postinstall.sh | 26 +++-- 15 files changed, 267 insertions(+), 75 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 87496bcec..30cc6c6be 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,7 +14,7 @@ jobs: run: | shopt -s extglob nullglob globstar shellcheck **/*.sh - pjrt-linux: + pjrt-linux-x86_64: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -23,7 +23,7 @@ jobs: - name: Build PJRT + XLA binary run: | if [ ! "$(git diff --exit-code HEAD^ spidr/backend/VERSION)" ]; then - curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/c-xla-v$(cat spidr/backend/VERSION)/libc_xla-linux.so" + curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/c-xla-v$(cat spidr/backend/VERSION)/libc_xla-linux-x86_64.so" else # free up space not used if running in Docker, see # https://github.com/orgs/community/discussions/25678#discussioncomment-5242449 @@ -34,14 +34,35 @@ jobs: sh -c "spidr/backend/build.sh" fi - mv libc_xla-linux.so libc_xla.so + mv libc_xla-linux-x86_64.so libc_xla.so - name: Upload binary uses: actions/upload-artifact@v4 with: - name: libc_xla.so + name: libc_xla-linux-x86_64 path: libc_xla.so if-no-files-found: error - pjrt-plugin-xla-cpu-linux: + pjrt-darwin-aarch64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Build PJRT + XLA binary + run: | + if [ ! "$(git diff --exit-code HEAD^ spidr/backend/VERSION)" ]; then + curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/c-xla-v$(cat spidr/backend/VERSION)/libc_xla-darwin-aarch64.dylib" + else + ./spidr/backend/build.sh + fi + + mv libc_xla-darwin-aarch64.dylib libc_xla.dylib + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: libc_xla-darwin-aarch64 + path: libc_xla.dylib + if-no-files-found: error + pjrt-plugin-xla-cpu-linux-x86_64: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -52,7 +73,7 @@ jobs: if [ ! "$(git diff --exit-code HEAD^ XLA_VERSION)" ]; then . ./dev.sh rev=$(cat XLA_VERSION) - curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision $rev)/pjrt_plugin_xla_cpu-linux.so" + curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision $rev)/pjrt_plugin_xla_cpu-linux-x86_64.so" else rm -rf /opt/hostedtoolcache docker run \ @@ -61,14 +82,37 @@ jobs: sh -c "pjrt-plugins/xla-cpu/build.sh" fi - mv pjrt_plugin_xla_cpu-linux.so pjrt_plugin_xla_cpu.so + mv pjrt_plugin_xla_cpu-linux-x86_64.so pjrt_plugin_xla_cpu.so - name: Upload binary uses: actions/upload-artifact@v4 with: - name: pjrt_plugin_xla_cpu.so + name: pjrt_plugin_xla_cpu-linux-x86_64 path: pjrt_plugin_xla_cpu.so if-no-files-found: error - pjrt-plugin-xla-cuda-linux: + pjrt-plugin-xla-cpu-darwin-aarch64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Build or fetch XLA CPU PJRT plugin + run: | + if [ ! "$(git diff --exit-code HEAD^ XLA_VERSION)" ]; then + . ./dev.sh + rev=$(cat XLA_VERSION) + curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision $rev)/pjrt_plugin_xla_cpu-darwin-aarch64.dylib" + else + ./pjrt-plugins/xla-cpu/build.sh + fi + + mv pjrt_plugin_xla_cpu-darwin-aarch64.dylib pjrt_plugin_xla_cpu.dylib + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: pjrt_plugin_xla_cpu-darwin-aarch64 + path: pjrt_plugin_xla_cpu.dylib + if-no-files-found: error + pjrt-plugin-xla-cuda-linux-x86_64: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -79,7 +123,7 @@ jobs: if [ ! "$(git diff --exit-code HEAD^ XLA_VERSION)" ]; then . ./dev.sh rev=$(cat XLA_VERSION) - curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision $rev)/pjrt_plugin_xla_cuda-linux.so" + curl -LO --fail-with-body "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision $rev)/pjrt_plugin_xla_cuda-linux-x86_64.so" else rm -rf /opt/hostedtoolcache # note this implies specific versions of CUDA and cuDNN @@ -89,59 +133,85 @@ jobs: sh -c "pjrt-plugins/xla-cuda/build.sh" fi - mv pjrt_plugin_xla_cuda-linux.so pjrt_plugin_xla_cuda.so + mv pjrt_plugin_xla_cuda-linux-x86_64.so pjrt_plugin_xla_cuda.so - name: Upload binary uses: actions/upload-artifact@v4 with: - name: pjrt_plugin_xla_cuda.so + name: pjrt_plugin_xla_cuda-linux-x86_64 path: pjrt_plugin_xla_cuda.so if-no-files-found: error - build-tests-xla-cpu: + build-tests-xla-cpu-linux-x86_64: runs-on: ubuntu-latest container: ghcr.io/stefan-hoeck/idris2-pack steps: - uses: actions/checkout@v4 - - name: Build tests - working-directory: test/xla-cpu + - name: Install build dependencies run: | apt-get update && apt-get install -y curl pack switch HEAD + - name: Build tests + working-directory: test/xla-cpu + run: | SPIDR_INSTALL_SUPPORT_LIBS=false pack --no-prompt build xla-cpu.ipkg tar cfz tests-xla-cpu.tar.gz -C build/exec . - name: Upload tests uses: actions/upload-artifact@v4 with: - name: tests-xla-cpu.tar.gz + name: tests-xla-cpu-linux-x86_64 path: test/xla-cpu/tests-xla-cpu.tar.gz if-no-files-found: error - build-tests-xla-cuda: + build-tests-xla-cpu-darwin-aarch64: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Install build dependencies + run: | + brew install chezscheme + git clone https://github.com/stefan-hoeck/idris2-pack.git + (cd idris2-pack && make micropack SCHEME=chez) + ~/.pack/bin/pack switch HEAD + - name: Build tests + working-directory: test/xla-cpu + run: | + SPIDR_INSTALL_SUPPORT_LIBS=false ~/.pack/bin/pack --no-prompt build xla-cpu.ipkg + tar cfz tests-xla-cpu.tar.gz -C build/exec . + - name: Upload tests + uses: actions/upload-artifact@v4 + with: + name: tests-xla-cpu-darwin-aarch64 + path: test/xla-cpu/tests-xla-cpu.tar.gz + if-no-files-found: error + build-tests-xla-cuda-linux-x86_64: runs-on: ubuntu-latest container: ghcr.io/stefan-hoeck/idris2-pack steps: - uses: actions/checkout@v4 - - name: Build tests - working-directory: test/xla-cuda + - name: Install build dependencies run: | apt-get update && apt-get install -y curl pack switch HEAD + - name: Build tests + working-directory: test/xla-cuda + run: | SPIDR_INSTALL_SUPPORT_LIBS=false pack --no-prompt build xla-cuda.ipkg - tar cfz tests-xla-cuda.tar.gz -C build/exec . + tar cfz tests-xla-cuda-linux-x86_64.tar.gz -C build/exec . - name: Upload tests uses: actions/upload-artifact@v4 with: - name: tests-xla-cuda.tar.gz - path: test/xla-cuda/tests-xla-cuda.tar.gz + name: tests-xla-cuda-linux-x86_64 + path: test/xla-cuda/tests-xla-cuda-linux-x86_64.tar.gz if-no-files-found: error - test-xla-cpu-linux: + test-xla-cpu-linux-x86_64: needs: - - pjrt-linux - - pjrt-plugin-xla-cpu-linux - - build-tests-xla-cpu + - pjrt-linux-x86_64 + - pjrt-plugin-xla-cpu-linux-x86_64 + - build-tests-xla-cpu-linux-x86_64 runs-on: ubuntu-latest steps: - name: Download artifacts uses: actions/download-artifact@v4 with: + pattern: "{libc_xla-linux-x86_64,*cpu-linux-x86_64}" merge-multiple: true - name: Install runtime dependencies run: | @@ -150,17 +220,37 @@ jobs: run: | tar xfz tests-xla-cpu.tar.gz . && rm tests-xla-cpu.tar.gz ./test - test-xla-cuda-linux: + test-xla-cpu-darwin-aarch64: + needs: + - pjrt-darwin-aarch64 + - pjrt-plugin-xla-cpu-darwin-aarch64 + - build-tests-xla-cpu-darwin-aarch64 + runs-on: macos-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: "*darwin-aarch64" + merge-multiple: true + - name: Install runtime dependencies + run: | + brew install chezscheme + - name: Run tests + run: | + tar xfz tests-xla-cpu.tar.gz && rm tests-xla-cpu.tar.gz + ./test + test-xla-cuda-linux-x86_64: needs: - - pjrt-linux - - pjrt-plugin-xla-cuda-linux - - build-tests-xla-cuda + - pjrt-linux-x86_64 + - pjrt-plugin-xla-cuda-linux-x86_64 + - build-tests-xla-cuda-linux-x86_64 runs-on: ubuntu-latest # needs a CUDA runner container: nvcr.io/nvidia/tensorrt:23.11-py3 steps: - name: Download artifacts uses: actions/download-artifact@v4 with: + pattern: "{libc_xla-linux-x86_64,*cuda-linux-x86_64}" merge-multiple: true - name: Install runtime dependencies run: | diff --git a/.github/workflows/release-c-xla.yml b/.github/workflows/release-c-xla.yml index 534042398..7da17ee24 100644 --- a/.github/workflows/release-c-xla.yml +++ b/.github/workflows/release-c-xla.yml @@ -23,7 +23,7 @@ jobs: tag_name: c-xla-v${{ env.C_XLA_VERSION }} release_name: C XLA release ${{ env.C_XLA_VERSION }} body: "C XLA release ${{ env.C_XLA_VERSION }}" - c-xla: + c-xla-linux-x86_64: needs: create-release runs-on: ubuntu-latest container: tensorflow/build:latest-python3.9 @@ -37,6 +37,22 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: libc_xla-linux.so - asset_name: libc_xla-linux.so + asset_path: libc_xla-linux-x86_64.so + asset_name: libc_xla-linux-x86_64.so asset_content_type: application/x-sharedlib + c-xla-darwin-aarch64: + needs: create-release + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Build C XLA lib + run: ./spidr/backend/build.sh + - name: Publish C XLA lib + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create-release.outputs.upload_url }} + asset_path: libc_xla-darwin-aarch64.dylib + asset_name: libc_xla-darwin-aarch64.dylib + asset_content_type: application/x-sharedlib diff --git a/.github/workflows/release-xla.yml b/.github/workflows/release-xla.yml index 8299f915d..f0173f2da 100644 --- a/.github/workflows/release-xla.yml +++ b/.github/workflows/release-xla.yml @@ -26,12 +26,12 @@ jobs: tag_name: xla-${{ env.XLA_REV }} release_name: XLA revision ${{ env.XLA_REV }} body: "XLA revision ${{ env.XLA_REV }}" - pjrt-plugin-xla-cpu-linux: + pjrt-plugin-xla-cpu-linux-x86_64: needs: create-release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Build XLA CPU plugin for Linux + - name: Build XLA CPU plugin for Linux x86_64 run: | rm -rf /opt/hostedtoolcache docker run \ @@ -44,15 +44,31 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: pjrt_plugin_xla_cpu-linux.so - asset_name: pjrt_plugin_xla_cpu-linux.so + asset_path: pjrt_plugin_xla_cpu-linux-x86_64.so + asset_name: pjrt_plugin_xla_cpu-linux-x86_64.so asset_content_type: application/x-sharedlib - pjrt-plugin-xla-cuda-linux: + pjrt-plugin-xla-cpu-darwin-aarch64: + needs: create-release + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Build XLA CPU plugin for Darwin AArch64 + run: ./pjrt-plugins/xla-cpu/build.sh + - name: Publish XLA CPU plugin + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create-release.outputs.upload_url }} + asset_path: pjrt_plugin_xla_cpu-darwin-aarch64.dylib + asset_name: pjrt_plugin_xla_cpu-darwin-aarch64.dylib + asset_content_type: application/x-sharedlib + pjrt-plugin-xla-cuda-linux-x86_64: needs: create-release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Build XLA CUDA plugin for Linux + - name: Build XLA CUDA plugin for Linux x86_64 run: | rm -rf /opt/hostedtoolcache docker run \ @@ -65,6 +81,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: pjrt_plugin_xla_cuda-linux.so - asset_name: pjrt_plugin_xla_cuda-linux.so + asset_path: pjrt_plugin_xla_cuda-linux-x86_64.so + asset_name: pjrt_plugin_xla_cuda-linux-x86_64.so asset_content_type: application/x-sharedlib diff --git a/.gitignore b/.gitignore index 518d76822..1b04df42e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ bazel bazel-* bazelisk *.so +*.dylib *.tar.gz diff --git a/README.md b/README.md index 5e23e17c9..bbdbcbd72 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,12 @@ See the [online reference](https://joelberkeley.github.io/spidr/) for API docume ### Install -Installation requires curl and [pack](https://github.com/stefan-hoeck/idris2-pack). To install spidr, install a PJRT plugin. A plugin executes a spidr program, and determines what hardware your program will run on. You can install the CPU plugin with +Installation requires curl and [pack](https://github.com/stefan-hoeck/idris2-pack). To install spidr, install a PJRT plugin. A plugin executes a spidr program, and determines what hardware your program will run on. You can install the CPU plugin, on Linux or Mac with Apple silicon, with ``` pack install pjrt-plugin-xla-cpu ``` or read the [plugin documentation](pjrt-plugins/README.md) for the CUDA-enabled GPU plugin and custom plugin builds. -We have tested spidr on Ubuntu Linux 22.04. It may work on other Linux distributions. If spidr doesn't work on your platform, [get in touch](#contact). - ### Motivation We made spidr to try out modern programming language capabilities in machine learning systems. To this end, we chose [Idris](https://github.com/idris-lang/Idris2) for the API; Idris is a general-purpose purely functional programming language with a particularly expressive type system. We also wanted to build something performant enough for working machine learning practitioners. Implementing efficient low-level linear algebra is not one of the project goals, so we opted to use [OpenXLA](https://openxla.org/)'s PJRT, an abstract interface for machine learning compilers for hardware accelerators. diff --git a/XLA_VERSION b/XLA_VERSION index 66066d25b..2cf52560e 100644 --- a/XLA_VERSION +++ b/XLA_VERSION @@ -1 +1 @@ -43517d94ad963a96a2a308b7b33d77ecd7de4b4a \ No newline at end of file +46bd34518db14456697224b9684f47bf4cdcf6ba \ No newline at end of file diff --git a/pjrt-plugins/xla-cpu/README.md b/pjrt-plugins/xla-cpu/README.md index 9afe8c352..256b24f65 100644 --- a/pjrt-plugins/xla-cpu/README.md +++ b/pjrt-plugins/xla-cpu/README.md @@ -4,7 +4,7 @@ This is the PJRT plugin for CPU. It uses the XLA compiler. ## Install -On Linux, run +On Linux, or MacOS with AArch64 (ARM64, Apple Silicon), run ``` pack install pjrt-plugin-xla-cpu ``` diff --git a/pjrt-plugins/xla-cpu/build.sh b/pjrt-plugins/xla-cpu/build.sh index cc77b4bca..094d8c41d 100755 --- a/pjrt-plugins/xla-cpu/build.sh +++ b/pjrt-plugins/xla-cpu/build.sh @@ -5,11 +5,29 @@ cd "$script_dir/../.." . ./dev.sh rev=$(cat XLA_VERSION) +osu="$(uname)" +case $osu in + 'Linux') + os=linux + arch=x86_64 + ext=so + ;; + 'Darwin') + os=darwin + arch=aarch64 + ext=dylib + ;; + *) + echo "OS $osu not handled" + exit 1 + ;; +esac + xla_dir=$(mktemp -d) install_xla "$rev" "$xla_dir" ( cd "$xla_dir" - ./configure.py --backend=CPU + ./configure.py --backend=CPU --os=$os bazel build //xla/pjrt/c:pjrt_c_api_cpu_plugin.so ) -mv "$xla_dir/bazel-bin/xla/pjrt/c/pjrt_c_api_cpu_plugin.so" pjrt_plugin_xla_cpu-linux.so +mv "$xla_dir/bazel-bin/xla/pjrt/c/pjrt_c_api_cpu_plugin.so" "pjrt_plugin_xla_cpu-$os-$arch.$ext" diff --git a/pjrt-plugins/xla-cpu/postinstall.sh b/pjrt-plugins/xla-cpu/postinstall.sh index c7de35295..e0493b19e 100755 --- a/pjrt-plugins/xla-cpu/postinstall.sh +++ b/pjrt-plugins/xla-cpu/postinstall.sh @@ -8,11 +8,21 @@ cd "$script_dir/../.." rev=$(cat XLA_VERSION) cd - > /dev/null 2>&1 -os=$(uname) -if [ "$os" != "Linux" ]; then - echo "OS ${os} not supported, unable to fetch supporting libraries." - exit 0; -fi; +os="$(uname)" +case $os in + 'Linux') + platform=linux-x86_64 + ext=so + ;; + 'Darwin') + platform=darwin-aarch64 + ext=dylib + ;; + *) + echo "WARNING: OS $os not supported, unable to fetch supporting libraries." + exit 0 + ;; +esac -curl -fsL "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision "$rev")/pjrt_plugin_xla_cpu-linux.so" \ - -o pjrt_plugin_xla_cpu.so --create-dirs --output-dir "$(idris2 --libdir)/pjrt-plugin-xla-cpu-0.0.1/lib" +curl -fsL "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision "$rev")/pjrt_plugin_xla_cpu-$platform.$ext" \ + -o "pjrt_plugin_xla_cpu.${ext}" --create-dirs --output-dir "$(idris2 --libdir)/pjrt-plugin-xla-cpu-0.0.1/lib" diff --git a/pjrt-plugins/xla-cuda/build.sh b/pjrt-plugins/xla-cuda/build.sh index b46974035..16277cc5c 100755 --- a/pjrt-plugins/xla-cuda/build.sh +++ b/pjrt-plugins/xla-cuda/build.sh @@ -5,6 +5,16 @@ cd "$script_dir/../.." . ./dev.sh rev=$(cat XLA_VERSION) +osu="$(uname)" +case $osu in + 'Linux') + ;; + *) + echo "OS $osu not handled" + exit 1 + ;; +esac + xla_dir=$(mktemp -d) install_xla "$rev" "$xla_dir" ( @@ -13,4 +23,4 @@ install_xla "$rev" "$xla_dir" # itself doesn't, see https://github.com/openxla/xla/issues/12017 bazel build --config release_gpu_linux //xla/pjrt/c:pjrt_c_api_gpu_plugin.so ) -mv "$xla_dir/bazel-bin/xla/pjrt/c/pjrt_c_api_gpu_plugin.so" pjrt_plugin_xla_cuda-linux.so +mv "$xla_dir/bazel-bin/xla/pjrt/c/pjrt_c_api_gpu_plugin.so" pjrt_plugin_xla_cuda-linux-x86_64.so diff --git a/pjrt-plugins/xla-cuda/postinstall.sh b/pjrt-plugins/xla-cuda/postinstall.sh index 841ad4d0d..1ae4a2ada 100755 --- a/pjrt-plugins/xla-cuda/postinstall.sh +++ b/pjrt-plugins/xla-cuda/postinstall.sh @@ -8,11 +8,15 @@ cd "$script_dir/../.." rev=$(cat XLA_VERSION) cd - > /dev/null 2>&1 -os=$(uname) -if [ "$os" != "Linux" ]; then - echo "OS ${os} not supported, unable to fetch supporting libraries." - exit 0; -fi; +os="$(uname)" +case $os in + 'Linux') + ;; + *) + echo "WARNING: OS $os not supported, unable to fetch supporting libraries." + exit 0 + ;; +esac -curl -fsL "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision "$rev")/pjrt_plugin_xla_cuda-linux.so" \ +curl -fsL "https://github.com/joelberkeley/spidr/releases/download/xla-$(short_revision "$rev")/pjrt_plugin_xla_cuda-linux-x86_64.so" \ -o pjrt_plugin_xla_cuda.so --create-dirs --output-dir "$(idris2 --libdir)/pjrt-plugin-xla-cuda-0.0.1/lib" diff --git a/spidr/backend/.bazelrc b/spidr/backend/.bazelrc index bcd03ac35..1f4a0970f 100644 --- a/spidr/backend/.bazelrc +++ b/spidr/backend/.bazelrc @@ -1,4 +1,5 @@ -build --action_env=BAZEL_CXXOPTS="-std=c++17" build --nobuild_runfile_links build --nolegacy_external_runfiles build --experimental_repo_remote_exec +build --cxxopt=-std=c++17 +build --host_cxxopt=-std=c++17 diff --git a/spidr/backend/VERSION b/spidr/backend/VERSION index 43b296183..9789c4ccb 100644 --- a/spidr/backend/VERSION +++ b/spidr/backend/VERSION @@ -1 +1 @@ -0.0.13 +0.0.14 diff --git a/spidr/backend/build.sh b/spidr/backend/build.sh index 7eaa43e64..e88541581 100755 --- a/spidr/backend/build.sh +++ b/spidr/backend/build.sh @@ -5,12 +5,30 @@ cd "$script_dir/../.." . ./dev.sh rev="$(cat XLA_VERSION)" -mkdir spidr/backend/xla -install_xla "$rev" spidr/backend/xla +osu="$(uname)" +case $osu in + 'Linux') + os=linux + arch=x86_64 + ext=so + ;; + 'Darwin') + os=darwin + arch=aarch64 + ext=dylib + ;; + *) + echo "OS $osu not handled" + exit 1 + ;; +esac ( cd spidr/backend + mkdir xla + install_xla "$rev" xla + (cd xla; ./configure.py --backend=cpu --os=$os) bazel build //:c_xla rm -rf xla ) -mv spidr/backend/bazel-bin/libc_xla.so libc_xla-linux.so +mv "spidr/backend/bazel-bin/libc_xla.$ext" "libc_xla-$os-$arch.$ext" diff --git a/spidr/postinstall.sh b/spidr/postinstall.sh index cf9e83853..05fd85957 100755 --- a/spidr/postinstall.sh +++ b/spidr/postinstall.sh @@ -5,11 +5,21 @@ if [ "$SPIDR_INSTALL_SUPPORT_LIBS" = false ]; then exit 0; fi script_dir=$(CDPATH="" cd -- "$(dirname -- "$0")" && pwd) xla_ext_version=$(cat "$script_dir/backend/VERSION") -os=$(uname) -if [ "$os" != "Linux" ]; then - echo "OS ${os} not supported, unable to fetch supporting libraries." - exit 0; -fi; - -curl -fsL "https://github.com/joelberkeley/spidr/releases/download/c-xla-v$xla_ext_version/libc_xla-linux.so" \ - -o libc_xla.so --create-dirs --output-dir "$(idris2 --libdir)/spidr-0.0.6/lib" +os="$(uname)" +case $os in + 'Linux') + platform=linux-x86_64 + ext=so + ;; + 'Darwin') + platform=darwin-aarch64 + ext=dylib + ;; + *) + echo "WARNING: OS $os not supported, unable to fetch supporting libraries." + exit 0 + ;; +esac + +curl -fsL "https://github.com/joelberkeley/spidr/releases/download/c-xla-v$xla_ext_version/libc_xla-$platform.$ext" \ + -o "libc_xla.$ext" --create-dirs --output-dir "$(idris2 --libdir)/spidr-0.0.6/lib"