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 vulkan sample image #27

Open
wants to merge 3 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
15 changes: 15 additions & 0 deletions .common-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ stages:
LOWER_CASE_SAMPLE: simplemultigpu
PUSH_SAMPLE_ONLY_TAG: "true"

# Define the sample targets
.sample-vulkan:
variables:
SAMPLE: vulkan
LOWER_CASE_SAMPLE: vulkan
PUSH_SAMPLE_ONLY_TAG: "true"

# Make buildx available as a docker CLI plugin
.buildx-setup:
before_script:
Expand Down Expand Up @@ -184,3 +191,11 @@ release:staging-device-query-ubuntu22.04:
needs:
- image-device-query-ubuntu22.04

release:staging-vulkan:
extends:
- .release:staging
- .dist-ubuntu22.04
- .sample-vulkan
needs:
- image-vulkan-ubuntu22.04

3 changes: 3 additions & 0 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- deviceQuery
- nvbandwidth
- simpleMultiGPU
- vulkan
exclude:
- dist: ubi9
sample: deviceQuery
Expand All @@ -49,6 +50,8 @@ jobs:
sample: nvbandwidth
- dist: ubi9
sample: simpleMultiGPU
- dist: ubi9
sample: vulkan

steps:
- uses: actions/checkout@v4
Expand Down
31 changes: 31 additions & 0 deletions .nvidia-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ image-simple-multi-gpu-ubuntu22.04:
- .dist-ubuntu22.04
- .sample-simple-multi-gpu

image-vulkan-ubuntu22.04:
extends:
- .image-pull
- .dist-ubuntu22.04
- .sample-vulkan

# The .scan step forms the base of the image scan operation performed before releasing
# images.
.scan:
Expand Down Expand Up @@ -223,6 +229,25 @@ scan-simple-multi-gpu-ubuntu22.04-arm64:
- image-simple-multi-gpu-ubuntu22.04
- scan-simple-multi-gpu-ubuntu22.04-amd64

scan-vulkan-ubuntu22.04-amd64:
extends:
- .scan
- .sample-vulkan
- .dist-ubuntu22.04
- .platform-amd64
needs:
- image-vulkan-ubuntu22.04

scan-vulkan-ubuntu22.04-arm64:
extends:
- .scan
- .sample-vulkan
- .dist-ubuntu22.04
- .platform-arm64
needs:
- image-vulkan-ubuntu22.04
- scan-vulkan-ubuntu22.04-amd64

# Define external release helpers
.release:ngc:
extends:
Expand Down Expand Up @@ -264,3 +289,9 @@ release:ngc-simple-multi-gpu-ubuntu22.04:
- .release:ngc
- .dist-ubuntu22.04
- .sample-simple-multi-gpu

release:ngc-vulkan-ubuntu22.04:
extends:
- .release:ngc
- .dist-ubuntu22.04
- .sample-vulkan
57 changes: 42 additions & 15 deletions deployments/container/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@

BUILD_MULTI_ARCH_IMAGES ?= false
DOCKER ?= docker
BUILDX =
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
BUILDX = buildx
endif
BUILDX =
MKDIR ?= mkdir

include $(CURDIR)/versions.mk

ifeq ($(IMAGE_NAME),)
REGISTRY ?= nvidia
IMAGE_NAME := $(REGISTRY)/cuda-sample
endif

# The Makefile describes the build process for a single CUDA sample: e.g. `vectorAdd`
ifeq ($(SAMPLE),)
# Use vectorAdd as the default sample
Expand All @@ -47,16 +39,34 @@ OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_TAG)
DEFAULT_PUSH_TARGET := ubuntu22.04
DISTRIBUTIONS := ubuntu22.04 ubi9

BUILD_TARGETS := $(patsubst %,build-%, $(DISTRIBUTIONS))
PUSH_TARGETS := $(patsubst %,push-%, $(DISTRIBUTIONS))
TEST_TARGETS := $(patsubst %,test-%, $(DISTRIBUTIONS))
IMAGE_TARGETS := $(patsubst %,image-%,$(DISTRIBUTIONS))
BUILD_TARGETS := $(patsubst %,build-%,$(DISTRIBUTIONS))
PUSH_TARGETS := $(patsubst %,push-%,$(DISTRIBUTIONS))
TEST_TARGETS := $(patsubst %,test-%,$(DISTRIBUTIONS))

.PHONY: $(DISTRIBUTIONS) $(PUSH_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)

