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 590.48.01 Driver Version: 590.48.01 CUDA Version: 13.1 |
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% 46C P8 12W / 145W | 578MiB / 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.0.1-devel-ubuntu24.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/jdk26/22/GPL/openjdk-26-ea+22_linux-x64_bin.tar.gz
51 RUN tar xvzf openjdk-26-ea+22_linux-x64_bin.tar.gz
52 ENV JAVA_HOME=/opt/babylon/jdk-26/
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 RUN wget https://download.java.net/java/early_access/jextract/22/6/openjdk-22-jextract+6-47_linux-x64_bin.tar.gz
75 RUN tar xvzf openjdk-22-jextract+6-47_linux-x64_bin.tar.gz > /dev/null
76 ENV PATH=/opt/babylon/babylon/hat/jextract-22/bin:$PATH
77 ENV PATH=/opt/babylon/babylon/build/linux-x86_64-server-release/jdk/bin/:$PATH
78 ENV JAVA_HOME=/opt/babylon/babylon/build/linux-x86_64-server-release/jdk
79 RUN /bin/bash -c "source env.bash"
80
81 RUN apt-get install -y maven
82 RUN mvn clean package
83
84 ## Expose a volume to pass files in the local directory
85 WORKDIR /opt/babylon/babylon/hat/
86 VOLUME ["/data"]
87 ```
88
89 ## Build Image
90
91 Run the following command in the same directory of the `Dockerfile` with the previous configuration:
92
93 ```bash
94 docker build . -t babylon
95 ```
96
97 ## Running Examples on the NVIDIA GPU
98
99 Check `nvidia-smi` tool from NVIDIA with the new image, so we have connection to the GPU:
100
101 ```bash
102 docker run -it --rm --runtime=nvidia --gpus all babylon nvidia-smi
103 ```
104
105 All setup! Now you can run HAT on NVIDIA GPUs.
106
107 Run matrix-multiply example:
108
109 ```bash
110 docker run -it --rm --runtime=nvidia --gpus all babylon java @.ffi-cuda-examples matmul --size=1024 --kernel=2DREGISTERTILING_FP16
111 ```
112
113 ## Enable debug info
114
115 ```bash
116 docker run -it --rm --runtime=nvidia --gpus all babylon java @.ffi-cuda-examples matmul -DHAT=INFO matmul --size=1024 --kernel=2DREGISTERTILING_FP16
117 ```
118
119 Expected output:
120
121 ```bash
122 [INFO] Input Size : 1024x1024
123 [INFO] Check Result: : false
124 [INFO] Num Iterations : 100
125 [INFO] NDRangeConfiguration: 2DREGISTER_TILING_FP16
126
127 [INFO] Using NVIDIA GPU: NVIDIA GeForce RTX 5060
128 [INFO] Dispatching the CUDA kernel
129 \_ BlocksPerGrid = [16,16,1]
130 \_ ThreadsPerBlock = [16,16,1]
131 ```