Skip to content

Commit

Permalink
collapse to a single containerfile, refactor build scripts to accomodate
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Miller <admiller@redhat.com>
  • Loading branch information
maxamillion committed Feb 26, 2025
1 parent bb953f7 commit 7e672c6
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 53 deletions.
11 changes: 0 additions & 11 deletions container-images/rocm-fedora-gfx10/Containerfile

This file was deleted.

13 changes: 0 additions & 13 deletions container-images/rocm-fedora-gfx11/Containerfile

This file was deleted.

11 changes: 0 additions & 11 deletions container-images/rocm-fedora-gfx8/Containerfile

This file was deleted.

11 changes: 0 additions & 11 deletions container-images/rocm-fedora-gfx9/Containerfile

This file was deleted.

9 changes: 9 additions & 0 deletions container-images/rocm-fedora/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM registry.fedoraproject.org/fedora:41

ARG ROCM_VARIANT
COPY ../scripts /scripts
RUN chmod +x /scripts/*.sh && \
/scripts/build_llama_and_whisper.sh "rocm" "${ROCM_VARIANT}"

ENV WHISPER_CPP_SHA=${WHISPER_CPP_SHA}
ENV LLAMA_CPP_SHA=${LLAMA_CPP_SHA}
29 changes: 26 additions & 3 deletions container-images/scripts/build_llama_and_whisper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ dnf_install() {
"procps-ng" "git" "dnf-plugins-core" "libcurl-devel")
local vulkan_rpms=("vulkan-headers" "vulkan-loader-devel" "vulkan-tools" \
"spirv-tools" "glslc" "glslang")
if [ "$containerfile" = "ramalama" ] || [ "$containerfile" = "rocm" ] || \
[ "$containerfile" = "vulkan" ]; then # All the UBI-based ones
if [[ "${containerfile}" = "ramalama" ]] || [[ "${containerfile}" =~ rocm* ]] || \
[[ "${containerfile}" = "vulkan" ]]; then # All the UBI-based ones
if [ "${ID}" = "fedora" ]; then
dnf install -y "${rpm_list[@]}"
else
Expand Down Expand Up @@ -90,7 +90,7 @@ set_install_prefix() {
configure_common_flags() {
common_flags=("-DGGML_NATIVE=OFF")
case "$containerfile" in
rocm)
rocm*)
if [ "${ID}" = "fedora" ]; then
common_flags+=("-DCMAKE_HIP_COMPILER_ROCM_ROOT=/usr")
fi
Expand Down Expand Up @@ -135,6 +135,25 @@ clone_and_build_llama_cpp() {
rm -rf llama.cpp
}

clean_fedora_rocm() {
case "${1}" in
gfx8)
rm -fr /usr/lib64/rocm/gfx9* /usr/lib64/rocm/gfx10* /usr/lib64/rocm/gfx11*
;;
gfx9)
rm -fr /usr/lib64/rocm/gfx8* /usr/lib64/rocm/gfx10* /usr/lib64/rocm/gfx11*
;;
gfx10)
rm -fr /usr/lib64/rocm/gfx8* /usr/lib64/rocm/gfx9* /usr/lib64/rocm/gfx11*
;;
gfx11)
rm -fr /usr/lib64/rocm/gfx8* /usr/lib64/rocm/gfx9* /usr/lib64/rocm/gfx10* && \
ln -s /usr/lib64/rocm/gfx1103/lib/rocblas/library/TensileLibrary_lazy_gfx1103.dat \
/usr/lib64/rocblas/library/TensileLibrary_lazy_gfx1103.dat
;;
esac
}

main() {
source /etc/os-release

Expand Down Expand Up @@ -162,8 +181,12 @@ main() {
esac

clone_and_build_llama_cpp
if [ "${ID}" = "fedora" ]; then
clean_fedora_rocm
fi
rm -rf /var/cache/*dnf* /opt/rocm-*/lib/*/library/*gfx9*
ldconfig # needed for libraries
}


main "$@"
21 changes: 17 additions & 4 deletions container_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -euo pipefail

_FEDORA_ROCM_VARIANTS=("gfx9" "gfx10" "gfx11")

available() {
command -v "$1" >/dev/null
}
Expand All @@ -28,7 +30,12 @@ add_build_platform() {

conman_build+=("--platform" "$platform")
conman_build+=("-t" "$REGISTRY_PATH/$image_name")
conman_build+=("-f" "$image_name/Containerfile" ".")
if [[ "${image_name}" =~ "rocm-fedora" ]]; then
conman_build+=("-f" "rocm-fedora/Containerfile" "--build-arg" "ROCM_VARIANT=${image_name#*-*-}")
else
conman_build+=("-f" "$image_name/Containerfile")
fi
conman_build+=(".")
}

rm_container_image() {
Expand All @@ -42,7 +49,7 @@ build() {
local image_name="${1//container-images\//}"
local conman_build=("${conman[@]}")
local conman_show_size=("${conman[@]}" "images" "--filter" "reference='$REGISTRY_PATH/$image_name'")
if [ "$3" == "-d" ]; then
if [[ "${3}" == "-d" ]]; then
add_build_platform
echo "${conman_build[@]}"
cd - > /dev/null
Expand Down Expand Up @@ -125,12 +132,18 @@ process_all_targets() {
# skip images that don't make sense for multi-arch builds
if [ "$command" = "multi-arch" ]; then
case "${i//container-images\//}" in
rocm|intel-gpu)
rocm|rocm-fedora|intel-gpu)
continue
;;
esac
fi
build "$i" "$command" "$option"
if [[ "${i}" =~ "rocm-fedora" ]]; then
for v in "${_FEDORA_ROCM_VARIANTS[@]}"; do
build "$i" "$command" "$option"
done
else
build "$i" "$command" "$option"
fi
done
}

Expand Down

0 comments on commit 7e672c6

Please sign in to comment.