Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
05bcd13
build: add sccache support and tune NVCC_THREADS for jit-cache wheel …
dierksen Apr 3, 2026
132b998
build: apply sccache and NVCC_THREADS tuning to AOT build import test
dierksen Apr 7, 2026
ecece08
build: pass sccache credentials to PR test AOT build jobs
dierksen Apr 7, 2026
534e877
build: use public S3 bucket for read-only sccache on PR tests
dierksen Apr 8, 2026
efa16ef
build: use us-west-2 as default sccache region
dierksen Apr 8, 2026
3778dc2
build: use GitHub Actions variables for bucket name and region
dierksen Apr 8, 2026
46b161e
debug: monitor memory usage in AOT build import jobs
dierksen Apr 29, 2026
05ce81b
debug: reduce AOT build concurrency
dierksen Apr 29, 2026
fb6d67a
Merge branch 'main' into jdierksen/sccache-nvcc-threads
dierksen Apr 29, 2026
2169e1a
build: coordinate nvcc threads with sccache jobserver
dierksen Apr 29, 2026
43c310c
ci: address AOT memory monitor review comments
dierksen Apr 30, 2026
8e94245
ci: restore isolated AOT package builds
dierksen Apr 30, 2026
6986b83
Merge AOT memory diagnostics with sccache build tuning
dierksen Apr 30, 2026
9a44887
build: make PR sccache writes effective
dierksen Apr 30, 2026
b8e8fe4
build: address sccache review feedback
dierksen Apr 30, 2026
5c528c7
Merge branch 'main' into jdierksen/sccache-nvcc-threads
dierksen Apr 30, 2026
2f5cdc3
Remove nvcc jobserver flags
dierksen May 1, 2026
296d356
revert nvcc threading; it was significantly slower
dierksen May 4, 2026
99bac02
Merge remote-tracking branch 'gitlab/main' into jdierksen/sccache-nvc…
dierksen May 4, 2026
e4d19b9
Merge remote-tracking branch 'origin/main' into jdierksen/sccache-nvc…
dierksen May 4, 2026
b13a7b5
refactor aot monitor into python instead of bash/awk
dierksen May 5, 2026
68cad93
Merge branch 'main' into jdierksen/sccache-nvcc-threads
dierksen May 6, 2026
770ba9e
address comments
dierksen May 6, 2026
50d5360
address feedback
dierksen May 6, 2026
c6d9d8a
build: extract shared jit-cache helpers to reduce duplication
dierksen May 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ jobs:
-e FLASHINFER_DEV_RELEASE_SUFFIX="${FLASHINFER_DEV_RELEASE_SUFFIX}" \
-e ARCH="${{ matrix.arch }}" \
-e FLASHINFER_CUDA_ARCH_LIST="${FLASHINFER_CUDA_ARCH_LIST}" \
-e SCCACHE_BUCKET="${{ vars.SCCACHE_BUCKET }}" \
-e AWS_ACCESS_KEY_ID="${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}" \
-e AWS_SECRET_ACCESS_KEY="${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}" \
-e SCCACHE_REGION="${{ vars.SCCACHE_REGION }}" \
-w /workspace \
${{ env.DOCKER_IMAGE }} \
bash /workspace/scripts/build_flashinfer_jit_cache_whl.sh
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ jobs:
-e FLASHINFER_LOCAL_VERSION="$FLASHINFER_LOCAL_VERSION" \
-e ARCH="${{ matrix.arch }}" \
-e FLASHINFER_CUDA_ARCH_LIST="${FLASHINFER_CUDA_ARCH_LIST}" \
-e SCCACHE_BUCKET="${{ vars.SCCACHE_BUCKET }}" \
-e AWS_ACCESS_KEY_ID="${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}" \
-e AWS_SECRET_ACCESS_KEY="${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}" \
-e SCCACHE_REGION="${{ vars.SCCACHE_REGION }}" \
-w /workspace \
${{ env.DOCKER_IMAGE }} \
bash /workspace/scripts/build_flashinfer_jit_cache_whl.sh
Expand Down
9 changes: 7 additions & 2 deletions flashinfer/jit/cpp_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,18 @@ def generate_ninja_build_for_op(

cxx = os.environ.get("CXX", "c++")
nvcc = os.environ.get("FLASHINFER_NVCC", "$cuda_home/bin/nvcc")
# Compiler launchers (e.g., sccache, ccache) — empty string when unset
cxx_launcher = os.environ.get("FLASHINFER_CXX_LAUNCHER", "")
nvcc_launcher = os.environ.get("FLASHINFER_NVCC_LAUNCHER", "")

lines = [
"ninja_required_version = 1.3",
f"name = {name}",
f"cuda_home = {cuda_home}",
f"cxx = {cxx}",
f"nvcc = {nvcc}",
f"cxx_launcher = {cxx_launcher}",
f"nvcc_launcher = {nvcc_launcher}",
Comment thread
dierksen marked this conversation as resolved.
Resolved
"",
"common_cflags = " + join_multiline(common_cflags),
"cflags = " + join_multiline(cflags),
Expand All @@ -261,12 +266,12 @@ def generate_ninja_build_for_op(
"ldflags = " + join_multiline(ldflags),
"",
"rule compile",
" command = $cxx -MMD -MF $out.d $cflags -c $in -o $out $post_cflags",
" command = $cxx_launcher $cxx -MMD -MF $out.d $cflags -c $in -o $out $post_cflags",
" depfile = $out.d",
" deps = gcc",
"",
"rule cuda_compile",
" command = $nvcc --generate-dependencies-with-compile --dependency-output $out.d $cuda_cflags -c $in -o $out $cuda_post_cflags",
" command = $nvcc_launcher $nvcc --generate-dependencies-with-compile --dependency-output $out.d $cuda_cflags -c $in -o $out $cuda_post_cflags",
Comment thread
dierksen marked this conversation as resolved.
Resolved
" depfile = $out.d",
" deps = gcc",
"",
Expand Down
58 changes: 51 additions & 7 deletions scripts/build_flashinfer_jit_cache_whl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,31 @@ echo "=========================================="
echo "Building flashinfer-jit-cache wheel"
echo "=========================================="

# MAX_JOBS = min(nproc, max(1, MemAvailable_GB/4))
# Parallelism: coordinate ninja jobs (MAX_JOBS) with nvcc internal threads (FLASHINFER_NVCC_THREADS).
# Each nvcc invocation compiles multiple -gencode targets; --threads=N parallelizes them.
MEM_AVAILABLE_GB=$(free -g | awk '/^Mem:/ {print $7}')
NPROC=$(nproc)
# MAX_JOBS=$(( MEM_AVAILABLE_GB / $([ "$(uname -m)" = "aarch64" ] && echo 8 || echo 4) ))
MAX_JOBS=$(( MEM_AVAILABLE_GB / 8 ))
if (( MAX_JOBS < 1 )); then
MAX_JOBS=1
elif (( NPROC < MAX_JOBS )); then
MAX_JOBS=$NPROC

# Set NVCC_THREADS to match number of gencode targets (capped at 8), unless already set
NUM_ARCHS=$(echo "${FLASHINFER_CUDA_ARCH_LIST}" | wc -w)
NVCC_THREADS=${FLASHINFER_NVCC_THREADS:-${NUM_ARCHS}}
if (( NVCC_THREADS > 8 )); then NVCC_THREADS=8; fi
Comment thread
dierksen marked this conversation as resolved.
Resolved
if (( NVCC_THREADS < 1 )); then NVCC_THREADS=1; fi

# Memory budget: ~2GB per nvcc thread
MEM_PER_JOB=$(( NVCC_THREADS * 2 ))
MAX_JOBS=$(( MEM_AVAILABLE_GB / MEM_PER_JOB ))
Comment thread
dierksen marked this conversation as resolved.
Resolved
if (( MAX_JOBS < 1 )); then MAX_JOBS=1; fi

# Cap total threads at available CPUs
TOTAL_THREADS=$(( MAX_JOBS * NVCC_THREADS ))
if (( TOTAL_THREADS > NPROC )); then
MAX_JOBS=$(( NPROC / NVCC_THREADS ))
if (( MAX_JOBS < 1 )); then MAX_JOBS=1; fi
fi

export MAX_JOBS
export FLASHINFER_NVCC_THREADS="${NVCC_THREADS}"

# Display build environment info
echo "CUDA Version: ${CUDA_VERSION}"
Expand All @@ -30,6 +43,7 @@ echo "FlashInfer Local Version: ${FLASHINFER_LOCAL_VERSION}"
echo "CUDA Architectures: ${FLASHINFER_CUDA_ARCH_LIST}"
echo "Dev Release Suffix: ${FLASHINFER_DEV_RELEASE_SUFFIX}"
echo "MAX_JOBS: ${MAX_JOBS}"
echo "NVCC_THREADS: ${FLASHINFER_NVCC_THREADS}"
echo "Python Version: $(python3 --version)"
echo "Git commit: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')"
echo "Working directory: $(pwd)"
Expand All @@ -51,6 +65,29 @@ echo "::group::Install build system"
pip install --upgrade build
echo "::endgroup::"

# Optional: set up sccache for compiler caching with S3 backend
if [ -n "$SCCACHE_BUCKET" ]; then
echo "::group::Install sccache"
SCCACHE_VERSION="0.9.1"
SCCACHE_ARCH=$(uname -m)
curl -fsSL "https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-${SCCACHE_ARCH}-unknown-linux-musl.tar.gz" | tar xz
mv "sccache-v${SCCACHE_VERSION}-${SCCACHE_ARCH}-unknown-linux-musl/sccache" /usr/local/bin/
rm -rf "sccache-v${SCCACHE_VERSION}-${SCCACHE_ARCH}-unknown-linux-musl"
chmod +x /usr/local/bin/sccache
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Namespace cache by CUDA version and CPU architecture
export SCCACHE_S3_KEY_PREFIX="cuda${CUDA_MAJOR}${CUDA_MINOR}-${SCCACHE_ARCH}"
export SCCACHE_IDLE_TIMEOUT=0
export FLASHINFER_NVCC_LAUNCHER="sccache"
export FLASHINFER_CXX_LAUNCHER="sccache"
Comment thread
dierksen marked this conversation as resolved.
Resolved

sccache --start-server
echo "sccache version: $(sccache --version)"
echo "sccache bucket: ${SCCACHE_BUCKET}"
echo "sccache prefix: ${SCCACHE_S3_KEY_PREFIX}"
echo "::endgroup::"
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Clean any previous builds
echo "Cleaning previous builds..."
rm -rf dist build *.egg-info
Expand Down Expand Up @@ -83,5 +120,12 @@ if [ -n "${OUTPUT_DIR}" ]; then
cp -v dist/*.whl "${OUTPUT_DIR}/"
fi

# Print sccache stats if enabled
if [ -n "$SCCACHE_BUCKET" ]; then
echo "::group::sccache stats"
sccache --show-stats
echo "::endgroup::"
fi

echo ""
echo "Build process completed!"
93 changes: 75 additions & 18 deletions scripts/task_test_jit_cache_package_build_import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ echo "========================================"
echo "Starting flashinfer-jit-cache test script"
echo "========================================"

# MAX_JOBS = min(nproc, max(1, MemAvailable_GB/(8 on aarch64, 4 otherwise)))
MEM_AVAILABLE_GB=$(free -g | awk '/^Mem:/ {print $7}')
NPROC=$(nproc)
MAX_JOBS=$(( MEM_AVAILABLE_GB / $([ "$(uname -m)" = "aarch64" ] && echo 8 || echo 4) ))
if (( MAX_JOBS < 1 )); then
MAX_JOBS=1
elif (( NPROC < MAX_JOBS )); then
MAX_JOBS=$NPROC
fi

echo "System Information:"
echo " - Available Memory: ${MEM_AVAILABLE_GB} GB"
echo " - Number of Processors: ${NPROC}"
echo " - MAX_JOBS: ${MAX_JOBS}"

# Export MAX_JOBS for PyTorch's cpp_extension to use
export MAX_JOBS

: ${CUDA_VISIBLE_DEVICES:=""}
echo "CUDA_VISIBLE_DEVICES: ${CUDA_VISIBLE_DEVICES}"

Expand Down Expand Up @@ -72,6 +54,37 @@ python -c "import torch; print(torch.__version__)"
CUDA_VERSION=$(python3 -c 'import torch; print(torch.version.cuda)' | cut -d'.' -f1,2 | tr -d '.')
echo "Detected CUDA version: cu${CUDA_VERSION}"

# Parallelism: coordinate ninja jobs (MAX_JOBS) with nvcc internal threads (FLASHINFER_NVCC_THREADS).
# Each nvcc invocation compiles multiple -gencode targets; --threads=N parallelizes them.
MEM_AVAILABLE_GB=$(free -g | awk '/^Mem:/ {print $7}')
NPROC=$(nproc)

NUM_ARCHS=$(echo "${FLASHINFER_CUDA_ARCH_LIST}" | wc -w)
NVCC_THREADS=${FLASHINFER_NVCC_THREADS:-${NUM_ARCHS}}
if (( NVCC_THREADS > 8 )); then NVCC_THREADS=8; fi
if (( NVCC_THREADS < 1 )); then NVCC_THREADS=1; fi

# Memory budget: ~2GB per nvcc thread
MEM_PER_JOB=$(( NVCC_THREADS * 2 ))
MAX_JOBS=$(( MEM_AVAILABLE_GB / MEM_PER_JOB ))
if (( MAX_JOBS < 1 )); then MAX_JOBS=1; fi

# Cap total threads at available CPUs
TOTAL_THREADS=$(( MAX_JOBS * NVCC_THREADS ))
if (( TOTAL_THREADS > NPROC )); then
MAX_JOBS=$(( NPROC / NVCC_THREADS ))
if (( MAX_JOBS < 1 )); then MAX_JOBS=1; fi
fi

export MAX_JOBS
export FLASHINFER_NVCC_THREADS="${NVCC_THREADS}"

echo "System Information:"
echo " - Available Memory: ${MEM_AVAILABLE_GB} GB"
echo " - Number of Processors: ${NPROC}"
echo " - MAX_JOBS: ${MAX_JOBS}"
echo " - NVCC_THREADS: ${NVCC_THREADS}"

echo ""
echo "========================================"
echo "Installing flashinfer package"
Expand All @@ -82,6 +95,44 @@ pip install -e . || {
}
echo "✓ Flashinfer package installed successfully"

# Set up sccache for compiler caching with S3 backend.
# Uses read-write mode when AWS credentials are available (nightly/release builds),
# otherwise falls back to read-only anonymous access to the public cache bucket.
SCCACHE_BUCKET="${SCCACHE_BUCKET:-flashinfer-build-cache}"
SCCACHE_REGION="${SCCACHE_REGION:-us-west-2}"

echo ""
echo "========================================"
echo "Setting up sccache"
echo "========================================"
SCCACHE_VERSION="0.9.1"
SCCACHE_ARCH=$(uname -m)
curl -fsSL "https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-${SCCACHE_ARCH}-unknown-linux-musl.tar.gz" | tar xz
mv "sccache-v${SCCACHE_VERSION}-${SCCACHE_ARCH}-unknown-linux-musl/sccache" /usr/local/bin/
rm -rf "sccache-v${SCCACHE_VERSION}-${SCCACHE_ARCH}-unknown-linux-musl"
chmod +x /usr/local/bin/sccache

export SCCACHE_BUCKET
export SCCACHE_REGION
export SCCACHE_S3_KEY_PREFIX="cuda${CUDA_VERSION}-${SCCACHE_ARCH}"
export SCCACHE_IDLE_TIMEOUT=0
export FLASHINFER_NVCC_LAUNCHER="sccache"
export FLASHINFER_CXX_LAUNCHER="sccache"

# If no AWS credentials, use anonymous read-only access to public bucket
if [ -z "${AWS_ACCESS_KEY_ID:-}" ]; then
export SCCACHE_S3_NO_CREDENTIALS=true
echo "sccache mode: read-only (public bucket, no credentials)"
else
echo "sccache mode: read-write"
fi

sccache --start-server
echo "sccache version: $(sccache --version)"
echo "sccache bucket: ${SCCACHE_BUCKET}"
echo "sccache region: ${SCCACHE_REGION}"
echo "sccache prefix: ${SCCACHE_S3_KEY_PREFIX}"

echo ""
echo "========================================"
echo "Building flashinfer-jit-cache wheel"
Expand Down Expand Up @@ -130,6 +181,12 @@ python scripts/verify_all_modules_compiled.py || {
}
echo "✓ All modules verified successfully"

echo ""
echo "========================================"
echo "sccache stats"
echo "========================================"
sccache --show-stats

echo ""
echo "========================================"
echo "✓✓✓ ALL TESTS PASSED! ✓✓✓"
Expand Down
Loading