Updating toolboxes with a two-stage build process to reduce size
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
FROM fedora:rawhide
|
||||
# build
|
||||
FROM registry.fedoraproject.org/fedora:rawhide AS builder
|
||||
|
||||
# 1) Install dependencies
|
||||
RUN dnf install -y \
|
||||
RUN dnf -y --nodocs --setopt=install_weak_deps=False install \
|
||||
make gcc cmake lld clang clang-devel compiler-rt libcurl-devel \
|
||||
radeontop git vim patch curl ninja-build \
|
||||
&& dnf clean all
|
||||
radeontop git vim patch curl ninja-build tar xz \
|
||||
&& dnf clean all && rm -rf /var/cache/dnf/*
|
||||
|
||||
# 2) Download ROCm nightly tarball
|
||||
WORKDIR /tmp
|
||||
RUN curl -L -o therock.tar.gz \
|
||||
https://therock-nightly-tarball.s3.amazonaws.com/therock-dist-linux-gfx1151-7.0.0rc20250811.tar.gz
|
||||
|
||||
# 3) Extract into /opt/rocm-7.0
|
||||
RUN mkdir -p /opt/rocm-7.0 \
|
||||
&& tar xvf therock.tar.gz -C /opt/rocm-7.0 --strip-components=1
|
||||
&& tar xzf therock.tar.gz -C /opt/rocm-7.0 --strip-components=1
|
||||
|
||||
# 4) Bake in ROCm env + full system PATH
|
||||
ENV ROCM_PATH=/opt/rocm-7.0 \
|
||||
HIP_PLATFORM=amd \
|
||||
HIP_PATH=/opt/rocm-7.0 \
|
||||
@@ -29,7 +25,6 @@ ENV ROCM_PATH=/opt/rocm-7.0 \
|
||||
CPATH=/opt/rocm-7.0/include \
|
||||
PKG_CONFIG_PATH=/opt/rocm-7.0/lib/pkgconfig
|
||||
|
||||
# 5) profile.d snippet for login & interactive shells
|
||||
RUN printf '%s\n' \
|
||||
'export ROCM_PATH=/opt/rocm-7.0' \
|
||||
'export HIP_PLATFORM=amd' \
|
||||
@@ -48,28 +43,17 @@ RUN printf '%s\n' \
|
||||
&& chmod +x /etc/profile.d/rocm.sh \
|
||||
&& echo 'source /etc/profile.d/rocm.sh' >> /etc/bashrc
|
||||
|
||||
# Install rocwmma
|
||||
WORKDIR /opt/
|
||||
WORKDIR /opt
|
||||
COPY ./build-rocwmma.sh .
|
||||
RUN chmod +x build-rocwmma.sh
|
||||
RUN ./build-rocwmma.sh
|
||||
RUN chmod +x build-rocwmma.sh && ./build-rocwmma.sh
|
||||
|
||||
# 6) Clone llama.cpp
|
||||
WORKDIR /opt/llama.cpp
|
||||
RUN git clone --recursive https://github.com/ggerganov/llama.cpp.git . \
|
||||
&& git clean -xdf \
|
||||
&& git submodule update --recursive
|
||||
COPY ./apply-rocwmma-fix.sh /opt/apply-rocwmma-fix.sh
|
||||
RUN chmod +x /opt/apply-rocwmma-fix.sh && /opt/apply-rocwmma-fix.sh /opt/llama.cpp
|
||||
|
||||
# Apply PAtch for rocwmma
|
||||
COPY ./apply-rocwmma-fix.sh /opt
|
||||
RUN chmod +x /opt/apply-rocwmma-fix.sh
|
||||
RUN /opt/apply-rocwmma-fix.sh /opt/llama.cpp
|
||||
|
||||
# 7) Apply patchpatch and apply
|
||||
COPY hip-rocm7rc.patch /opt/llama.cpp/hip-rocm7rc.patch
|
||||
RUN patch -p1 < hip-rocm7rc.patch
|
||||
|
||||
# 8) Configure, build & install llama.cpp with HIP
|
||||
RUN cmake -S . -B build \
|
||||
-DGGML_HIP=ON \
|
||||
-DAMDGPU_TARGETS=gfx1151 \
|
||||
@@ -79,13 +63,59 @@ RUN cmake -S . -B build \
|
||||
&& cmake --build build --config Release -- -j$(nproc) \
|
||||
&& cmake --install build --config Release
|
||||
|
||||
# 9) Copy the .so from build/bin into /usr/lib64 so ldconfig can see it
|
||||
RUN find /opt/llama.cpp/build -type f -name 'lib*.so*' -exec cp {} /usr/lib64/ \; \
|
||||
&& ldconfig
|
||||
# keep bin; drop headers/docs/static libs; drop source tree
|
||||
RUN find /opt/rocm-7.0 -type f -name '*.a' -delete \
|
||||
&& rm -rf /opt/rocm-7.0/include /opt/rocm-7.0/share \
|
||||
/opt/rocm-7.0/llvm/include /opt/rocm-7.0/llvm/share \
|
||||
&& rm -rf /opt/llama.cpp
|
||||
|
||||
# runtime
|
||||
FROM registry.fedoraproject.org/fedora-minimal:rawhide
|
||||
|
||||
RUN microdnf -y --nodocs --setopt=install_weak_deps=0 install \
|
||||
bash ca-certificates libatomic libstdc++ libgcc radeontop vim \
|
||||
&& microdnf clean all && rm -rf /var/cache/dnf/*
|
||||
|
||||
COPY --from=builder /opt/rocm-7.0 /opt/rocm-7.0
|
||||
COPY --from=builder /usr/local/ /usr/local/
|
||||
|
||||
# 10) Install helper script
|
||||
COPY gguf-vram-estimator.py /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/gguf-vram-estimator.py
|
||||
|
||||
# 11) Default to interactive bash
|
||||
ENV ROCM_PATH=/opt/rocm-7.0 \
|
||||
HIP_PLATFORM=amd \
|
||||
HIP_PATH=/opt/rocm-7.0 \
|
||||
HIP_CLANG_PATH=/opt/rocm-7.0/llvm/bin \
|
||||
HIP_INCLUDE_PATH=/opt/rocm-7.0/include \
|
||||
HIP_LIB_PATH=/opt/rocm-7.0/lib \
|
||||
HIP_DEVICE_LIB_PATH=/opt/rocm-7.0/lib/llvm/amdgcn/bitcode \
|
||||
PATH=/opt/rocm-7.0/bin:/opt/rocm-7.0/llvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
|
||||
LD_LIBRARY_PATH=/opt/rocm-7.0/lib:/opt/rocm-7.0/lib64:/opt/rocm-7.0/llvm/lib \
|
||||
LIBRARY_PATH=/opt/rocm-7.0/lib:/opt/rocm-7.0/lib64 \
|
||||
CPATH=/opt/rocm-7.0/include \
|
||||
PKG_CONFIG_PATH=/opt/rocm-7.0/lib/pkgconfig
|
||||
|
||||
RUN printf '%s\n' \
|
||||
'export ROCM_PATH=/opt/rocm-7.0' \
|
||||
'export HIP_PLATFORM=amd' \
|
||||
'export HIP_PATH=/opt/rocm-7.0' \
|
||||
'export HIP_CLANG_PATH=/opt/rocm-7.0/llvm/bin' \
|
||||
'export HIP_INCLUDE_PATH=/opt/rocm-7.0/include' \
|
||||
'export HIP_LIB_PATH=/opt/rocm-7.0/lib' \
|
||||
'export HIP_DEVICE_LIB_PATH=/opt/rocm-7.0/lib/llvm/amdgcn/bitcode' \
|
||||
'export PATH="$ROCM_PATH/bin:$HIP_CLANG_PATH:$PATH"' \
|
||||
'export LD_LIBRARY_PATH="$HIP_LIB_PATH:$ROCM_PATH/lib:$ROCM_PATH/lib64:$ROCM_PATH/llvm/lib"' \
|
||||
'export LIBRARY_PATH="$HIP_LIB_PATH:$ROCM_PATH/lib:$ROCM_PATH/lib64"' \
|
||||
'export CPATH="$HIP_INCLUDE_PATH"' \
|
||||
'export PKG_CONFIG_PATH="$ROCM_PATH/lib/pkgconfig"' \
|
||||
'export ROCBLAS_USE_HIPBLASLT=1' \
|
||||
> /etc/profile.d/rocm.sh \
|
||||
&& chmod +x /etc/profile.d/rocm.sh \
|
||||
&& echo 'source /etc/profile.d/rocm.sh' >> /etc/bashrc
|
||||
|
||||
# make /usr/local libs visible without touching env
|
||||
RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf \
|
||||
&& echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local.conf \
|
||||
&& ldconfig
|
||||
|
||||
CMD ["/bin/bash"]
|
||||
|
||||
Reference in New Issue
Block a user