diff --git a/.github/workflows/buildserver.yml b/.github/workflows/buildserver.yml new file mode 100644 index 0000000..60b5ccc --- /dev/null +++ b/.github/workflows/buildserver.yml @@ -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" + 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 }} diff --git a/Dockerfile.client b/Dockerfile.client new file mode 100644 index 0000000..832923b --- /dev/null +++ b/Dockerfile.client @@ -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" ] diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 0000000..9486e92 --- /dev/null +++ b/Dockerfile.server @@ -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"] \ No newline at end of file