# Certain samples do not allow multi-arch images. We disable them here.
# TODO: Does it make more sense to set this at a CI-level?
ifeq ($(SAMPLE),nbody)
AMD64_SAMPLES = vulkan
ARM64_SAMPLES =
SINGLE_ARCH_SAMPLES = nbody $(AMD64_SAMPLES) $(ARM64_SAMPLES)
ifeq ($(SAMPLE),$(filter $(SAMPLE),$(SINGLE_ARCH_SAMPLES)))
$(info Using single-architecture for $(SAMPLE))
BUILD_MULTI_ARCH_IMAGES = false
# Certain samples are only supported on AMD64.
ifeq ($(SAMPLE),$(filter $(SAMPLE),$(AMD64_SAMPLES)))
ARCH = amd64
endif
# Certain samples are only supported on AMD64.
ifeq ($(SAMPLE),$(filter $(SAMPLE),$(ARM64_SAMPLES)))
ARCH = arm64
endif
endif

# If BUILD_MULTI_ARCH_IMAGES is still true for a given set of samples, we enable buildx.
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
BUILDX = buildx
endif

ifneq ($(BUILD_MULTI_ARCH_IMAGES),true)
Expand Down Expand Up @@ -87,7 +97,7 @@ endif

build-%: DIST = $(*)
# For the following samples, we use specific Dockerfiles:
ifeq ($(SAMPLE),$(filter $(SAMPLE),nbody nvbandwidth))
ifeq ($(SAMPLE),$(filter $(SAMPLE),nbody nvbandwidth vulkan))
build-%: DOCKERFILE = $(CURDIR)/deployments/container/$(SAMPLE)/Dockerfile
else
build-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile.$(DOCKERFILE_SUFFIX)
Expand All @@ -98,7 +108,7 @@ build-ubuntu%: DOCKERFILE_SUFFIX = ubuntu
build-ubi9: DOCKERFILE_SUFFIX = ubi9

# Use a generic build target to build the relevant images
$(BUILD_TARGETS): build-%:
$(IMAGE_TARGETS): image-%:
DOCKER_BUILDKIT=1 \
$(DOCKER) $(BUILDX) build --pull \
--provenance=false --sbom=false \
Expand All @@ -109,3 +119,20 @@ $(BUILD_TARGETS): build-%:
--build-arg SAMPLE_NAME=$(SAMPLE) \
-f $(DOCKERFILE) \
$(CURDIR)

# Handle the default build target.
.PHONY: build
build: $(DEFAULT_PUSH_TARGET)
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)

REGCTL ?= regctl
$(PUSH_TARGETS): push-%:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE)

push-short:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
16 changes: 1 addition & 15 deletions deployments/container/multi-arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,4 @@ PUSH_ON_BUILD ?= false
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64

REGCTL ?= regctl
$(PUSH_TARGETS): push-%:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE)

push-short:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE_NAME):${LOWER_CASE_SAMPLE}-$(OUT_IMAGE_VERSION)

push-sample:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE_NAME):$(LOWER_CASE_SAMPLE)
$(BUILD_TARGETS): build-%: image-%
23 changes: 13 additions & 10 deletions deployments/container/native-only.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ PUSH_ON_BUILD ?= false
ARCH ?= $(shell uname -m)
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/$(ARCH)

$(PUSH_TARGETS): push-%:
$(DOCKER) tag "$(IMAGE)" "$(OUT_IMAGE)"
$(DOCKER) push "$(OUT_IMAGE)"
ifeq ($(PUSH_ON_BUILD),true)
$(BUILD_TARGETS): build-%: image-%
$(DOCKER) push "$(IMAGE)"
else
$(BUILD_TARGETS): build-%: image-%
endif

push-short:
$(DOCKER) tag $(IMAGE) $(OUT_IMAGE_NAME):${LOWER_CASE_SAMPLE}-$(OUT_IMAGE_VERSION)
$(DOCKER) push $(OUT_IMAGE_NAME):${LOWER_CASE_SAMPLE}-$(OUT_IMAGE_VERSION)

push-sample:
$(DOCKER) tag $(IMAGE) $(OUT_IMAGE_NAME):$(LOWER_CASE_SAMPLE)
$(DOCKER) push $(OUT_IMAGE_NAME):$(LOWER_CASE_SAMPLE)
# For the default distribution we also retag the image.
# Note: This needs to be updated for multi-arch images.
ifeq ($(IMAGE_TAG),$(VERSION)-$(DIST))
$(DEFAULT_PUSH_TARGET):
$(DOCKER) image inspect $(IMAGE) > /dev/null || $(DOCKER) pull $(IMAGE)
$(DOCKER) tag $(IMAGE) $(subst :$(IMAGE_TAG),:$(VERSION),$(IMAGE))
endif
99 changes: 99 additions & 0 deletions deployments/container/vulkan/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copy link
Contributor

@guptaNswati guptaNswati Mar 18, 2025

