Skip to content

Commit 0a7732c

Browse files
committed
feat(stablediffusion-ggml): respect build type
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 07655c0 commit 0a7732c

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

Makefile

+2-8
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,8 @@ sources/stablediffusion-ggml.cpp:
302302
git checkout $(STABLEDIFFUSION_GGML_VERSION) && \
303303
git submodule update --init --recursive --depth 1 --single-branch
304304

305-
sources/stablediffusion-ggml.cpp/build/libstable-diffusion.a: sources/stablediffusion-ggml.cpp
306-
cd sources/stablediffusion-ggml.cpp && \
307-
mkdir -p build && \
308-
cd build && \
309-
cmake $(CMAKE_ARGS) .. && \
310-
cmake --build . --config Release
311-
312-
backend/go/image/stablediffusion-ggml/libsd.a: sources/stablediffusion-ggml.cpp/build/libstable-diffusion.a
305+
backend/go/image/stablediffusion-ggml/libsd.a: sources/stablediffusion-ggml.cpp
306+
$(MAKE) -C backend/go/image/stablediffusion-ggml build/libstable-diffusion.a
313307
$(MAKE) -C backend/go/image/stablediffusion-ggml libsd.a
314308

315309
backend-assets/grpc/stablediffusion-ggml: backend/go/image/stablediffusion-ggml/libsd.a backend-assets/grpc

backend/go/image/stablediffusion-ggml/Makefile

+45-3
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,62 @@ INCLUDE_PATH := $(abspath ./)
22
LIBRARY_PATH := $(abspath ./)
33

44
AR?=ar
5-
5+
CMAKE_ARGS?=
66
BUILD_TYPE?=
77
# keep standard at C11 and C++11
88
CXXFLAGS = -I. -I$(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp/thirdparty -I$(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp/ggml/include -I$(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp -O3 -DNDEBUG -std=c++17 -fPIC
99

10+
# Disable Shared libs as we are linking on static gRPC and we can't mix shared and static
11+
CMAKE_ARGS+=-DBUILD_SHARED_LIBS=OFF
12+
13+
# If build type is cublas, then we set -DGGML_CUDA=ON to CMAKE_ARGS automatically
14+
ifeq ($(BUILD_TYPE),cublas)
15+
CMAKE_ARGS+=-DGGML_CUDA=ON
16+
# If build type is openblas then we set -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS
17+
# to CMAKE_ARGS automatically
18+
else ifeq ($(BUILD_TYPE),openblas)
19+
CMAKE_ARGS+=-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS
20+
# If build type is clblas (openCL) we set -DGGML_CLBLAST=ON -DCLBlast_DIR=/some/path
21+
else ifeq ($(BUILD_TYPE),clblas)
22+
CMAKE_ARGS+=-DGGML_CLBLAST=ON -DCLBlast_DIR=/some/path
23+
# If it's hipblas we do have also to set CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++
24+
else ifeq ($(BUILD_TYPE),hipblas)
25+
CMAKE_ARGS+=-DGGML_HIP=ON
26+
# If it's OSX, DO NOT embed the metal library - -DGGML_METAL_EMBED_LIBRARY=ON requires further investigation
27+
# But if it's OSX without metal, disable it here
28+
else ifeq ($(OS),Darwin)
29+
ifneq ($(BUILD_TYPE),metal)
30+
CMAKE_ARGS+=-DGGML_METAL=OFF
31+
else
32+
CMAKE_ARGS+=-DGGML_METAL=ON
33+
CMAKE_ARGS+=-DGGML_METAL_EMBED_LIBRARY=ON
34+
TARGET+=--target ggml-metal
35+
endif
36+
endif
37+
38+
ifeq ($(BUILD_TYPE),sycl_f16)
39+
CMAKE_ARGS+=-DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON
40+
endif
41+
42+
ifeq ($(BUILD_TYPE),sycl_f32)
43+
CMAKE_ARGS+=-DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
44+
endif
45+
1046
# warnings
1147
CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
1248

49+
build/libstable-diffusion.a:
50+
mkdir -p build && \
51+
cd build && \
52+
cmake $(CMAKE_ARGS) ../../../../../sources/stablediffusion-ggml.cpp && \
53+
cmake --build . --config Release
54+
1355
gosd.o:
1456
$(CXX) $(CXXFLAGS) gosd.cpp -o gosd.o -c
1557

1658
libsd.a: gosd.o
17-
cp $(INCLUDE_PATH)/../../../../sources/stablediffusion-ggml.cpp/build/libstable-diffusion.a ./libsd.a
59+
cp $(INCLUDE_PATH)/build/libstable-diffusion.a ./libsd.a
1860
$(AR) rcs libsd.a gosd.o
1961

2062
clean:
21-
rm -f gosd.o libsd.a
63+
rm -f gosd.o libsd.a build

0 commit comments

Comments
 (0)