Skip to content
Merged
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
Binary file removed .DS_Store
Binary file not shown.
74 changes: 74 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: build

on:
push:
branches: [main, master]
pull_request:

jobs:
# Compile-only matrix: no GPU required, catches build regressions on every PR.
compile:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
cuda: ['11.8.0-devel-ubuntu22.04', '12.6.3-cudnn-devel-ubuntu24.04']
runs-on: ubuntu-latest
container: nvidia/cuda:${{ matrix.cuda }}
name: "PHP ${{ matrix.php }} / CUDA ${{ matrix.cuda }}"
env:
# ubuntu22.04's apt pulls in tzdata, which asks an interactive timezone
# question and hangs the job forever without this.
DEBIAN_FRONTEND: noninteractive
TZ: Etc/UTC
steps:
- uses: actions/checkout@v4

- name: Install PHP ${{ matrix.php }} and build tools
run: |
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo "$TZ" > /etc/timezone
apt-get update
apt-get install -y --no-install-recommends software-properties-common
add-apt-repository -y ppa:ondrej/php
apt-get update
apt-get install -y --no-install-recommends \
php${{ matrix.php }}-cli php${{ matrix.php }}-dev \
build-essential autoconf pkg-config

- name: phpize + configure + build
working-directory: plugin
run: |
phpize
./configure --with-cuda=/usr/local/cuda --with-cudnn=/usr/local/cuda --with-nvrtc=/usr/local/cuda
make -j"$(nproc)"

- name: Extension loads
working-directory: plugin
run: php -d extension="$PWD/modules/cuda.so" -m | grep -i cuda

- name: Headers are self-contained
working-directory: plugin
run: |
set -e
for h in php_cuda.h tensor.h tensor_kernels.cuh cuda_kernels.cuh; do
echo "Checking $h"
echo "#include \"$h\"" > /tmp/hdr_check.c
gcc -fsyntax-only -I. -I/usr/local/cuda/include \
$(php-config --includes) /tmp/hdr_check.c || exit 1
done

# GPU test job: requires a self-hosted runner with an NVIDIA GPU.
gpu-tests:
runs-on: [self-hosted, gpu]
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Build
working-directory: plugin
run: |
phpize
./configure --with-cuda=/usr/local/cuda --with-cudnn=/usr/local/cuda --with-nvrtc=/usr/local/cuda
make -j"$(nproc)"
- name: Run .phpt suite
working-directory: plugin
run: php run-tests.php -q -x -d extension="$PWD/modules/cuda.so" ../tests/
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# phpize / configure / make artifacts
plugin/.libs/
plugin/.deps/
plugin/autom4te.cache/
plugin/build/
plugin/Makefile
plugin/Makefile.fragments
plugin/Makefile.global
plugin/Makefile.objects
plugin/confdefs.h
plugin/conftest.c
plugin/conftest.cu
plugin/config.h
plugin/config.h.in
plugin/config.h.in~
plugin/config.log
plugin/config.nice
plugin/config.status
plugin/configure
plugin/configure.ac
plugin/configure.in
plugin/configure~
plugin/aclocal.m4
plugin/libtool
plugin/modules/
plugin/run-tests.php
plugin/include/
plugin/*.lo
plugin/*.la
plugin/*.o
plugin/*.dep

# OS noise
.DS_Store
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Reference build environment: Ubuntu 24.04 + PHP + CUDA 12.x + cuDNN 9
#
# Build: docker build -t php-cuda .
# Run (GPU required): docker run --gpus all --rm php-cuda php -m
# Tests: docker run --gpus all --rm php-cuda bash -c 'cd /src/plugin && php run-tests.php -q -d extension=$PWD/modules/cuda.so ../tests/'

FROM nvidia/cuda:12.6.3-cudnn-devel-ubuntu24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
php-cli php-dev \
build-essential autoconf pkg-config \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
COPY plugin/ /src/plugin/
COPY tests/ /src/tests/

WORKDIR /src/plugin
RUN phpize \
&& ./configure --with-cuda=/usr/local/cuda --with-cudnn=/usr/local/cuda --with-nvrtc=/usr/local/cuda \
&& make -j"$(nproc)" \
&& make install \
&& echo "extension=cuda.so" > "$(php-config --ini-dir)/cuda.ini"

# Smoke check: the extension must load even without a GPU present at build time.
RUN php -m | grep -i cuda

CMD ["php", "-m"]
Loading
Loading