1 # Running HAT with Docker on NVIDIA GPUs
2
3 ----
4 * [Contents](hat-00.md)
5 * Build Babylon and HAT
6 * [Quick Install](hat-01-quick-install.md)
7 * [Building Babylon with jtreg](hat-01-02-building-babylon.md)
8 * [Building HAT with jtreg](hat-01-03-building-hat.md)
9 * [Enabling the NVIDIA CUDA Backend](hat-01-05-building-hat-for-cuda.md)
10 * [Testing Framework](hat-02-testing-framework.md)
11 * [Running Examples](hat-03-examples.md)
12 * [HAT Programming Model](hat-03-programming-model.md)
13 * Interface Mapping
14 * [Interface Mapping Overview](hat-04-01-interface-mapping.md)
15 * [Cascade Interface Mapping](hat-04-02-cascade-interface-mapping.md)
16 * Development
17 * [Project Layout](hat-01-01-project-layout.md)
18 * Implementation Details
19 * [Walkthrough Of Accelerator.compute()](hat-accelerator-compute.md)
20 * [How we minimize buffer transfers](hat-minimizing-buffer-transfers.md)
21 * [Running HAT with Docker on NVIDIA GPUs](hat-07-docker-build-nvidia.md)
22 ---
23
24 ## Setting Up Docker Containers for NVIDIA GPUs
25
26 To run Docker on NVIDIA GPUs, you need to install the NVIDIA Container Toolkit first.
27 Follow the instructions [here](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
28
29 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:
30
31 ```bash
32 sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
33 ```
34
35 You will get an output similar to this:
36
37 ```bash
38 +-----------------------------------------------------------------------------------------+
39 | NVIDIA-SMI 590.48.01 Driver Version: 590.48.01 CUDA Version: 13.1 |
40 +-----------------------------------------+------------------------+----------------------+
41 | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
42 | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
43 | | | MIG M. |
44 |=========================================+========================+======================|
45 | 0 NVIDIA GeForce RTX 5060 Off | 00000000:01:00.0 On | N/A |
46 | 0% 46C P8 12W / 145W | 578MiB / 8151MiB | 0% Default |
47 | | | N/A |
48 +-----------------------------------------+------------------------+----------------------+
49
50 +-----------------------------------------------------------------------------------------+
51 | Processes: |
52 | GPU GI CI PID Type Process name GPU Memory |
53 | ID ID Usage |
54 |=========================================================================================|
55 | No running processes found |
56 +-----------------------------------------------------------------------------------------+
57 ```
58
59 ## DockerFile for HAT using NVIDIA SDK
60
61 You can use the following `Dockerfile` for building a new docker container:
62
63 ```dockerfile
64 FROM nvidia/cuda:13.0.1-devel-ubuntu24.04
65
66 RUN apt-get update -q && apt install -qy \
67 build-essential git cmake vim maven curl bash unzip zip wget
68
69 WORKDIR /opt/babylon/
70 RUN wget https://download.java.net/java/early_access/jdk26/22/GPL/openjdk-26-ea+22_linux-x64_bin.tar.gz
71 RUN tar xvzf openjdk-26-ea+22_linux-x64_bin.tar.gz
72 ENV JAVA_HOME=/opt/babylon/jdk-26/
73 ENV PATH=$JAVA_HOME/bin:$PATH
74 RUN java --version
75
76 ## Configure Babylon/HAT from source
77 RUN git clone https://github.com/openjdk/babylon.git
78 WORKDIR /opt/babylon/babylon
79
80 RUN apt-get update -y
81 RUN apt-get install -y autoconf libfreetype6-dev
82 RUN apt-get install -y file
83 RUN apt-get install -y libasound2-dev
84 RUN apt-get install -y libcups2-dev
85 RUN apt-get install -y libfontconfig1-dev
86 RUN apt-get install -y libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev
87
88 RUN bash configure --with-boot-jdk=${JAVA_HOME}
89 RUN make clean
90 RUN make images
91
92 # Configure HAT
93 WORKDIR /opt/babylon/babylon/hat
94 RUN wget https://download.java.net/java/early_access/jextract/22/6/openjdk-22-jextract+6-47_linux-x64_bin.tar.gz
95 RUN tar xvzf openjdk-22-jextract+6-47_linux-x64_bin.tar.gz > /dev/null
96 ENV PATH=/opt/babylon/babylon/hat/jextract-22/bin:$PATH
97 ENV PATH=/opt/babylon/babylon/build/linux-x86_64-server-release/jdk/bin/:$PATH
98 ENV JAVA_HOME=/opt/babylon/babylon/build/linux-x86_64-server-release/jdk
99 RUN /bin/bash -c "source env.bash"
100
101 RUN java @hat/clean
102 RUN java @hat/bld
103
104 ## Expose a volume to pass files in the local directory
105 WORKDIR /opt/babylon/babylon/hat/
106 VOLUME ["/data"]
107 ```
108
109 ## Build Image
110
111 Run the following command in the same directory of the `Dockerfile` with the previous configuration:
112
113 ```bash
114 docker build . -t babylon
115 ```
116
117 ## Running Examples on the NVIDIA GPU
118
119 Check `nvidia-smi` tool from NVIDIA with the new image, so we have connection to the GPU:
120
121 ```bash
122 docker run -it --rm --runtime=nvidia --gpus all babylon nvidia-smi
123 ```
124
125 All setup! Now you can run HAT on NVIDIA GPUs.
126
127 Run matrix-multiply example:
128
129 ```bash
130 docker run -it --rm --runtime=nvidia --gpus all babylon java -cp hat/job.jar hat.java run ffi-cuda matmul --size=1024 --kernel=2DREGISTERTILING_FP16
131 ```
132
133 ## Enable debug info
134
135 ```bash
136 docker run -it --rm --runtime=nvidia --gpus all babylon java -cp hat/job.jar hat.java run ffi-cuda -DHAT=INFO matmul --size=1024 --kernel=2DREGISTERTILING_FP16
137 ```
138
139 Expected output:
140
141 ```bash
142 [INFO] Input Size : 1024x1024
143 [INFO] Check Result: : false
144 [INFO] Num Iterations : 100
145 [INFO] NDRangeConfiguration: 2DREGISTER_TILING_FP16
146
147 [INFO] Using NVIDIA GPU: NVIDIA GeForce RTX 5060
148 [INFO] Dispatching the CUDA kernel
149 \_ BlocksPerGrid = [16,16,1]
150 \_ ThreadsPerBlock = [16,16,1]
151 ```