Skip to content

Commit fca2d1e

Browse files
committed
Enhance setup script with smart APT update strategy, improved CUDA version detection, and conditional installation of development libraries; update GitHub Actions workflow to include weekly cache timestamp and cache APT packages.
1 parent 273e4a1 commit fca2d1e

File tree

2 files changed

+108
-17
lines changed

2 files changed

+108
-17
lines changed

.ci/setup.sh

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,65 @@ echo "CUDA_VERSION: $CUDA_VERSION"
1717

1818
# Install system dependencies
1919
echo "Installing system dependencies..."
20-
sudo apt-get update
2120

22-
# Set up LLVM 17 APT source with modern GPG key handling
23-
echo "Setting up LLVM 17 APT source with modern GPG key handling..."
24-
25-
# Download and install GPG key to /usr/share/keyrings
26-
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key |
27-
gpg --dearmor | sudo tee /usr/share/keyrings/llvm-archive-keyring.gpg >/dev/null
28-
29-
# Make sure key file is readable by _apt
30-
sudo chmod a+r /usr/share/keyrings/llvm-archive-keyring.gpg
21+
# Check if we have cached APT lists (indicates cache hit)
22+
HAS_APT_CACHE=false
23+
if [ -f "/var/lib/apt/lists/lock" ] || [ "$(ls -A /var/lib/apt/lists/ 2>/dev/null | wc -l)" -gt 5 ]; then
24+
echo "✅ Detected cached APT package lists"
25+
HAS_APT_CACHE=true
26+
else
27+
echo "📦 No APT cache found"
28+
HAS_APT_CACHE=false
29+
fi
3130

32-
# Write APT source list, explicitly binding keyring file
33-
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" |
34-
sudo tee /etc/apt/sources.list.d/llvm-toolchain-jammy-17.list
31+
# Set up LLVM 17 APT source with modern GPG key handling
32+
echo "Setting up LLVM 17 APT source..."
33+
NEED_SOURCE_UPDATE=false
34+
35+
# Check if LLVM source is already configured
36+
if [ ! -f "/etc/apt/sources.list.d/llvm-toolchain-jammy-17.list" ]; then
37+
echo "📝 Configuring LLVM APT source..."
38+
39+
# Download and install GPG key to /usr/share/keyrings
40+
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key |
41+
gpg --dearmor | sudo tee /usr/share/keyrings/llvm-archive-keyring.gpg >/dev/null
42+
43+
# Make sure key file is readable by _apt
44+
sudo chmod a+r /usr/share/keyrings/llvm-archive-keyring.gpg
45+
46+
# Write APT source list, explicitly binding keyring file
47+
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" |
48+
sudo tee /etc/apt/sources.list.d/llvm-toolchain-jammy-17.list
49+
50+
NEED_SOURCE_UPDATE=true
51+
echo "✅ LLVM APT source configured"
52+
else
53+
echo "✅ LLVM APT source already configured"
54+
fi
3555

36-
# Update package lists
37-
sudo apt-get update
56+
# Smart APT update strategy
57+
APT_UPDATED=false
58+
if [ "$HAS_APT_CACHE" = "true" ] && [ "$NEED_SOURCE_UPDATE" = "false" ]; then
59+
echo "🚀 Using cached package lists, skipping initial update"
60+
APT_UPDATED=false
61+
elif [ "$NEED_SOURCE_UPDATE" = "true" ]; then
62+
echo "🔄 Updating package lists (new source added)..."
63+
sudo apt-get update
64+
APT_UPDATED=true
65+
else
66+
echo "🔄 Updating package lists (no cache available)..."
67+
sudo apt-get update
68+
APT_UPDATED=true
69+
fi
3870

3971
# Install clang and clangd first
4072
echo "Installing clang and clangd..."
41-
sudo apt-get install -y clang-17 clangd-17
73+
if command -v clang-17 &> /dev/null && command -v clangd-17 &> /dev/null; then
74+
echo "✅ clang-17 and clangd-17 already installed"
75+
else
76+
echo "📦 Installing clang-17 and clangd-17..."
77+
sudo apt-get install -y clang-17 clangd-17
78+
fi
4279

