holoscan-install-source
NVIDIA/skills
使用代码库内基于 Docker 的构建脚本从源代码构建 Holoscan SDK,从而为基于 CMake 的应用程序生成本地安装目录。
...展开全部Holoscan SDK — 从源代码编译
目的
使用nvidia-holoscan/holoscan-sdk源代码树中的./run脚本(该脚本在 Docker 容器内进行构建)构建 Holoscan SDK,生成可作为 CMake 依赖项使用的本地安装目录。
先决条件
- 配备 NVIDIA GPU 及驱动程序(
nvidia-smi)的 Linux 主机。 git、配备 NVIDIA Container Toolkit 的 Docker(docker run --gpus all即可),以及docker-buildx-plugin。- 约 20 GB 可用磁盘空间,用于构建容器及构建/安装目录。
- 首次干净构建需时 10–30 分钟。
限制
- 仅在已发布的软件包(Conda / 容器 / apt / wheel)无法满足需求时才建议使用——例如需要调试符号、自定义 CMake 选项或不受支持的配置。
- 仍需 Docker ——
./run脚本在容器内进行构建;这并非真正的裸机构建。 - 交叉编译为 aarch64 需要在主机上安装
qemu-user-static。
步骤 0:参考官方安装说明
在构建之前,请务必查阅https://docs.nvidia.com/holoscan/sdk-user-guide/sdk_installation.html中的“从源代码构建”部分(以及所选标签对应的 GitHubREADME.md/DEVELOP.md文件)。 提取以下内容:目标架构和 CUDA 主版本所需的./run参数、受支持的分支/标签、该版本中提到的任何 Dockerfile 补丁,以及推荐用于验证的测试名称。如果文档与下文内容不一致,以文档为准。
步骤 1:先决条件
检查是否已安装 git 和 Docker(支持 GPU 直通):
git --version
docker --version
docker run --rm --gpus all ubuntu:22.04 nvidia-smi
- 如果缺少 Docker → 请参考 https://docs.docker.com/engine/install/ 进行安装
- 如果 GPU 直通失败 → 安装 NVIDIA Container Toolkit:
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \ | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \ | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit sudo nvidia-ctk runtime configure --runtime=docker && sudo systemctl restart docker - 如果缺少 Docker buildx:
sudo apt-get install docker-buildx-plugin
步骤 2:克隆代码库
如有需要,将代码库克隆到 ~/holoscan/holoscan-sdk
mkdir -p ~/holoscan/
git clone https://github.com/nvidia-holoscan/holoscan-sdk.git
cd ~/holoscan/holoscan-sdk
要构建特定的发布标签(出于稳定性考虑,建议使用):
git tag | grep -E '^v[0-9]' | sort -V | tail -5 # 列出最近的标签
git checkout v # 例如 v4.1.0
步骤 3:构建
./run 构建脚本可一步完成容器创建、CMake 配置、编译和安装。请提醒用户首次运行需耗时10–30 分钟(下载基础镜像 + 编译)。
./run build
常用选项:
| 参数 | 用途 |
|---|---|
--type debug |
调试构建(包含符号,不进行优化) |
--type RelWithDebInfo |
发布版 + 调试符号 |
--arch aarch64 |
针对 ARM64 的交叉编译(需要运行sudo apt install qemu-user-static) |
--gpu igpu |
针对 Jetson/IGX 的 iGPU 构建 |
--dryrun |
预览命令而不执行 |
如果修改选项后出现 CMake 缓存错误:
./run clear_cache && ./run build
输出文件位于以下文件夹中,可通过./run get_build_dir和./run get_install_dir获取
- 构建目录:
build-cu- / - 安装目录:
install-cu.- /
步骤 4:运行测试
运行以下测试
- EXAMPLE_CPP_HELLO_WORLD_TEST
- EXAMPLE_PYTHON_HELLO_WORLD_TEST
- EXAMPLE_CPP_TENSOR_INTEROP_TEST
- EXAMPLE_PYTHON_TENSOR_INTEROP_TEST
- EXAMPLE_CPP_VIDEO_REPLAYER_TEST
- 示例_Python_视频_回放器_测试
./run test
要一次性运行所有六个必测用例,请使用单引号包裹的正则表达式(必须用引号包裹|符号,以防止 bash 将其视为管道):
./run test --options "-R 'EXAMPLE_CPP_HELLO_WORLD_TEST|EXAMPLE_PYTHON_HELLO_WORLD_TEST|EXAMPLE_CPP_TENSOR_INTEROP_TEST|EXAMPLE_PYTHON_TENSOR_INTEROP_TEST|EXAMPLE_CPP_VIDEO_REPLAYER_TEST|EXAMPLE_PYTHON_VIDEO_REPLAYER_TEST' --output-on-failure"
按名称或正则表达式运行特定测试:
./run test --name
./run test --options "-R '' --output-on-failure"
./run test --verbose
重要提示:当正则表达式字符串中包含|时,请务必使用单引号包裹该字符串——如果不加引号,bash 会将|解释为管道符,导致命令因“命令未找到”而失败。
预期结果:所有测试均通过。在继续执行之前,请记录任何失败情况并向用户报告。
步骤 5:将应用程序指向安装树
构建完成后,应用程序可将安装目录用作 CMake 依赖项。请向用户提供以下路径:
/path/to/holoscan-sdk/install-cu-/
用户在构建自己的应用程序时,可以将Holoscan_ROOT或CMAKE_PREFIX_PATH设置为该目录。
故障排除
| 症状 | 解决方法 |
|---|---|
bash:运行测试时命令未找到 |
正则表达式中包含|— 请用单引号将其括起来:--options "-R ' |
| 更改选项后出现 CMake 缓存错误 | ./run clear_cache && ./run build |
| 未找到 Docker buildx | sudo apt-get install docker-buildx-plugin |
| 构建容器内无法识别 GPU | 验证 NVIDIA Container Toolkit 并重新运行sudo nvidia-ctk runtime configure --runtime=docker |
| 交叉编译失败(aarch64) | 安装 qemu:sudo apt-get install qemu-user-static |
---
name: holoscan-install-source
description: Build the Holoscan SDK from source using its in-tree Docker-based build script, producing a local install tree for CMake-based applications.
license: Apache-2.0
---
# Holoscan SDK — Build from Source
## Purpose
Build the Holoscan SDK from the `nvidia-holoscan/holoscan-sdk` source tree using its `./run` script (which builds inside a Docker container), producing a local install tree consumable as a CMake dependency.
## Prerequisites
- Linux host with NVIDIA GPU + driver (`nvidia-smi`).
- `git`, Docker with NVIDIA Container Toolkit (`docker run --gpus all` works), and `docker-buildx-plugin`.
- ~20 GB free disk for the build container + build/install trees.
- 10–30 min for a clean first build.
## Limitations
- Only recommended when published packages (Conda / container / apt / wheel) don't fit — debug symbols, custom CMake options, or unsupported configs.
- Still requires Docker — the `./run` script builds inside a container; this is not a true bare-metal build.
- Cross-compiling to aarch64 needs `qemu-user-static` on the host.
## Step 0: Consult the Official Install Instructions
Always fetch the "Build from Source" section of `https://docs.nvidia.com/holoscan/sdk-user-guide/sdk_installation.html` (and the linked GitHub `README.md` / `DEVELOP.md` for the chosen tag) before building. Extract: required `./run` flags for the target architecture and CUDA major, supported branches/tags, any Dockerfile patches called out for the release, and the test names recommended for verification. If the doc disagrees with anything below, the doc wins.
## Step 1: Prerequisites
Check that git and Docker (with GPU passthrough) are available:
```bash
git --version
docker --version
docker run --rm --gpus all ubuntu:22.04 nvidia-smi
```
- If Docker is missing → help install from https://docs.docker.com/engine/install/
- If GPU passthrough fails → install NVIDIA Container Toolkit:
```bash
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
| sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \
| sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker && sudo systemctl restart docker
```
- If Docker buildx is missing: `sudo apt-get install docker-buildx-plugin`
## Step 2: Clone the Repository
Clone repo to ~/holoscan/holoscan-sdk if needed
```bash
mkdir -p ~/holoscan/
git clone https://github.com/nvidia-holoscan/holoscan-sdk.git
cd ~/holoscan/holoscan-sdk
```
To build a specific release tag (recommended for stability):
```bash
git tag | grep -E '^v[0-9]' | sort -V | tail -5 # list recent tags
git checkout v<VERSION> # e.g. v4.1.0
```
## Step 3: Build
The `./run build` script handles container creation, CMake configuration, compilation, and install in one step. Warn the user this takes **10–30 minutes** on first run (downloads base image + compiles).
```bash
./run build
```
Common options:
| Flag | Purpose |
|------|---------|
| `--type debug` | Debug build (symbols, no optimization) |
| `--type RelWithDebInfo` | Release + debug symbols |
| `--arch aarch64` | Cross-compile for ARM64 (needs `sudo apt install qemu-user-static`) |
| `--gpu igpu` | iGPU build for Jetson/IGX |
| `--dryrun` | Preview commands without executing |
If CMake cache errors occur after changing options:
```bash
./run clear_cache && ./run build
```
Output lands in these folders, and can be retrieved with `./run get_build_dir` and `./run get_install_dir`
* Build dir: `build-cu<N>-<arch>/`
* Install dir: `install-cu<N>-<arch>/`.
## Step 4: Run Tests
Run the following tests
* EXAMPLE_CPP_HELLO_WORLD_TEST
* EXAMPLE_PYTHON_HELLO_WORLD_TEST
* EXAMPLE_CPP_TENSOR_INTEROP_TEST
* EXAMPLE_PYTHON_TENSOR_INTEROP_TEST
* EXAMPLE_CPP_VIDEO_REPLAYER_TEST
* EXAMPLE_PYTHON_VIDEO_REPLAYER_TEST
```bash
./run test
```
To run all six required tests at once, use a single-quoted regex (the `|` must be quoted to prevent bash from treating it as a pipe):
```bash
./run test --options "-R 'EXAMPLE_CPP_HELLO_WORLD_TEST|EXAMPLE_PYTHON_HELLO_WORLD_TEST|EXAMPLE_CPP_TENSOR_INTEROP_TEST|EXAMPLE_PYTHON_TENSOR_INTEROP_TEST|EXAMPLE_CPP_VIDEO_REPLAYER_TEST|EXAMPLE_PYTHON_VIDEO_REPLAYER_TEST' --output-on-failure"
```
Run a specific test by name or regex:
```bash
./run test --name <test_name>
./run test --options "-R '<regex>' --output-on-failure"
./run test --verbose
```
**Important:** Always single-quote the regex string when it contains `|` — without quotes, bash interprets `|` as a pipe and the command fails with `command not found`.
Expected: all tests pass. Note any failures and report them to the user before continuing.
## Step 5: Point Applications at the Install Tree
Once built, applications can use the install tree as a CMake dependency. Give the user this path:
```
/path/to/holoscan-sdk/install-cu<N>-<arch>/
```
They can set `Holoscan_ROOT` or `CMAKE_PREFIX_PATH` to this directory when building their own applications.
## Troubleshooting
| Symptom | Fix |
|---------|-----|
| `bash: <TEST_NAME>: command not found` when running tests | The regex contains `\|` — wrap it in single quotes: `--options "-R '<regex>'"` |
| CMake cache errors after option change | `./run clear_cache && ./run build` |
| Docker buildx not found | `sudo apt-get install docker-buildx-plugin` |
| GPU not visible inside build container | Verify NVIDIA Container Toolkit and re-run `sudo nvidia-ctk runtime configure --runtime=docker` |
| Cross-compile fails (aarch64) | Install qemu: `sudo apt-get install qemu-user-static` |





首页
