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

Add build files #41

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
83 changes: 83 additions & 0 deletions .github/workflows/buildserver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: publish a docker image

on:
push:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- cuda_version: "12.6.2"
ubuntu_version: "24.04"
dockerfile: "Dockerfile.client"
image_suffix: "-client"
- cuda_version: "12.6.2"
ubuntu_version: "24.04"
dockerfile: "Dockerfile.server"
image_suffix: "-server"
- cuda_version: "12.5.1"
ubuntu_version: "22.04"
kevmo314 marked this conversation as resolved.
Show resolved Hide resolved
dockerfile: "Dockerfile.client"
image_suffix: "-client"
- cuda_version: "12.5.1"
ubuntu_version: "22.04"
dockerfile: "Dockerfile.server"
image_suffix: "-server"
- cuda_version: "12.4.1"
ubuntu_version: "22.04"
dockerfile: "Dockerfile.client"
image_suffix: "-client"
- cuda_version: "12.4.1"
ubuntu_version: "22.04"
dockerfile: "Dockerfile.server"
image_suffix: "-server"

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ matrix.image_suffix }}
tags: |
type=ref,event=branch,suffix=-cuda${{ matrix.cuda_version }}
type=ref,event=pr,suffix=-cuda${{ matrix.cuda_version }}
type=semver,pattern={{version}},suffix=-cuda${{ matrix.cuda_version }}
type=semver,pattern={{major}}.{{minor}},suffix=-cuda${{ matrix.cuda_version }}
type=sha,suffix=-cuda${{ matrix.cuda_version }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64/v8
context: .
build-args: |
CUDA_VERSION=${{ matrix.cuda_version }}
UBUNTU_VERSION=${{ matrix.ubuntu_version }}
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ${{ matrix.dockerfile }}
20 changes: 20 additions & 0 deletions Dockerfile.client
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG CUDA_VERSION=12.6.2
ARG UBUNTU_VERSION=24.04

FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} AS builder
WORKDIR /build
COPY client.cpp .
COPY codegen codegen
RUN g++ -fPIC -c client.cpp -o client.o -I/usr/local/cuda/include
RUN g++ -fPIC -c codegen/gen_client.cpp -o gen_client.o -I/usr/local/cuda/include
RUN g++ -fPIC -c codegen/manual_client.cpp -o manual_client.o -I/usr/local/cuda/include
RUN g++ -shared -o libscuda.so client.o gen_client.o manual_client.o -L/usr/local/cuda/lib64 -lcudart -lstdc++


FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
ENV SCUDA_SERVER=host.docker.internal
WORKDIR /cuda
COPY --from=builder /build/libscuda.so .
ENV LD_PRELOAD=/cuda/libscuda.so
WORKDIR /
CMD [ "nvidia-smi" ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this client file is not quite as useful for anything outside testing as one would likely want to embed the .so file into one of their Dockerfiles instead of using this container as a base. Could we publish the .so file onto GitHub Releases for the client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my idea was to offer a drop-in replacement for local development, example you got a dev env and instead of using cuda as a base you can just drop in scuda.

I see your point, but i also see no harm in releasing this.

15 changes: 15 additions & 0 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG CUDA_VERSION=12.6.2
ARG UBUNTU_VERSION=24.04

FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} AS builder
WORKDIR /build
COPY server.cu .
COPY codegen codegen
RUN nvcc -o server -lnvidia-ml -lcuda server.cu codegen/gen_server.cpp codegen/manual_server.cpp

FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
ENV SCUDA_PORT=14833
WORKDIR /app
COPY --from=builder /build/server /app/
EXPOSE $SCUDA_PORT
CMD ["/app/server"]