Skip to content

Commit 3172429

Browse files
committed
Fix crashing
captures the block returned by the last emulate_i128_* call (loop_body_exit_bb) and uses it for the bit_phi, quot_phi, and rem_phi incoming edges. This keeps the PHIs consistent with the optimized control flow that those helpers build, so the codegen no longer crashes.
1 parent 8a26542 commit 3172429

File tree

2 files changed

+171
-3
lines changed

2 files changed

+171
-3
lines changed

crates/rustc_codegen_nvvm/src/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16771677
let one_shifted = body_bx.emulate_i128_shl(one_i128, bit_next);
16781678
let quot_candidate = body_bx.or(quot_phi, one_shifted);
16791679
let quot_new = body_bx.select(rem_ge, quot_candidate, quot_phi);
1680+
let loop_body_exit_bb = body_bx.llbb();
16801681
body_bx.br(loop_header_bb);
1681-
header_bx.add_incoming_to_phi(bit_phi, bit_next, loop_body_bb);
1682-
header_bx.add_incoming_to_phi(quot_phi, quot_new, loop_body_bb);
1683-
header_bx.add_incoming_to_phi(rem_phi, rem_new, loop_body_bb);
1682+
header_bx.add_incoming_to_phi(bit_phi, bit_next, loop_body_exit_bb);
1683+
header_bx.add_incoming_to_phi(quot_phi, quot_new, loop_body_exit_bb);
1684+
header_bx.add_incoming_to_phi(rem_phi, rem_new, loop_body_exit_bb);
16841685

16851686
*self = exit_bx;
16861687
(quot_res, rem_res)

