Skip to content
Snippets Groups Projects
Commit 1d7126d5 authored by Ing. Vojtěch Nikl's avatar Ing. Vojtěch Nikl
Browse files

Adding plugin for notebooks to use nvidia cards

parent af797801
No related branches found
No related tags found
No related merge requests found
Showing
with 725 additions and 76 deletions
# notebooks-nvidia-device-plugin # notebooks-nvidia-device-plugin
## What is this repo?
This repo contains custom Nvidia Device Plugin that allows us to deploy Jupyter notebooks from our Kubernetes Jupyterhub onto gpus with active migs (migs simply divide gpus into smaller equal units, allowing multiple users to work concurently on a single gpu with devided resources. The original Nvidia Device Plugin for some unknown reason doesnt allow the master node to see and work with migs on worker nodes.
## How to make the migs work?
## Getting started Activate migs on target GPU, for example using these commands (repeat to create multiple migs)
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
``` ```
cd existing_repo nvidia-smi -mig 1
git remote add origin https://gitlab.cesnet.cz/702/projekty/eosc-notebooks/notebooks-nvidia-device-plugin.git nvidia-smi mig -cci 1g.12gb
git branch -M main nvidia-smi mig -cgi 1g.12gb
git push -uf origin main
``` ```
## Integrate with your tools Other useful arguments to show and delete migs are
```
- [ ] [Set up project integrations](https://gitlab.cesnet.cz/702/projekty/eosc-notebooks/notebooks-nvidia-device-plugin/-/settings/integrations) -lci -lgi -dci -dgi
```
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation When migs are correctly setup, install custom Nvidia Device Plugin onto the master node (where jupyterhub is installed)
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage ```
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. helm install nvidia-device-plugin-custom ./nvidia-device-plugin-custom/ -n kube-system
```
## Support Check that the master node correctly sees the migs
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. ```
kubectl describe node k8s-staging1-gpu-0
```
where this line should contain the number of available migs (should be 1 or more)
```
nvidia.com/mig-1g.11gb: 7
```
## Roadmap Other useful commands to work with the plugin
If you have ideas for releases in the future, it is a good idea to list them in the README. ```
helm uninstall nvidia-device-plugin-custom -n kube-system
kubectl delete pod -n kube-system nvidia-device-plugin-egi-5xwsm
kubectl logs nvidia-device-plugin-egi-87bkb -n kube-system
```
## Contributing ## How to test and benchmark the migs?
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. Folder `test-mig-master` shows how to describe migs in kubernetes yaml file and how to display the migs using nvidia-smi inside kubernetes container.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. Folder `benchmark` constain python code with timed matrix multiplication algorithm to test the performance of the migs and whole gpus. Adjust the N variable representing the size of matrices. We tested with N=16384, one whole nvidia H100 gpu without migs was able to complete the benchmark in exactly 10 seconds, and after diving the gpu into 7 equal migs (the highest amount available, no smaller migs are possible on H100), each mig was able to run the same benchmark in 75s (+-1s) regardless of the total number of migs running the benchmark. That shows that there is very little overhead with using migs and performance of all migs is almost equal the performance of the same mig-less gpu, and also that the performance for each user wont be affected by other users using other migs on the same gpu.
## Authors and acknowledgment Folder `test-mig-jupyterlab` shows how to test the migs inside a docker container within the environment of a single jupyterlab notebook.
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
#!/bin/sh
NAME=test-mig
docker image build --network host -t $NAME .
docker run --rm -it --network host $NAME
FROM nvidia/cuda:12.6.1-devel-ubuntu22.04
# Install Python and required libraries
RUN apt-get update && apt-get install -y python3 python3-pip && \
pip3 install numba numpy && \
apt-get clean
# Copy the Python script into the container
COPY gpu_test_time.py /app/gpu_test.py
# Set the working directory
WORKDIR /app
# the uuid comes from $ nvidia-smi --query-gpu=index,uuid --format=csv
RUN export CUDA_VISIBLE_DEVICES=GPU-bdabf532-16b6-546f-0103-1461eb65e40b
# Command to run the script
CMD ["python3", "gpu_test.py"]
from numba import cuda
import numpy as np
import os
import time
# Check the GPU assigned by CUDA
device = cuda.get_current_device()
print(f"Running on device: {device.name}")
# Define kernel
@cuda.jit
def matrix_mult(A, B, C):
row, col = cuda.grid(2)
if row < C.shape[0] and col < C.shape[1]:
tmp = 0
for k in range(A.shape[1]):
tmp += A[row, k] * B[k, col]
C[row, col] = tmp
# Initialize matrices
N = 4096 # Small matrix size
A = np.random.rand(N, N).astype(np.float32)
B = np.random.rand(N, N).astype(np.float32)
C = np.zeros((N, N), dtype=np.float32)
# Transfer data to GPU
A_device = cuda.to_device(A)
B_device = cuda.to_device(B)
C_device = cuda.device_array((N, N), dtype=np.float32)
# Define thread/block layout
threads_per_block = (16, 16)
blocks_per_grid_x = int(np.ceil(C.shape[0] / threads_per_block[0]))
blocks_per_grid_y = int(np.ceil(C.shape[1] / threads_per_block[1]))
blocks_per_grid = (blocks_per_grid_x, blocks_per_grid_y)
# Measure start time
start_time = time.time()
# Launch the kernel
matrix_mult[blocks_per_grid, threads_per_block](A_device, B_device, C_device)
# Copy result back to host
C = C_device.copy_to_host()
print("Matrix multiplication result:")
print(C)
# Wait for the GPU to finish
cuda.synchronize()
# Measure end time
end_time = time.time()
# Print elapsed time
print(f"Time taken for GPU computation: {end_time - start_time:.6f} seconds")
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
apiVersion: v2
name: nvidia-device-plugin-egi
description: NVIDIA Device Plugin for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.12.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.12.0"
{{/*
Expand the name of the chart.
*/}}
{{- define "nvidia-device-plugin-egi.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "nvidia-device-plugin-egi.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nvidia-device-plugin-egi.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "nvidia-device-plugin-egi.labels" -}}
helm.sh/chart: {{ include "nvidia-device-plugin-egi.chart" . }}
{{ include "nvidia-device-plugin-egi.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "nvidia-device-plugin-egi.selectorLabels" -}}
app.kubernetes.io/name: {{ include "nvidia-device-plugin-egi.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "nvidia-device-plugin-egi.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "nvidia-device-plugin-egi.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nvidia-device-plugin-egi.fullname" . }}
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "nvidia-device-plugin-egi.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "nvidia-device-plugin-egi.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
---
# Source: nvidia-device-plugin/templates/daemonset.yml
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# 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.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nvidia-device-plugin-egi
namespace: kube-system
labels:
helm.sh/chart: nvidia-device-plugin-egi
app.kubernetes.io/name: nvidia-device-plugin-egi
app.kubernetes.io/instance: nvidia-device-plugin-egi
app.kubernetes.io/version: "0.12.0"
app.kubernetes.io/managed-by: Helm
spec:
selector:
matchLabels:
app.kubernetes.io/name: nvidia-device-plugin-egi
app.kubernetes.io/instance: nvidia-device-plugin-egi
updateStrategy:
type: RollingUpdate
template:
metadata:
# This annotation is deprecated. Kept here for backward compatibility
# See https://kubernetes.io/docs/tasks/administer-cluster/guaranteed-scheduling-critical-addon-pods/
# annotations:
# scheduler.alpha.kubernetes.io/critical-pod: ""
labels:
app.kubernetes.io/name: nvidia-device-plugin-egi
app.kubernetes.io/instance: nvidia-device-plugin-egi
spec:
# Mark this pod as a critical add-on; when enabled, the critical add-on
# scheduler reserves resources for critical add-on pods so that they can
# be rescheduled after a failure.
# See https://kubernetes.io/docs/tasks/administer-cluster/guaranteed-scheduling-critical-addon-pods/
priorityClassName: "system-node-critical"
securityContext:
{}
containers:
- image: nvcr.io/nvidia/k8s-device-plugin:v0.12.0
imagePullPolicy: IfNotPresent
name: nvidia-device-plugin-egi-ctr
args:
- "--mig-strategy=mixed"
- "--pass-device-specs=false"
- "--fail-on-init-error=true"
- "--device-list-strategy=envvar"
- "--device-id-strategy=uuid"
- "--nvidia-driver-root=/"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
volumeMounts:
- name: device-plugin
mountPath: /var/lib/kubelet/device-plugins
volumes:
- name: device-plugin
hostPath:
path: /var/lib/kubelet/device-plugins
tolerations:
- key: CriticalAddonsOnly
operator: Exists
- effect: NoSchedule
key: nvidia.com/gpu
operator: Exists
nodeSelector:
gpu: "true"
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "nvidia-device-plugin-egi.fullname" . }}
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "nvidia-device-plugin-egi.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "nvidia-device-plugin-egi.fullname" . }}
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.ingress.className }}
ingressClassName: {{ . }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- with .pathType }}
pathType: {{ . }}
{{- end }}
backend:
service:
name: {{ include "nvidia-device-plugin-egi.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
{{- end }}
{{- end }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "nvidia-device-plugin-egi.fullname" . }}
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "nvidia-device-plugin-egi.selectorLabels" . | nindent 4 }}
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "nvidia-device-plugin-egi.serviceAccountName" . }}
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "nvidia-device-plugin-egi.fullname" . }}-test-connection"
labels:
{{- include "nvidia-device-plugin-egi.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "nvidia-device-plugin-egi.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
# Default values for nvidia-device-plugin-egi.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/
replicaCount: 0
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
image:
repository: nginx
# This sets the pull policy for images.
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: ""
# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: []
# This is to override the chart name.
nameOverride: ""
fullnameOverride: ""
#This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/
serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
# This is for setting Kubernetes Annotations to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
podAnnotations: {}
# This is for setting Kubernetes Labels to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
podLabels: {}
podSecurityContext: {}
# fsGroup: 2000
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/
service:
# This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
type: ClusterIP
# This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports
port: 80
# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/
ingress:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
#This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
autoscaling:
enabled: false
minReplicas: 0
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
# Additional volumes on the output Deployment definition.
volumes: []
# - name: foo
# secret:
# secretName: mysecret
# optional: false
# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true
nodeSelector: {}
tolerations: []
affinity: {}
#!/bin/sh
# Check if MIG ID is provided
if [ -z "$1" ]; then
echo "Usage: $0 <MIG_UUID>"
exit 1
fi
MIG_UUID="$1"
NAME=jupyterlab-test-mig
docker image build --network host -t $NAME .
docker run --rm -it --network host \
--gpus "\"device=$MIG_UUID\"" \
-e NVIDIA_VISIBLE_DEVICES="$MIG_UUID" \
$NAME
FROM nvidia/cuda:12.6.1-devel-ubuntu22.04
# Install Python and dependencies
RUN apt-get update && apt-get install -y \
python3-pip python3-dev curl && \
pip3 install --no-cache-dir \
jupyterlab numba numpy && \
apt-get clean
# Set environment variables for CUDA
ENV PATH=/usr/local/cuda/bin:$PATH
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
EXPOSE 80
# Copy the Python script into the container
COPY gpu_test_time.py /app/gpu_test.py
# Set the working directory
WORKDIR /app
# the uuid comes from $ nvidia-smi --query-gpu=index,uuid --format=csv
#RUN export CUDA_VISIBLE_DEVICES=GPU-bdabf532-16b6-546f-0103-1461eb65e40b
# Set default command to start JupyterLab
CMD ["jupyter-lab", "--ip=0.0.0.0", "--allow-root", "--port=80"]
from numba import cuda
import numpy as np
import os
import time
# Check the GPU assigned by CUDA
device = cuda.get_current_device()
print(f"Running on device: {device.name}")
# Define kernel
@cuda.jit
def matrix_mult(A, B, C):
row, col = cuda.grid(2)
if row < C.shape[0] and col < C.shape[1]:
tmp = 0
for k in range(A.shape[1]):
tmp += A[row, k] * B[k, col]
C[row, col] = tmp
# Initialize matrices
N = 4096 # Small matrix size
A = np.random.rand(N, N).astype(np.float32)
B = np.random.rand(N, N).astype(np.float32)
C = np.zeros((N, N), dtype=np.float32)
# Transfer data to GPU
A_device = cuda.to_device(A)
B_device = cuda.to_device(B)
C_device = cuda.device_array((N, N), dtype=np.float32)
# Define thread/block layout
threads_per_block = (16, 16)
blocks_per_grid_x = int(np.ceil(C.shape[0] / threads_per_block[0]))
blocks_per_grid_y = int(np.ceil(C.shape[1] / threads_per_block[1]))
blocks_per_grid = (blocks_per_grid_x, blocks_per_grid_y)
# Measure start time
start_time = time.time()
# Launch the kernel
matrix_mult[blocks_per_grid, threads_per_block](A_device, B_device, C_device)
# Copy result back to host
C = C_device.copy_to_host()
print("Matrix multiplication result:")
print(C)
# Wait for the GPU to finish
cuda.synchronize()
# Measure end time
end_time = time.time()
# Print elapsed time
print(f"Time taken for GPU computation: {end_time - start_time:.6f} seconds")
FROM nvidia/cuda:12.6.1-base-ubuntu22.04
# Install Python and required libraries
RUN apt-get update && apt-get install -y python3 python3-pip && \
pip3 install numba numpy && \
apt-get clean
# Copy the Python script into the container
COPY gpu_test.py /app/gpu_test.py
# Set the working directory
WORKDIR /app
# Command to run the script
CMD ["python3", "gpu_test.py"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment