|
| 1 | +# Docker Setup |
| 2 | + |
| 3 | +This document describes how to use Docker for FZGPUModules development, testing, and deployment. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The provided Dockerfile creates a single image that supports all three use cases: |
| 8 | +- **Local development**: Full environment for building and developing FZGPUModules |
| 9 | +- **CI/CD testing**: Automated testing and validation in containerized environments |
| 10 | +- **Distribution/deployment**: Packaged environment with the library pre-installed |
| 11 | + |
| 12 | +The image is based on NVIDIA CUDA 12.6.0 with Ubuntu 24.04 and includes: |
| 13 | +- CMake and Ninja build tools |
| 14 | +- C++ compiler (g++) |
| 15 | +- CUDA development libraries |
| 16 | +- Python 3 and pip |
| 17 | +- Sanitizer libraries (libasan8, libubsan1) for debugging |
| 18 | + |
| 19 | +**FZGPUModules is pre-built and installed into the image** during the Docker build. After pulling the image, users can immediately write and compile code against the library — no library build step required. |
| 20 | + |
| 21 | +Installed locations: |
| 22 | +- Headers: `/usr/local/include/fzgmod/` |
| 23 | +- Libraries: `/usr/local/lib/` |
| 24 | +- CMake package config: `/usr/local/lib/cmake/FZGPUModules/` (`find_package` ready) |
| 25 | + |
| 26 | +## Building the Docker Image |
| 27 | + |
| 28 | +```bash |
| 29 | +docker build -t fzgpumodules:latest . |
| 30 | +``` |
| 31 | + |
| 32 | +Or with a specific version tag: |
| 33 | + |
| 34 | +```bash |
| 35 | +docker build -t fzgpumodules:1.0.0 . |
| 36 | +``` |
| 37 | + |
| 38 | +The build takes a few minutes — it compiles FZGPUModules during the image build so subsequent runs are instant. |
| 39 | + |
| 40 | +## Using the Pre-Installed Library |
| 41 | + |
| 42 | +### Quick Start |
| 43 | + |
| 44 | +Mount a directory containing your code and compile directly: |
| 45 | + |
| 46 | +```bash |
| 47 | +docker run --rm --gpus all \ |
| 48 | + -v $(pwd):/workspace \ |
| 49 | + fzgpumodules:latest \ |
| 50 | + nvcc my_app.cu -o my_app -lfzgmod -L/usr/local/lib |
| 51 | +``` |
| 52 | + |
| 53 | +### With CMake (Recommended) |
| 54 | + |
| 55 | +Use `find_package(FZGPUModules REQUIRED)` in your `CMakeLists.txt`: |
| 56 | + |
| 57 | +```cmake |
| 58 | +cmake_minimum_required(VERSION 3.20) |
| 59 | +project(MyApp CUDA CXX) |
| 60 | +
|
| 61 | +find_package(FZGPUModules REQUIRED) |
| 62 | +
|
| 63 | +add_executable(my_app my_app.cu) |
| 64 | +target_link_libraries(my_app PRIVATE FZGMOD::fzgmod) |
| 65 | +``` |
| 66 | + |
| 67 | +Then build inside the container: |
| 68 | + |
| 69 | +```bash |
| 70 | +docker run --rm --gpus all \ |
| 71 | + -v $(pwd):/workspace \ |
| 72 | + fzgpumodules:latest \ |
| 73 | + bash -c "cmake -B build -S . && cmake --build build" |
| 74 | +``` |
| 75 | + |
| 76 | +### Interactive Shell |
| 77 | + |
| 78 | +Start an interactive session to develop incrementally: |
| 79 | + |
| 80 | +```bash |
| 81 | +docker run --rm -it --gpus all \ |
| 82 | + -v $(pwd):/workspace \ |
| 83 | + fzgpumodules:latest |
| 84 | +``` |
| 85 | + |
| 86 | +## Local Development (Building FZGPUModules Itself) |
| 87 | + |
| 88 | +To build and modify FZGPUModules source, mount the repo and build inside the container: |
| 89 | + |
| 90 | +```bash |
| 91 | +docker run --rm -it --gpus all \ |
| 92 | + -v /path/to/FZGPUModules:/workspace/src \ |
| 93 | + fzgpumodules:latest \ |
| 94 | + bash -c "cd /workspace/src && \ |
| 95 | + cmake --preset release -DBUILD_EXAMPLES=ON && \ |
| 96 | + cmake --build build/release -j$(nproc)" |
| 97 | +``` |
| 98 | + |
| 99 | +The pre-installed library in the image is unaffected — your source build stays in the mounted directory. |
| 100 | + |
| 101 | +## CI/CD Testing |
| 102 | + |
| 103 | +### Running the Test Suite |
| 104 | + |
| 105 | +```bash |
| 106 | +docker run --rm --gpus all \ |
| 107 | + -v $(pwd):/workspace/src \ |
| 108 | + fzgpumodules:latest \ |
| 109 | + bash -c "cd /workspace/src && \ |
| 110 | + cmake --preset release -DBUILD_TESTING=ON && \ |
| 111 | + cmake --build build/release -j$(nproc) && \ |
| 112 | + ctest --test-dir build/release --output-on-failure" |
| 113 | +``` |
| 114 | + |
| 115 | +### Full Build with All Targets |
| 116 | + |
| 117 | +```bash |
| 118 | +docker run --rm --gpus all \ |
| 119 | + -v $(pwd):/workspace/src \ |
| 120 | + fzgpumodules:latest \ |
| 121 | + bash -c "cd /workspace/src && \ |
| 122 | + cmake --preset release \ |
| 123 | + -DBUILD_EXAMPLES=ON \ |
| 124 | + -DBUILD_TESTING=ON \ |
| 125 | + -DBUILD_PROFILING=ON && \ |
| 126 | + cmake --build build/release -j$(nproc)" |
| 127 | +``` |
| 128 | + |
| 129 | +## GPU Support |
| 130 | + |
| 131 | +All commands above use `--gpus all` to enable GPU access. This requires: |
| 132 | +- NVIDIA Docker runtime installed on the host |
| 133 | +- NVIDIA driver compatible with CUDA 12.6 |
| 134 | + |
| 135 | +To verify GPU access in the container: |
| 136 | + |
| 137 | +```bash |
| 138 | +docker run --rm --gpus all fzgpumodules:latest nvidia-smi |
| 139 | +``` |
| 140 | + |
| 141 | +On some systems you may need `--runtime=nvidia` instead of `--gpus all`. |
| 142 | + |
| 143 | +## Development Notes |
| 144 | + |
| 145 | +### Sanitizers |
| 146 | + |
| 147 | +The image includes AddressSanitizer (libasan8) and UndefinedBehaviorSanitizer (libubsan1). To build with sanitizers: |
| 148 | + |
| 149 | +```bash |
| 150 | +docker run --rm -it --gpus all \ |
| 151 | + -v $(pwd):/workspace/src \ |
| 152 | + fzgpumodules:latest \ |
| 153 | + bash -c "cd /workspace/src && \ |
| 154 | + cmake --preset release \ |
| 155 | + -DCMAKE_CXX_FLAGS='-fsanitize=address,undefined' && \ |
| 156 | + cmake --build build/release -j$(nproc)" |
| 157 | +``` |
| 158 | + |
| 159 | +### Python Integration |
| 160 | + |
| 161 | +Python 3 and pip are available for profiling scripts or future bindings: |
| 162 | + |
| 163 | +```bash |
| 164 | +docker run --rm -it fzgpumodules:latest python3 --version |
| 165 | +``` |
| 166 | + |
| 167 | +## Troubleshooting |
| 168 | + |
| 169 | +### GPU Not Detected |
| 170 | + |
| 171 | +If `nvidia-smi` fails inside the container: |
| 172 | +- Verify the NVIDIA container toolkit is installed on the host |
| 173 | +- Check that your driver version supports CUDA 12.6 (`nvidia-smi` on the host shows the max supported CUDA version) |
| 174 | +- Try `--runtime=nvidia` if `--gpus all` is not recognized |
| 175 | + |
| 176 | +### find_package Cannot Find FZGPUModules |
| 177 | + |
| 178 | +The CMake package config is at `/usr/local/lib/cmake/FZGPUModules/`. If `find_package` fails, set the path explicitly: |
| 179 | + |
| 180 | +```bash |
| 181 | +cmake -B build -S . -DFZGPUModules_DIR=/usr/local/lib/cmake/FZGPUModules |
| 182 | +``` |
| 183 | + |
| 184 | +### Build Failures in CI |
| 185 | + |
| 186 | +If the image build fails during the `cmake --install` step: |
| 187 | +- Ensure `third_party/tomlplusplus/` is present (it must be vendored, not just a submodule reference) |
| 188 | +- Verify `third_party/googletest/` is initialized if running with `-DBUILD_TESTING=ON` during the image build (it is excluded from the default release build) |
| 189 | + |
| 190 | +## See Also |
| 191 | + |
| 192 | +- [Building FZGPUModules](building.md) — General build instructions |
| 193 | +- [Architecture Guide](architecture.md) — Project structure and design |
0 commit comments