#!/bin/bash # Search the offline NVIDIA docs corpus fetched by fetch_nvidia_docs.sh. # # KDOCS=/opt/nvidia-docs ./search_docs.sh "cp.async.bulk" # find it # KDOCS=/opt/nvidia-docs ./search_docs.sh -C 12 "expect_tx" # with more context # # Searches the .txt renderings (greppable); falls back to the installed CUDA headers for API # signatures, which are more authoritative than any web page and are always present. set -uo pipefail DOCS=${KDOCS:-/opt/nvidia-docs} CTX=4 if [ "${1:-}" = "-C" ]; then CTX=$2; shift 2; fi PAT=${1:-} [ -z "$PAT" ] && { echo "usage: [KDOCS=dir] search_docs.sh [-C n] " >&2; exit 1; } if [ -d "$DOCS" ] && ls "$DOCS"/*.txt >/dev/null 2>&1; then echo "== $DOCS ==" grep -rn --color=never -C "$CTX" -- "$PAT" "$DOCS"/*.txt 2>/dev/null | head -80 else echo "no fetched docs at $DOCS (run fetch_nvidia_docs.sh, or set KDOCS)" >&2 fi # Search EVERY include root, deduped by real path: /usr/local/cuda/include and # /usr/local/cuda/targets//include are different trees, and cuda.h (where the driver API lives) # is only in the latter -- picking just the first one silently finds nothing. INCS=$(for d in /usr/local/cuda*/targets/*/include /usr/local/cuda*/include; do [ -d "$d" ] && readlink -f "$d" done | sort -u) if [ -n "$INCS" ]; then echo echo "== CUDA headers -- authoritative for signatures ==" # shellcheck disable=SC2086 grep -rn --include="*.h" --include="*.hpp" --include="*.cuh" --color=never -- "$PAT" $INCS 2>/dev/null | head -15 fi