1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# RusTorch GPU Dockerfile
# CUDA and OpenCL support for GPU acceleration
FROM nvidia/cuda:12.2-devel-ubuntu22.04 as builder
# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
cmake \
clang \
python3 \
python3-dev \
ocl-icd-opencl-dev \
opencl-headers \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /usr/src/rustorch
# Copy manifests
COPY Cargo.toml Cargo.lock ./
# Create dummy main for dependency caching
RUN mkdir -p src && echo "fn main() {}" > src/main.rs
RUN cargo build --release --features "cuda opencl" && rm -rf src
# Copy source code
COPY src ./src
COPY examples ./examples
# Build with GPU features
RUN cargo build --release --features "cuda opencl"
# Production stage
FROM nvidia/cuda:12.2-runtime-ubuntu22.04
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
python3 \
python3-pip \
ocl-icd-opencl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN useradd -m -u 1001 rustorch
# Create directories
RUN mkdir -p /app/data /app/models /app/output && \
chown -R rustorch:rustorch /app
# Copy built artifacts
COPY --from=builder /usr/src/rustorch/target/release/deps/* /app/bin/
COPY --from=builder /usr/src/rustorch/target/release/librustorch.* /app/lib/
COPY --from=builder /usr/src/rustorch/examples /app/examples/
# Set environment variables
ENV RUST_LOG=info
ENV CUDA_VISIBLE_DEVICES=0
ENV RUSTORCH_GPU=true
# Switch to non-root user
USER rustorch
WORKDIR /app
# Health check with GPU validation
HEALTHCHECK --interval=60s --timeout=30s --start-period=10s --retries=3 \
CMD nvidia-smi || exit 1
CMD ["bash"]