Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build the libpoplar wrapper in CI #48

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/build_libpoplar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Build libpoplar wrapper

on:
push:
branches: "main"
tags: ["*"]
pull_request:
release:

jobs:
build-libpoplar:
runs-on: ubuntu-latest
container:
image: ${{ matrix.docker_image }}
options: --privileged
strategy:
fail-fast: false
matrix:
include:
- docker_image: graphcore/poplar:3.2.0-ubuntu-20.04-20230314
artifact_name: poplar-3.2.0
- docker_image: graphcore/poplar:3.3.0-ubuntu-20.04-20230703
artifact_name: poplar-3.3.0
steps:
- name: "Install, g++, jq"
# g++ is needed to build the wrapper, jq for
# the `julia-actions/cache` workflow
run: |
apt-get update -y
apt-get install -y g++ jq
env:
DEBIAN_FRONTEND: noninteractive
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: "1.7"
- uses: julia-actions/cache@v1
- name: "Export environment variables"
# Starting from graphcore/poplar:3.3.0 some environment variables like `CPATH` and
# `LD_LIBRARY_PATH`, which we need for building the bindings, are only set with the
# `bash` shell, while GHA uses by default `sh` for steps inside containers. So we
# need to start a step with `shell: bash` and re-export the relevant variables for
# the following steps.
shell: bash
run: |
echo "PATH=${PATH}" >> "${GITHUB_ENV}"
echo "CPATH=${CPATH}" >> "${GITHUB_ENV}"
echo "LIBRARY_PATH=${LIBRARY_PATH}" >> "${GITHUB_ENV}"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> "${GITHUB_ENV}"
echo "POPLAR_SDK_ENABLED=${POPLAR_SDK_ENABLED}" >> "${GITHUB_ENV}"
- name: Instantiate wrapper generation environment
working-directory: ${{ github.workspace }}/deps
run: |
julia --project=. --color=yes -e 'using Pkg; Pkg.instantiate(); Pkg.precompile()'
- name: Generate source code of libpoplar wrapper
working-directory: ${{ github.workspace }}/deps
shell: julia --project=. --color=yes {0}
run: |
include(joinpath(pwd(), "generate_wrapper.jl"))
generate_wrapper()
env:
CXX: g++
- name: Instantiate build environment
working-directory: ${{ github.workspace }}/deps/bb_recipe
run: |
julia --project=. --color=yes -e 'using Pkg; Pkg.instantiate(); Pkg.precompile()'
- name: Compile libpoplar wrapper
working-directory: ${{ github.workspace }}/deps/bb_recipe
run: |
julia --project=. --color=yes build_tarballs.jl --verbose
- uses: actions/upload-artifact@v4
with:
name: products-${{ matrix.artifact_name }}
path: ${{ github.workspace }}/deps/bb_recipe/products
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: "main"
tags: ["*"]
pull_request:
# pull_request:
release:

# Note: ideally we'd have one job for running the tests and another for building
Expand Down
16 changes: 16 additions & 0 deletions deps/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
libcxxwrap_julia_jll = "3eaa8342-bff7-56a5-9981-c04077f7cee7"

[compat]
Clang = "0.14, 0.17.4, 0.18"
JSON = "0.21.4"
Pkg = "1"
Scratch = "1.1"
UUIDs = "1"
libcxxwrap_julia_jll = "0.11"
julia = "1.7"
3 changes: 3 additions & 0 deletions deps/bb_recipe/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
BinaryBuilder = "12aac903-9f7c-5d81-afc2-d9565ea332ae"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
66 changes: 66 additions & 0 deletions deps/bb_recipe/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using BinaryBuilder
using Pkg

name = "libpoplar_wrapper"
version = v"1.0"

# `POPLAR_SDK_ENABLED` should point to where the Poplar SDK is installed,
# otherwise fallback to `/opt/poplar` (default dir in Graphcore Docker
# containers).
poplar_dir = get(ENV, "POPLAR_SDK_ENABLED", "/opt/poplar")

sources = [
# The generated wrappers
DirectorySource("../wrapper"),
DirectorySource(dirname(poplar_dir)),
]

script = "POPLAR_DIR=$(basename(poplar_dir))\n" * raw"""
cd ${WORKSPACE}/srcdir/

mkdir -p "${libdir}"

c++ \
-O0 \
-std=c++17 \
-fPIC \
-shared \
-I${POPLAR_DIR}/include \
-I${includedir} \
-I${includedir}/julia \
-I. \
-o "${libdir}/libpoplar_julia.${dlext}" \
template.cpp \
-L${POPLAR_DIR}/lib \
-L${libdir} \
-lpopops \
-lpoplar \
-lcxxwrap_julia \
-ljulia

install_license /usr/share/licenses/MIT
"""

julia_versions = if VersionNumber(ENV["SDK_VERSION"]) < v"3.3"
["1.9.0", "1.10.0"]
else
["1.11.0"]
end

base_platforms = [
Platform("x86_64", "linux"; libc="glibc", cxxstring_abi="cxx11")
]

platforms = vcat([(p = deepcopy(platform); p["julia_version"] = julia_version; p) for platform in base_platforms, julia_version in julia_versions]...)

products = [
LibraryProduct("libpoplar_julia", :libpoplar_julia; dont_dlopen=true),
]

dependencies = [
BuildDependency(PackageSpec(;name="libjulia_jll", version=v"1.10.9")),
Dependency("libcxxwrap_julia_jll"; compat = "~0.11.2"),
]

build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
julia_compat="1.9", preferred_gcc_version=v"10", dont_dlopen=true)
Loading