1 # Docker NVIDIA Notes
2 [Back to Index ../](../index.md)
3
4 ## Setting Up Docker Containers for NVIDIA GPUs
5
6 To run Docker on NVIDIA GPUs, you need to install the NVIDIA Container Toolkit first.
7 Follow the instructions [here](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
8
9 Once the NVIDIA Container Toolkit has been installed, you can check access to the GPU by running the following image to run the `nvidia-smi` tool:
10
11 ```bash
12 sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
13 ```
14
15 You will get an output similar to this:
16
17 ```bash
18 +-----------------------------------------------------------------------------------------+
19 | NVIDIA-SMI 610.43.02 KMD Version: 610.43.02 CUDA UMD Version: 13.3 |
20 +-----------------------------------------+------------------------+----------------------+
21 | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
22 | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
23 | | | MIG M. |
24 |=========================================+========================+======================|
25 | 0 NVIDIA GeForce RTX 5060 Off | 00000000:01:00.0 On | N/A |
26 | 0% 48C P8 13W / 145W | 579MiB / 8151MiB | 0% Default |
27 | | | N/A |
28 +-----------------------------------------+------------------------+----------------------+
29
30 +-----------------------------------------------------------------------------------------+
31 | Processes: |
32 | GPU GI CI PID Type Process name GPU Memory |
33 | ID ID Usage |
34 |=========================================================================================|
35 | No running processes found |
36 +-----------------------------------------------------------------------------------------+
37 ```
38
39 ## DockerFile for HAT using NVIDIA SDK
40
41 You can use the following `Dockerfile` for building a new docker container:
42
43 ```dockerfile
44 FROM nvidia/cuda:13.3.1-devel-ubuntu26.04
45
46 RUN apt-get update -q && apt install -qy \
47 build-essential git cmake vim maven curl bash unzip zip wget
48
49 WORKDIR /opt/babylon/
50 RUN wget https://download.java.net/java/early_access/jdk28/13/GPL/openjdk-28-ea+13_linux-x64_bin.tar.gz
51 RUN tar xvzf openjdk-28-ea+13_linux-x64_bin.tar.gz
52 ENV JAVA_HOME=/opt/babylon/jdk-28/
53 ENV PATH=$JAVA_HOME/bin:$PATH
54 RUN java --version
55
56 ## Configure Babylon/HAT from source
57 RUN git clone https://github.com/openjdk/babylon.git
58 WORKDIR /opt/babylon/babylon
59
60 RUN apt-get update -y
61 RUN apt-get install -y autoconf libfreetype6-dev
62 RUN apt-get install -y file
63 RUN apt-get install -y libasound2-dev
64 RUN apt-get install -y libcups2-dev
65 RUN apt-get install -y libfontconfig1-dev
66 RUN apt-get install -y libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev
67
68 RUN bash configure --with-boot-jdk=${JAVA_HOME}
69 RUN make clean
70 RUN make images
71
72 # Configure HAT
73 WORKDIR /opt/babylon/babylon/hat
74 ENV PATH=/opt/babylon/babylon/build/linux-x86_64-server-release/jdk/bin/:$PATH
75 ENV JAVA_HOME=/opt/babylon/babylon/build/linux-x86_64-server-release/jdk
76 RUN /bin/bash -c "source env.bash"
77
78 RUN mvn clean package
79
80 ## Expose volume
81 WORKDIR /opt/babylon/babylon/hat/
82 VOLUME ["/data"]
83 ```
84
85 ## Build Image
86
87 Run the following command in the same directory of the `Dockerfile` with the previous configuration:
88
89 ```bash
90 docker build . -t babylon
91 ```
92
93 ## Running Examples on the NVIDIA GPU
94
95 Check `nvidia-smi` tool from NVIDIA with the new image, so we have connection to the GPU:
96
97 ```bash
98 docker run -it --rm --runtime=nvidia --gpus all babylon nvidia-smi
99 ```
100
101 All setup! Now you can run HAT on NVIDIA GPUs.
102
103 Run matrix-multiply example:
104
105 ```bash
106 docker run -it --rm --runtime=nvidia --gpus all babylon java @.ffi-cuda-example matmul.Main --size=1024 --kernel=2DREGISTERTILING_FP16
107 ```
108
109 ## Enable debug info
110
111 ```bash
112 docker run -it --rm --runtime=nvidia --gpus all babylon java -DHAT=INFO @.ffi-cuda-example matmul.Main --size=1024 --kernel=2DREGISTERTILING_FP16
113
114 Expected output:
115
116 ```bash
117 [INFO] Input Size : 1024x1024
118 [INFO] Check Result: : false
119 [INFO] Num Iterations : 100
120 [INFO] NDRangeConfiguration: 2DREGISTER_TILING_FP16
121
122 [INFO] Using NVIDIA GPU: NVIDIA GeForce RTX 5060
123 [INFO] Dispatching the CUDA kernel
124 \_ BlocksPerGrid = [16,16,1]
125 \_ ThreadsPerBlock = [16,16,1]
126 ```