Choose a reason for hiding this comment

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

what SPDX is?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a tag to improve machine-readability of the license headers.

See https://spdx.dev/learn/handling-license-info/

# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM nvcr.io/nvidia/cuda:12.8.1-base-ubuntu22.04 AS builder

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y && apt-get install -y --no-install-recommends \
wget \
&& \
rm -rf /var/lib/apt/lists/*

# See instructions from https://vulkan.lunarg.com/doc/sdk/1.4.309.0/linux/getting_started_ubuntu.html
RUN wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | tee /etc/apt/trusted.gpg.d/lunarg.asc \
&& \
wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list http://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list \
&& \
apt update -y \
&& \
apt install -y --no-install-recommends vulkan-sdk \
&& \
rm -rf /var/lib/apt/lists/*

# TODO: Should we include this in the list above.
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
make \
cmake \
pkg-config \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /build

ARG BUILD_EXAMPLES="computeheadless renderheadless"
ENV BUILD_EXAMPLES=$BUILD_EXAMPLES

RUN apt-get update && apt-get install -y --no-install-recommends \
libglm-dev \
&& rm -rf /var/lib/apt/lists/*

# TODO: We should update to the official samples
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why are we not using the official ones in this build?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not want to change how the samples are being built when compared to https://gitlab.com/nvidia/container-images/vulkan/-/blame/master/samples/Dockerfile.ubuntu?ref_type=heads#L35 in this commit.

RUN git clone --depth=1 https://github.com/SaschaWillems/Vulkan.git \
&& cd Vulkan \
sed -e 's|https://|git@|g' .gitmodules \
&& \
git submodule sync \
&& \
git submodule update \
&& mkdir -p build && cd build \
&& cmake -D RESOURCE_INSTALL_DIR=/cuda-samples .. \
&& make ${BUILD_EXAMPLES}

FROM nvcr.io/nvidia/cuda:12.8.1-base-ubuntu22.04

LABEL io.k8s.display-name="NVIDIA CUDA Vulkan samples"
LABEL name="NVIDIA CUDA Vulkan samples"
LABEL vendor="NVIDIA"
LABEL version="N/A"
LABEL release="N/A"
LABEL summary="NVIDIA container to validate GPU support for Vulkan"
LABEL description="See summary"

COPY ./LICENSE ./licenses/LICENSE

RUN mkdir -p /cuda-samples

COPY --from=builder /build/Vulkan/build/bin/computeheadless /cuda-samples/bin/computeheadless
COPY --from=builder /build/Vulkan/build/bin/renderheadless /cuda-samples/bin/renderheadless
COPY --from=builder /build/Vulkan/shaders/glsl/computeheadless/ /cuda-samples/shaders/glsl/computeheadless/
COPY --from=builder /build/Vulkan/shaders/glsl/renderheadless/ /cuda-samples/shaders/glsl/renderheadless/
COPY --from=builder /build/Vulkan/shaders/hlsl/computeheadless/ /cuda-samples/shaders/hlsl/computeheadless/
COPY --from=builder /build/Vulkan/shaders/hlsl/renderheadless/ /cuda-samples/shaders/hlsl/renderheadless/

COPY /deployments/container/vulkan/entrypoint.sh /cuda-samples/entrypoint.sh
RUN ln -s /cuda-samples/entrypoint.sh /cuda-samples/sample

ENV DEBIAN_FRONTEND=noninteractive
COPY --from=builder /etc/apt/sources.list.d/lunarg-vulkan-jammy.list /etc/apt/sources.list.d/lunarg-vulkan-jammy.list
COPY --from=builder /etc/apt/trusted.gpg.d/lunarg.asc /etc/apt/trusted.gpg.d/lunarg.asc

RUN apt update -y && apt install -y --no-install-recommends \
vulkan-sdk \
&& \
rm -rf /var/lib/apt/lists/*

CMD ["/cuda-samples/sample"]
21 changes: 21 additions & 0 deletions deployments/container/vulkan/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

EXAMPLES=/cuda-samples/bin/
for i in $(ls ${EXAMPLES}); do
echo 'y' | ${EXAMPLES}/$i
echo "\n"
done
5 changes: 5 additions & 0 deletions versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ VERSION ?= cuda$(shell grep -Eo "FROM.*cuda:[0-9\.]+" deployments/container/Doc
# Specify the tag for the https://github.com/NVIDIA/cuda-samples repository.
# This need not match the CUDA_VERSION above.
CUDA_SAMPLES_VERSION := v12.0

ifeq ($(IMAGE_NAME),)
REGISTRY ?= nvcr.io/nvidia/k8s
IMAGE_NAME := $(REGISTRY)/cuda-sample
endif