Skip to content

Commit b150cb3

Browse files
committed
Support Moore Threads GPU
Signed-off-by: Xiaodong Ye <[email protected]>
1 parent ff89ba9 commit b150cb3

21 files changed

+1462
-18
lines changed

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,33 @@ if(CMAKE_HIP_COMPILER)
136136
endforeach()
137137
endif()
138138
endif()
139+
140+
if(NOT EXISTS $ENV{MUSA_PATH})
141+
if (NOT EXISTS /opt/musa)
142+
set(MUSA_PATH /usr/local/musa)
143+
else()
144+
set(MUSA_PATH /opt/musa)
145+
endif()
146+
else()
147+
set(MUSA_PATH $ENV{MUSA_PATH})
148+
endif()
149+
list(APPEND CMAKE_MODULE_PATH "${MUSA_PATH}/cmake")
150+
find_package(MUSAToolkit)
151+
if(MUSAToolkit_FOUND)
152+
if(NOT MUSA_ARCHITECTURES)
153+
set(MUSA_ARCHITECTURES "21;22;31")
154+
endif()
155+
156+
if(MUSA_ARCHITECTURES)
157+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-musa)
158+
set(OLLAMA_MUSA_INSTALL_DIR ${OLLAMA_INSTALL_DIR}/musa_v4)
159+
install(TARGETS ggml-musa
160+
RUNTIME_DEPENDENCIES
161+
DIRECTORIES ${MUSAToolkit_BIN_DIR} ${MUSAToolkit_LIBRARY_DIR}
162+
PRE_INCLUDE_REGEXES mublas musart musa
163+
PRE_EXCLUDE_REGEXES ".*"
164+
RUNTIME DESTINATION ${OLLAMA_MUSA_INSTALL_DIR} COMPONENT MUSA
165+
LIBRARY DESTINATION ${OLLAMA_MUSA_INSTALL_DIR} COMPONENT MUSA
166+
)
167+
endif()
168+
endif()

CMakePresets.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@
5353
"CMAKE_HIP_FLAGS": "-parallel-jobs=4",
5454
"AMDGPU_TARGETS": "gfx900;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102;gfx1151;gfx1200;gfx1201;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-"
5555
}
56+
},
57+
{
58+
"name": "MUSA",
59+
"inherits": [ "Default" ]
60+
},
61+
{
62+
"name": "MUSA 4",
63+
"inherits": [ "MUSA" ],
64+
"cacheVariables": {
65+
"MUSA_ARCHITECTURES": "21;22;31"
66+
}
5667
}
5768
],
5869
"buildPresets": [
@@ -95,6 +106,16 @@
95106
"name": "ROCm 6",
96107
"inherits": [ "ROCm" ],
97108
"configurePreset": "ROCm 6"
109+
},
110+
{
111+
"name": "MUSA",
112+
"configurePreset": "MUSA",
113+
"targets": [ "ggml-musa" ]
114+
},
115+
{
116+
"name": "MUSA 4",
117+
"inherits": [ "MUSA" ],
118+
"configurePreset": "MUSA 4"
98119
}
99120
]
100121
}

Dockerfile

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ARG ROCMVERSION=6.3.3
66
ARG JETPACK5VERSION=r35.4.1
77
ARG JETPACK6VERSION=r36.4.0
88
ARG CMAKEVERSION=3.31.2
9+
ARG MUSAVERSION=rc4.0.1
910

1011
# We require gcc v10 minimum. v10.3 has regressions, so the rockylinux 8.5 AppStream has the latest compatible version
1112
FROM --platform=linux/amd64 rocm/dev-almalinux-8:${ROCMVERSION}-complete AS base-amd64
@@ -100,21 +101,49 @@ COPY --from=jetpack-6 dist/lib/ollama /lib/ollama/cuda_jetpack6
100101
FROM scratch AS rocm
101102
COPY --from=rocm-6 dist/lib/ollama /lib/ollama
102103

104+
# Moore Threads (MUSA) build stages
105+
FROM --platform=linux/amd64 mthreads/musa:${MUSAVERSION}-mudnn-devel-ubuntu22.04 AS musa-4
106+
RUN apt-get update \
107+
&& apt-get install -y curl \
108+
&& apt-get clean \
109+
&& rm -rf /var/lib/apt/lists/*
110+
ARG CMAKEVERSION
111+
RUN curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-$(uname -m).tar.gz | tar xz -C /usr/local --strip-components 1
112+
COPY CMakeLists.txt CMakePresets.json .
113+
COPY ml/backend/ggml/ggml ml/backend/ggml/ggml
114+
ENV LDFLAGS=-s
115+
RUN --mount=type=cache,target=/root/.ccache \
116+
cmake --preset 'MUSA 4' \
117+
&& cmake --build --parallel --preset 'MUSA 4' \
118+
&& cmake --install build --component MUSA --strip --parallel 8
119+
120+
FROM scratch AS musa
121+
COPY --from=musa-4 dist/lib/ollama/musa_v4 /lib/ollama/musa_v4
122+
103123
FROM ${FLAVOR} AS archive
104124
COPY --from=cpu dist/lib/ollama /lib/ollama
105125
COPY --from=build /bin/ollama /bin/ollama
106126

107-
FROM ubuntu:24.04
127+
FROM ubuntu:22.04
108128
RUN apt-get update \
109129
&& apt-get install -y ca-certificates \
110130
&& apt-get clean \
111131
&& rm -rf /var/lib/apt/lists/*
132+
ARG FLAVOR
133+
RUN if [ "$FLAVOR" = "musa" ]; then \
134+
apt-get update \
135+
&& apt-get install -y libelf1 libnuma1 \
136+
&& apt-get clean \
137+
&& rm -rf /var/lib/apt/lists/*; \
138+
fi
112139
COPY --from=archive /bin /usr/bin
113140
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
114141
COPY --from=archive /lib/ollama /usr/lib/ollama
115142
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
116143
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
117144
ENV NVIDIA_VISIBLE_DEVICES=all
145+
ENV MTHREADS_DRIVER_CAPABILITIES=compute,utility
146+
ENV MTHREADS_VISIBLE_DEVICES=all
118147
ENV OLLAMA_HOST=0.0.0.0:11434
119148
EXPOSE 11434
120149
ENTRYPOINT ["/bin/ollama"]

LICENSE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
The ollama-musa from Moore Threads is licensed under the MIT License listed below.
2+
Copyright (c) 2025 Moore Threads Technology Co., Ltd ("Moore Threads"). All rights reserved.
3+
4+
-------------------------------------------------------------------------
5+
The following copyright statements and licenses apply to various open source software
6+
packages (or portions thereof) that are distributed with this ollama-musa. ollama-musa that
7+
includes this file does not necessarily use all the open source software packages referred
8+
to below and may also only use portions of a given package. Some open source software
9+
packages referred to below may have been modified by Moore Threads Technology Co., Ltd.
10+
-------------------------------------------------------------------------
11+
112
MIT License
213

314
Copyright (c) Ollama

0 commit comments

Comments
 (0)