#!/bin/bash # Fetch NVIDIA's official CUDA/PTX documentation into a local directory, for offline use. # # ./fetch_nvidia_docs.sh [dest] [cuda-version] # default: ./nvidia-docs, version auto-detected # # Emits .html and .txt per document. The .txt is the one that matters: it is greppable, # which is the only way a ~700-page reference is usable offline. PDFs are deliberately NOT fetched -- # they cannot be grepped, are read in 20-page slices, and cost ~30 MB for no added capability. # # WHY A FETCHER AND NOT BUNDLED FILES # NVIDIA's documentation is copyrighted and NOT redistributable. The CUDA EULA distributes only the # files listed in its Attachment A -- runtime libraries such as libcudart.so -- and documentation is not # among them. So this repo cannot ship the guides; you download your own copy, direct from NVIDIA, under # their terms. Linking and citing is fine; copying is not. # # OFFLINE USE: task containers have network at IMAGE BUILD time and none at run time. Run this in a # Dockerfile RUN step and the agent has the official docs available offline while it works: # # RUN bash fetch_nvidia_docs.sh /opt/nvidia-docs 12.8.0 # # (c) NVIDIA Corporation. Terms: https://docs.nvidia.com/cuda/eula/ set -uo pipefail DEST=${1:-./nvidia-docs} VER=${2:-} mkdir -p "$DEST" HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) PY=$(command -v python3 || command -v python || true) # Match the docs to the toolkit you compile with. docs.nvidia.com/cuda/ always serves the NEWEST CUDA, # and instructions documented there may not assemble on an older ptxas -- CUDA 12.8 ships PTX ISA 8.7 # while the live page currently documents 9.3. if [ -z "$VER" ] && command -v nvcc >/dev/null 2>&1; then V=$(nvcc --version | grep -oE 'release [0-9]+\.[0-9]+' | head -1 | cut -d' ' -f2) [ -n "$V" ] && VER="$V.0" fi if [ -n "$VER" ] && curl -sSL --fail --max-time 60 -o /dev/null \ "https://docs.nvidia.com/cuda/archive/$VER/cuda-c-programming-guide/index.html" 2>/dev/null; then BASE="https://docs.nvidia.com/cuda/archive/$VER" echo "fetching docs for CUDA $VER (matched to this toolkit)" else [ -n "$VER" ] && echo "no archive for CUDA $VER; falling back to the current docs" BASE="https://docs.nvidia.com/cuda" fi NSIGHT="https://docs.nvidia.com/nsight-compute" # NOTE: the Lovelace guide is published as "ada-tuning-guide" -- there is no lovelace-tuning-guide URL. # NOTE: the CUDA Runtime API reference is deliberately absent. Its index page is only a table of # contents -- the real content is on generated per-module subpages -- and for signatures the installed # headers under $CUDA_HOME/include are both authoritative and already local. Grep those instead. DOCS=" cuda-c-programming-guide|$BASE/cuda-c-programming-guide/index.html cuda-c-best-practices-guide|$BASE/cuda-c-best-practices-guide/index.html parallel-thread-execution|$BASE/parallel-thread-execution/index.html inline-ptx-assembly|$BASE/inline-ptx-assembly/index.html ampere-tuning-guide|$BASE/ampere-tuning-guide/index.html ada-tuning-guide|$BASE/ada-tuning-guide/index.html hopper-tuning-guide|$BASE/hopper-tuning-guide/index.html blackwell-tuning-guide|$BASE/blackwell-tuning-guide/index.html nsight-compute-profiling-guide|$NSIGHT/ProfilingGuide/index.html nsight-compute-cli|$NSIGHT/NsightComputeCli/index.html " ok=0; fail=0 for entry in $DOCS; do name=${entry%%|*} url=${entry#*|} html="$DEST/$name.html" if ! curl -sSL --fail --max-time 120 -o "$html" "$url" 2>/dev/null; then echo " FAIL $name" fail=$((fail + 1)) continue fi if [ -n "$PY" ] && [ -f "$HERE/_html2txt.py" ]; then "$PY" "$HERE/_html2txt.py" "$html" > "$DEST/$name.txt" 2>/dev/null || rm -f "$DEST/$name.txt" fi if [ -f "$DEST/$name.txt" ]; then echo " ok $name ($(du -h "$DEST/$name.txt" | cut -f1) text)" else echo " ok $name (html only -- no python3 for the text rendering)" fi ok=$((ok + 1)) done cat > "$DEST/LICENSE-NOTICE.txt" <<'NOTE' These documents were downloaded from https://docs.nvidia.com and are Copyright (c) NVIDIA Corporation. All rights reserved. They are NOT covered by the license of the repository that shipped this script, and they are NOT redistributable. The CUDA EULA (https://docs.nvidia.com/cuda/eula/) permits distribution only of the files enumerated in its Attachment A -- runtime libraries such as libcudart.so -- and documentation is not among them. You obtained this copy directly from NVIDIA, for your own use, under NVIDIA's terms. Do not re-publish these files. If you need to share them, share the fetch script instead. NOTE echo echo "$ok fetched, $fail failed -> $DEST" echo "search with: KDOCS=$DEST tools/search_docs.sh " echo "Copyright (c) NVIDIA Corporation. Not redistributable; see $DEST/LICENSE-NOTICE.txt"