gRPCServerCLI: AMD Support
Using [SCALE](https://docs.scale-lang.com/stable/) for CUDA compatibility and a heaping of source hacks I was able to compile for AMD.
I don't have a SCALE supported GPU, but hopefully support for the Strix Halo / Ryzen AI MAX+ 395 / gfx1151 is added soon so I can test.
Unfortunately, I did have to disable cuDNN since SCALE doesn't target that yet. I don't know what fallbacks are in place, but hoping paths will still be CUDA/SCALE GPU accelerated.
Adding the below as a starting point for others.
```Dockerfile
# Dockerfile
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# System deps (git, etc. – add ROCm/Vulkan bits as needed)
RUN apt-get update && apt-get install -y --no-install-recommends \
bash git wget curl ca-certificates \
libncurses6 libpng-dev libjpeg-dev libatlas-base-dev libblas-dev clang llvm \
&& rm -rf /var/lib/apt/lists/*
# SCALE
RUN cd /root && wget https://pkgs.scale-lang.com/deb/dists/noble/main/binary-all/scale-repos.deb \
&& apt-get install -y ./scale-repos.deb && rm /root/scale-repos.deb \
&& apt-get update && apt-get install -y scale-free \
&& rm -rf /var/lib/apt/lists/*
# Swift (official toolchain)
RUN apt-get update && apt-get install -y --no-install-recommends \
unzip gnupg2 libcurl4-openssl-dev libpython3-dev pkg-config \
&& rm -rf /var/lib/apt/lists/* && \
\
cd /tmp && \
curl -LO "https://download.swift.org/swift-6.2.1-release/ubuntu2404/swift-6.2.1-RELEASE/swift-6.2.1-RELEASE-ubuntu24.04.tar.gz" && \
# Extract directly into /usr/local
tar xzf swift-*.tar.gz -C /usr/local && \
# Create a stable /usr/local/swift symlink
SWIFT_DIR=$(ls -d /usr/local/swift-* | head -n 1) && \
ln -s "$SWIFT_DIR" /usr/local/swift && \
rm swift-*.tar.gz && \
\
# Make swiftc / swift globally available
ln -sf /usr/local/swift/usr/bin/swiftc /usr/bin/swiftc && \
ln -sf /usr/local/swift/usr/bin/swift /usr/bin/swift
ENV PATH="/usr/local/swift/usr/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/swift/usr/lib:/usr/local/swift/usr/lib/swift/linux"
ENV C_INCLUDE_PATH="/usr/local/swift/usr/include"
ENV CPLUS_INCLUDE_PATH="/usr/local/swift/usr/include"
# Bazel
RUN cd /root && wget https://github.com/bazelbuild/bazelisk/releases/download/v1.27.0/bazelisk-amd64.deb \
&& apt-get update && apt-get install -y ./bazelisk-amd64.deb \
&& rm -rf /var/lib/apt/lists/*
# Use bash for all subsequent RUN commands
SHELL ["/bin/bash", "-lc"]
# Tell Bazel / rules_swift to use clang instead of gcc
ENV CC=clang CXX=clang++ LD=lld
# Make llvm-config visible where rules_swift expects it
# (Ubuntu will install e.g. /usr/bin/llvm-config-18)
RUN if command -v llvm-config-18 >/dev/null 2>&1; then \
ln -sf "$(command -v llvm-config-18)" /usr/local/bin/llvm-config; \
elif command -v llvm-config >/dev/null 2>&1; then \
ln -sf "$(command -v llvm-config)" /usr/local/bin/llvm-config; \
fi
# libdispatch build deps (from swift-corelibs-libdispatch INSTALL for Linux)
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
ninja-build \
clang \
systemtap-sdt-dev \
libbsd-dev \
linux-libc-dev \
&& rm -rf /var/lib/apt/lists/*
# Build and install swift-corelibs-libdispatch (GCD) for Linux
WORKDIR /usr/local/src
RUN git clone --depth=1 https://github.com/swiftlang/swift-corelibs-libdispatch.git && \
mkdir -p swift-corelibs-libdispatch/build && \
cd swift-corelibs-libdispatch/build && \
cmake -G Ninja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_INSTALL_PREFIX=/usr/local \
.. && \
ninja && \
ninja install && \
cd / && rm -rf /usr/local/src/swift-corelibs-libdispatch
WORKDIR /usr/local/src
RUN git clone https://github.com/drawthingsai/draw-things-community.git
WORKDIR /usr/local/src/draw-things-community
RUN \
# Disable cuDNN + dispatch for this SCALE build
sed -i 's/have_cudnn = True/have_cudnn = False/' WORKSPACE.linux && \
# sed -i 's/use_dispatch = True/use_dispatch = False/' WORKSPACE.linux && \
\
# Enter SCALE env + install Bazel deps
. /opt/scale/bin/scaleenv gfx1100 && \
./Scripts/install.sh && \
\
# 1) Fetch only the deps for Apps:gRPCServerCLI
bazel fetch //Apps:gRPCServerCLI || true && \
\
# 2) Patch sentencepiece: make PROTOBUF_NOINLINE a no-op so it doesn't
# conflict with PROTOBUF_ALWAYS_INLINE on SCALE/clang.
find /root/.cache/bazel -path '*external/sentencepiece/third_party/protobuf-lite/google/protobuf/port_def.inc' \
-print -exec sed -i 's/#define PROTOBUF_NOINLINE[[:space:]]\+__attribute__((noinline))/#define PROTOBUF_NOINLINE/' {} \; && \
\
# 3) Patch s4nnc: FILE* optionals in Store.swift + DataFrameAddons.swift
find /root/.cache/bazel -path '*external/s4nnc/nnc/Store.swift' \
-print -exec sed -i \
-e 's/fileno(fp)/fileno(fp!)/' \
-e 's/fseek(fp, 0, SEEK_END)/fseek(fp!, 0, SEEK_END)/' \
-e 's/ftell(fp)/ftell(fp!)/' \
-e 's/fclose(fp)/fclose(fp!)/' \
-e 's/fseek(externalFileRead, offset, SEEK_SET)/fseek(externalFileRead!, offset, SEEK_SET)/' \
-e 's/fread(loadedBytes, 1, length, externalFileRead)/fread(loadedBytes, 1, length, externalFileRead!)/' \
{} \; && \
\
find /root/.cache/bazel -path '*external/s4nnc/nnc/DataFrameAddons.swift' \
-print -exec sed -i \
-e 's/fclose(fileHandle)/fclose(fileHandle!)/' \
{} \; && \
\
# 4) Patch SwiftLog: localtime() returns Optional<tm> on this toolchain
find /root/.cache/bazel -path '*external/SwiftLog/Sources/Logging/Logging.swift' \
-print -exec sed -i \
'/"%Y-%m-%dT%H:%M:%S%z"/c\ strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime!)' \
{} \; && \
\
# 4b) Patch swift-log-datadog: same localtime() optional issue
find /root/.cache/bazel -path '*external/swift-log-datadog/Sources/DataDogLog/Extensions/String+Timestamp.swift' \
-print -exec sed -i \
'/"%Y-%m-%dT%H:%M:%S%z"/c\ strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime!)' \
{} \; && \
# 5) Patch SwiftNIOSSL: FILEPointer? -> FILEPointer for fclose
find /root/.cache/bazel -path '*external/SwiftNIOSSL/Sources/NIOSSL/PosixPort.swift' \
-print -exec sed -i \
-e 's/FILEPointer?) -> CInt/FILEPointer) -> CInt/' \
{} \; && \
\
# 6) Patch ZIPFoundation in the repo: fseeko on optional FILE*
sed -i \
's/fseeko(result, 0, SEEK_END)/fseeko(result!, 0, SEEK_END)/' \
Vendors/ZIPFoundation/Sources/ZIPFoundation/Archive+MemoryFile.swift && \
\
# 7) Final Bazel build with warnings suppressed
bazel build Apps:gRPCServerCLI \
--keep_going \
--spawn_strategy=local \
--compilation_mode=opt \
--copt=-w \
--cxxopt=-w \
--host_copt=-w \
--host_cxxopt=-w \
--swiftcopt=-suppress-warnings
EXPOSE 7859
ENTRYPOINT ["/usr/local/src/draw-things-community/bazel-bin/Apps/gRPCServerCLI"]
```
0 条评论