4380
# Set up clang alternatives
4481
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 100
@@ -47,7 +84,42 @@ sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-17 100
4784

4885
# Install CUDA and development libraries
4986
echo "Installing CUDA and development libraries..."
50-
sudo apt-get install -y cuda-toolkit-12.8 libstdc++6 libstdc++-12-dev libffi-dev libncurses-dev zlib1g-dev libxml2-dev git build-essential
87+
88+
# Check for specific CUDA 12.8 version
89+
CUDA_VERSION_REQUIRED="12.8"
90+
HAS_CORRECT_CUDA=false
91+
92+
if command -v nvcc &> /dev/null; then
93+
# Get CUDA version from nvcc
94+
INSTALLED_CUDA_VERSION=$(nvcc --version | grep "release" | sed -n 's/.*release \([0-9]\+\.[0-9]\+\).*/\1/p')
95+
if [ "$INSTALLED_CUDA_VERSION" = "$CUDA_VERSION_REQUIRED" ]; then
96+
echo "✅ CUDA $CUDA_VERSION_REQUIRED already installed"
97+
HAS_CORRECT_CUDA=true
98+
else
99+
echo "⚠️ Found CUDA $INSTALLED_CUDA_VERSION, but need $CUDA_VERSION_REQUIRED"
100+
HAS_CORRECT_CUDA=false
101+
fi
102+
else
103+
echo "📦 No CUDA toolkit found"
104+
HAS_CORRECT_CUDA=false
105+
fi
106+
107+
if [ "$HAS_CORRECT_CUDA" = "true" ]; then
108+
echo "🔧 Installing development libraries only..."
109+
# Install other dev libraries but skip CUDA toolkit
110+
sudo apt-get install -y libstdc++6 libstdc++-12-dev libffi-dev libncurses-dev zlib1g-dev libxml2-dev git build-essential
111+
else
112+
# Need to install CUDA - ensure package lists are updated
113+
if [ "$APT_UPDATED" = "false" ]; then
114+
echo "🔄 Updating package lists before CUDA installation..."
115+
sudo apt-get update
116+
APT_UPDATED=true
117+
fi
118+
119+
echo "📦 Installing CUDA $CUDA_VERSION_REQUIRED and development libraries..."
120+
# Install all packages including CUDA toolkit (this is the big download)
121+
sudo apt-get install -y cuda-toolkit-12.8 libstdc++6 libstdc++-12-dev libffi-dev libncurses-dev zlib1g-dev libxml2-dev git build-essential
122+
fi
51123

52124
# Verify clang installation
53125
echo "Verifying clang installation..."

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
echo "date=$DATE_STAMP" >> $GITHUB_OUTPUT
4343
echo "Using daily cache stamp: $DATE_STAMP"
4444
45+
- name: Get weekly cache timestamp
46+
id: weekly-cache
47+
run: |
48+
# Calculate year-week (e.g., 2024-03) for weekly cache expiration
49+
WEEK_STAMP=$(date +"%Y-%U")
50+
echo "week=$WEEK_STAMP" >> $GITHUB_OUTPUT
51+
echo "Using weekly cache stamp: $WEEK_STAMP"
52+
4553
- name: Cache pip dependencies
4654
uses: actions/cache@v3
4755
with:
@@ -50,6 +58,17 @@ jobs:
5058
restore-keys: |
5159
${{ runner.os }}-pip-3.11-
5260
61+
- name: Cache APT packages
62+
uses: actions/cache@v3
63+
with:
64+
path: |
65+
/var/cache/apt/archives
66+
/var/lib/apt/lists
67+
key: ${{ runner.os }}-apt-${{ hashFiles('.ci/setup.sh') }}-${{ steps.weekly-cache.outputs.week }}
68+
restore-keys: |
69+
${{ runner.os }}-apt-${{ hashFiles('.ci/setup.sh') }}-
70+
${{ runner.os }}-apt-
71+
5372
- name: Get Triton latest commit
5473
id: triton-commit
5574
run: |

0 commit comments

Comments
 (0)