-
Notifications
You must be signed in to change notification settings - Fork 4
Refine NVSHMEM path and codgen, build_nvshmem.sh and docs. #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a6d317f
62b4d43
28e63d7
3d48955
7a3969b
eafb16c
4abfdfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,103 +1,75 @@ | ||
| #!/bin/bash | ||
| # Build NVSHMEM from source for TileLang device-side use. Run from repo root or set NVSHMEM_SRC. | ||
| # Usage: source build_nvshmem.sh [--arch 90] [--jobs N] [--force-download] | ||
| # Override at runtime: NVSHMEM_SRC, NVSHMEM_* (see below), CMAKE, NVSHMEM_VERSION. | ||
|
|
||
| if [ -z "${NVSHMEM_SRC}" ]; then | ||
| export NVSHMEM_SRC="$(realpath ../../3rdparty/nvshmem_src)" | ||
| echo "NVSHMEM_SRC not set, defaulting to ${NVSHMEM_SRC}" | ||
| else | ||
| NVSHMEM_SRC="$(realpath ${NVSHMEM_SRC})" | ||
| echo "Using NVSHMEM_SRC=${NVSHMEM_SRC}" | ||
| fi | ||
|
|
||
| if [ -d "${NVSHMEM_SRC}" ]; then | ||
| if [ "$(ls -A ${NVSHMEM_SRC})" ]; then | ||
| echo "NVSHMEM_SRC directory (${NVSHMEM_SRC}) is not empty, cleaning it..." | ||
| rm -rf "${NVSHMEM_SRC}/"* | ||
| rm -rf "${NVSHMEM_SRC}/".* 2>/dev/null || true | ||
| fi | ||
| else | ||
| mkdir -p "${NVSHMEM_SRC}" | ||
| fi | ||
|
|
||
| wget https://developer.nvidia.com/downloads/assets/secure/nvshmem/nvshmem_src_3.2.5-1.txz | ||
| tar zxvf nvshmem_src_3.2.5-1.txz | ||
| rm -rf nvshmem_src_3.2.5-1.txz | ||
|
|
||
| mkdir -p "${NVSHMEM_SRC}" | ||
| mv nvshmem_src/* "${NVSHMEM_SRC}/" | ||
| mv nvshmem_src/.* "${NVSHMEM_SRC}/" 2>/dev/null || true | ||
| rmdir nvshmem_src | ||
|
|
||
|
|
||
| export NVSHMEM_PATH="${NVSHMEM_SRC}" | ||
|
|
||
| VER="${NVSHMEM_VERSION:-3.2.5-1}" | ||
| TARBALL="nvshmem_src_${VER}.txz" | ||
| URL="${NVSHMEM_SOURCE_URL:-https://developer.nvidia.com/downloads/assets/secure/nvshmem/${TARBALL}}" | ||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| PROJECT_ROOT=$(realpath "${SCRIPT_DIR}") | ||
| echo "SCRIPT_DIR: ${SCRIPT_DIR}" | ||
| echo "PROJECT_ROOT: ${PROJECT_ROOT}" | ||
| echo "NVSHMEM will be installed to: ${NVSHMEM_SRC}" | ||
|
|
||
| FORCE_DL="" | ||
| ARCH="" | ||
| JOBS="" | ||
|
|
||
| # Iterate over the command-line arguments | ||
| while [[ $# -gt 0 ]]; do | ||
| key="$1" | ||
|
|
||
| case $key in | ||
| --arch) | ||
| # Process the arch argument | ||
| ARCH="$2" | ||
| shift # Skip the argument value | ||
| shift # Skip the argument key | ||
| ;; | ||
| --jobs) | ||
| # Process the jobs argument | ||
| JOBS="$2" | ||
| shift # Skip the argument value | ||
| shift # Skip the argument key | ||
| ;; | ||
| *) | ||
| # Unknown argument | ||
| echo "Unknown argument: $1" | ||
| shift # Skip the argument | ||
| ;; | ||
| esac | ||
| case "$1" in | ||
| -h|--help) echo "Usage: bash build_nvshmem.sh [--arch ARCH] [--jobs N] [--force-download]"; exit 0 ;; | ||
| --arch) ARCH="$2"; shift 2 ;; | ||
| --jobs) JOBS="$2"; shift 2 ;; | ||
| --force-download) FORCE_DL=1; shift ;; | ||
| *) shift ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ -n "${ARCH}" ]]; then | ||
| export CMAKE_CUDA_ARCHITECTURES="${ARCH}" | ||
| CUDAARCH_ARGS="-DCMAKE_CUDA_ARCHITECTURES=${ARCH}" | ||
| fi | ||
|
|
||
| if [[ -z "${JOBS}" ]]; then | ||
| JOBS=$(nproc --ignore 2) | ||
| fi | ||
|
|
||
| export NVSHMEM_IBGDA_SUPPORT=0 | ||
| export NVSHMEM_IBGDA_SUPPORT_GPUMEM_ONLY=0 | ||
| export NVSHMEM_IBDEVX_SUPPORT=0 | ||
| export NVSHMEM_IBRC_SUPPORT=1 | ||
| export NVSHMEM_LIBFABRIC_SUPPORT=0 | ||
| export NVSHMEM_MPI_SUPPORT=1 | ||
| export NVSHMEM_USE_GDRCOPY=0 | ||
| export NVSHMEM_TORCH_SUPPORT=1 | ||
| export NVSHMEM_ENABLE_ALL_DEVICE_INLINING=1 | ||
|
|
||
| pushd "${NVSHMEM_SRC}" | ||
| mkdir -p build | ||
| cd build | ||
| CMAKE=${CMAKE:-cmake} | ||
|
|
||
| if [ ! -f CMakeCache.txt ]; then | ||
| ${CMAKE} .. \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ | ||
| ${CUDAARCH_ARGS} \ | ||
| -DNVSHMEM_BUILD_TESTS=OFF \ | ||
| -DNVSHMEM_BUILD_EXAMPLES=OFF \ | ||
| -DNVSHMEM_BUILD_PACKAGES=OFF | ||
| export NVSHMEM_SRC="$(realpath "${NVSHMEM_SRC:-$SCRIPT_DIR/../../3rdparty/nvshmem_src}")" | ||
| export NVSHMEM_PATH="${NVSHMEM_SRC}" | ||
| JOBS="${JOBS:-$(nproc 2>/dev/null || echo 4)}" | ||
| ARCH="${ARCH:-$CMAKE_CUDA_ARCHITECTURES}" | ||
|
|
||
| if [[ -n "$FORCE_DL" ]] || [[ ! -f "${NVSHMEM_SRC}/CMakeLists.txt" ]]; then | ||
| if [[ -f "${NVSHMEM_SRC}/CMakeLists.txt" ]]; then | ||
| rm -rf "${NVSHMEM_SRC:?}/"* | ||
| rm -rf "${NVSHMEM_SRC}/".* 2>/dev/null || true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On lines 34 and 44, the Safer glob alternatives- rm -rf "${NVSHMEM_SRC}/".* 2>/dev/null || true
+ rm -rf "${NVSHMEM_SRC}"/.[!.]* "${NVSHMEM_SRC}"/..?* 2>/dev/null || true- mv nvshmem_src/.* "${NVSHMEM_SRC}/" 2>/dev/null || true
+ mv nvshmem_src/.[!.]* nvshmem_src/..?* "${NVSHMEM_SRC}/" 2>/dev/null || trueThe pattern Also applies to: 44-44 🤖 Prompt for AI Agents |
||
| else | ||
| mkdir -p "${NVSHMEM_SRC}" | ||
| fi | ||
| cd "${SCRIPT_DIR}" | ||
| [[ -f "${TARBALL}" ]] || { wget -q --show-progress "${URL}" -O "${TARBALL}" || { echo "Download failed (login at developer.nvidia.com?)." >&2; exit 1; }; } | ||
| tar -zxf "${TARBALL}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong tar decompression flag for
Fix- tar -zxf "${TARBALL}"
+ tar xf "${TARBALL}"Using 🤖 Prompt for AI Agents |
||
| rm -f "${TARBALL}" | ||
| [[ -d nvshmem_src ]] || { echo "Missing nvshmem_src after extract." >&2; exit 1; } | ||
| mv nvshmem_src/* "${NVSHMEM_SRC}/" | ||
| mv nvshmem_src/.* "${NVSHMEM_SRC}/" 2>/dev/null || true | ||
| rmdir nvshmem_src | ||
| fi | ||
|
|
||
| make VERBOSE=1 -j"${JOBS}" | ||
| popd | ||
|
|
||
| echo "NVSHMEM installed successfully to ${NVSHMEM_SRC}" | ||
| export NVSHMEM_IBGDA_SUPPORT="${NVSHMEM_IBGDA_SUPPORT:-0}" | ||
| export NVSHMEM_IBGDA_SUPPORT_GPUMEM_ONLY="${NVSHMEM_IBGDA_SUPPORT_GPUMEM_ONLY:-0}" | ||
| export NVSHMEM_IBDEVX_SUPPORT="${NVSHMEM_IBDEVX_SUPPORT:-0}" | ||
| export NVSHMEM_IBRC_SUPPORT="${NVSHMEM_IBRC_SUPPORT:-1}" | ||
| export NVSHMEM_LIBFABRIC_SUPPORT="${NVSHMEM_LIBFABRIC_SUPPORT:-0}" | ||
| export NVSHMEM_MPI_SUPPORT="${NVSHMEM_MPI_SUPPORT:-1}" | ||
| export NVSHMEM_USE_GDRCOPY="${NVSHMEM_USE_GDRCOPY:-0}" | ||
| export NVSHMEM_TORCH_SUPPORT="${NVSHMEM_TORCH_SUPPORT:-1}" | ||
| export NVSHMEM_ENABLE_ALL_DEVICE_INLINING="${NVSHMEM_ENABLE_ALL_DEVICE_INLINING:-1}" | ||
| [[ -z "${ARCH}" ]] || export CMAKE_CUDA_ARCHITECTURES="${ARCH}" | ||
|
|
||
| cd "${NVSHMEM_SRC}" | ||
| mkdir -p build && cd build | ||
| CMAKE="${CMAKE:-cmake}" | ||
| [[ -f CMakeCache.txt ]] || ${CMAKE} .. \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ | ||
| ${ARCH:+-DCMAKE_CUDA_ARCHITECTURES=${ARCH}} \ | ||
| -DNVSHMEM_BUILD_TESTS=OFF \ | ||
| -DNVSHMEM_BUILD_EXAMPLES=OFF \ | ||
| -DNVSHMEM_BUILD_PACKAGES=OFF | ||
|
|
||
| make -j"${JOBS}" VERBOSE=1 | ||
|
|
||
| echo "" | ||
| echo "NVSHMEM built successfully at: ${NVSHMEM_SRC}" | ||
| echo "" | ||
| echo "To use NVSHMEM, add to your environment (e.g. in ~/.bashrc or before running examples):" | ||
| echo " export NVSHMEM_SRC=\"${NVSHMEM_SRC}\"" | ||
| echo " export LD_LIBRARY_PATH=\"${NVSHMEM_SRC}/build/src/lib:\$LD_LIBRARY_PATH\"" | ||
| echo "" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent usage guidance: comment says
source, help saysbash.Line 2 says "Run from repo root or set NVSHMEM_SRC" and line 3 says
source build_nvshmem.sh, but the--helpoutput on line 16 saysbash build_nvshmem.sh. The Installation docs also usebash. Since the script usesexit(notreturn) and changescwd, it should not besourced. Update the header comment to match.🤖 Prompt for AI Agents