deploy-cuda.sh

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Remote connection details
5+
REMOTE_HOST="[email protected]"
6+
REMOTE_PORT="24527"
7+
REMOTE_DIR="/root/Rust-CUDA"
8+
SSH_OPTS=(-o StrictHostKeyChecking=no -L 8080:localhost:8080)
9+
10+
echo "🚀 Deploying Rust GPU Chimera Demo to vast.ai (Native CUDA Setup)"
11+
echo "=============================================================="
12+
13+
# Create remote directory
14+
echo "Creating remote directory..."
15+
ssh "${SSH_OPTS[@]}" -p "$REMOTE_PORT" "$REMOTE_HOST" "mkdir -p $REMOTE_DIR"
16+
17+
# Sync files
18+
echo "Syncing project files..."
19+
rsync -avz --delete \
20+
--exclude 'target/' \
21+
--exclude '.git/' \
22+
--exclude '*.swp' \
23+
--exclude '.DS_Store' \
24+
--exclude 'deploy-*.sh' \
25+
-e "ssh ${SSH_OPTS[*]} -p $REMOTE_PORT" \
26+
./ "$REMOTE_HOST:$REMOTE_DIR/"
27+
28+
echo "Files synced successfully!"
29+
30+
# SSH into the machine and set up environment
31+
echo -e "\n📦 Setting up CUDA development environment..."
32+
ssh "${SSH_OPTS[@]}" -p "$REMOTE_PORT" "$REMOTE_HOST" << 'EOF'
33+
# Clear MOTD
34+
echo "" > /etc/motd
35+
36+
cd /root/Rust-CUDA
37+
38+
# Check GPU
39+
echo -e "\n🎮 GPU Information:"
40+
nvidia-smi --query-gpu=name,driver_version,memory.total --format=csv
41+
42+
# Check CUDA version
43+
echo -e "\n🚀 CUDA Version:"
44+
nvcc --version 2>/dev/null || echo "NVCC not found, checking nvidia-smi..."
45+
nvidia-smi | grep "CUDA Version" || echo "CUDA info not found"
46+
47+
# Install build dependencies if not present
48+
echo -e "\n📦 Installing build dependencies..."
49+
if ! command -v clang &> /dev/null; then
50+
apt-get update
51+
DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
52+
build-essential \
53+
clang \
54+
curl \
55+
libssl-dev \
56+
libtinfo-dev \
57+
pkg-config \
58+
xz-utils \
59+
zlib1g-dev
60+
fi
61+
62+
# Install Rust if not present
63+
if ! command -v cargo &> /dev/null; then
64+
echo -e "\n🦀 Installing Rust..."
65+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
66+
source $HOME/.cargo/env
67+
fi
68+
69+
# Show Rust version
70+
echo -e "\n🦀 Rust version:"
71+
cargo --version
72+
rustc --version
73+
74+
# Check if LLVM 7 is needed and not present
75+
if ! command -v llvm-config-7 &> /dev/null && ! command -v llvm-config &> /dev/null; then
76+
echo -e "\n⚠️ LLVM 7 not found. Installing LLVM for CUDA support..."
77+
78+
# Install LLVM dependencies
79+
apt-get update
80+
DEBIAN_FRONTEND=noninteractive apt-get -qq -y install \
81+
libffi-dev \
82+
libedit-dev \
83+
libncurses5-dev \
84+
libxml2-dev \
85+
python3 \
86+
ninja-build
87+
88+
# Download and build LLVM 7.1.0
89+
mkdir -p /tmp/llvm7
90+
cd /tmp/llvm7
91+
92+
echo "Downloading LLVM 7.1.0..."
93+
curl -sSf -L -O https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/llvm-7.1.0.src.tar.xz
94+
tar -xf llvm-7.1.0.src.tar.xz
95+
cd llvm-7.1.0.src
96+
mkdir build && cd build
97+
98+
echo "Building LLVM 7.1.0 (this will take a while)..."
99+
cmake -G Ninja \
100+
-DCMAKE_BUILD_TYPE=Release \
101+
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
102+
-DLLVM_BUILD_LLVM_DYLIB=ON \
103+
-DLLVM_LINK_LLVM_DYLIB=ON \
104+
-DLLVM_ENABLE_ASSERTIONS=OFF \
105+
-DLLVM_ENABLE_BINDINGS=OFF \
106+
-DLLVM_INCLUDE_EXAMPLES=OFF \
107+
-DLLVM_INCLUDE_TESTS=OFF \
108+
-DLLVM_INCLUDE_BENCHMARKS=OFF \
109+
-DLLVM_ENABLE_ZLIB=ON \
110+
-DLLVM_ENABLE_TERMINFO=ON \
111+
-DCMAKE_INSTALL_PREFIX=/usr \
112+
..
113+
114+
ninja -j$(nproc)
115+
ninja install
116+
117+
# Create symlink
118+
ln -s /usr/bin/llvm-config /usr/bin/llvm-config-7
119+
120+
# Cleanup
121+
cd /
122+
rm -rf /tmp/llvm7
123+
124+
echo "LLVM 7 installed successfully!"
125+
fi
126+
127+
# Set up environment variables
128+
export LD_LIBRARY_PATH="/usr/local/cuda/nvvm/lib64:${LD_LIBRARY_PATH}"
129+
export LLVM_LINK_STATIC=1
130+
export RUST_LOG=info
131+
export PATH="$HOME/.cargo/bin:${PATH}"
132+
133+
# Go back to project directory
134+
cd /root/Rust-CUDA
135+
136+
# Show toolchain info
137+
echo -e "\n🔧 Rust toolchain:"
138+
rustup show
139+
140+
# Build and run
141+
echo -e "\n🔨 Building project..."
142+
143+
# Test CPU backend first
144+
echo -e "\n📊 Testing CPU backend..."
145+
cargo test --release
146+
cargo run --release
147+
148+
# Test CUDA backend
149+
echo -e "\n🎮 Building and testing CUDA backend..."
150+
if cargo build --release --features cuda; then
151+
echo "CUDA build successful!"
152+
echo -e "\n🚀 Running CUDA demo..."
153+
cargo test --release --features cuda
154+
cargo run --release --features cuda
155+
else
156+
echo "CUDA build failed. Checking environment..."
157+
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
158+
echo "CUDA NVVM libraries:"
159+
ls -la /usr/local/cuda/nvvm/lib64/ 2>/dev/null || echo "NVVM lib64 not found"
160+
echo "LLVM config:"
161+
llvm-config --version 2>/dev/null || echo "llvm-config not found"
162+
fi
163+
164+
echo -e "\n✅ Setup complete!"
165+
EOF
166+
167+
echo -e "\n✅ Deployment complete!"

0 commit comments

Comments
 (0)