@@ -8,6 +8,11 @@ ONEAPI_VARS?=/opt/intel/oneapi/setvars.sh
88# keep standard at C11 and C++11
99CXXFLAGS = -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
1010
11+ GOCMD? =go
12+ CGO_LDFLAGS? =
13+ GO_TAGS? =
14+ LD_FLAGS? =
15+
1116# Disable Shared libs as we are linking on static gRPC and we can't mix shared and static
1217CMAKE_ARGS+=-DBUILD_SHARED_LIBS =OFF
1318
@@ -21,7 +26,7 @@ else ifeq ($(BUILD_TYPE),openblas)
2126# If build type is clblas (openCL) we set -DGGML_CLBLAST=ON -DCLBlast_DIR=/some/path
2227else ifeq ($(BUILD_TYPE),clblas)
2328 CMAKE_ARGS+=-DGGML_CLBLAST=ON -DCLBlast_DIR=/some/path
24- # If it's hipblas we do have also to set CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++
29+ # If it's hipblas we do have also to set CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++
2530else ifeq ($(BUILD_TYPE),hipblas)
2631 CMAKE_ARGS+=-DGGML_HIP=ON
2732# If it's OSX, DO NOT embed the metal library - -DGGML_METAL_EMBED_LIBRARY=ON requires further investigation
@@ -36,16 +41,35 @@ else ifeq ($(OS),Darwin)
3641 endif
3742endif
3843
39- # ifeq ($(BUILD_TYPE),sycl_f16)
40- # CMAKE_ARGS+=-DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON -DSD_SYCL=ON -DGGML_SYCL_F16=ON
41- # endif
44+ ifeq ($(BUILD_TYPE ) ,sycl_f16)
45+ CMAKE_ARGS+=-DGGML_SYCL=ON \
46+ -DCMAKE_C_COMPILER=icx \
47+ -DCMAKE_CXX_COMPILER=icpx \
48+ -DSD_SYCL=ON \
49+ -DGGML_SYCL_F16=ON
50+ CC=icx
51+ CXX=icpx
52+ CGO_LDFLAGS += -fsycl -L${DNNLROOT}/lib -ldnnl ${MKLROOT}/lib/intel64/libmkl_sycl.a -fiopenmp -fopenmp-targets=spir64 -lOpenCL
53+ CGO_LDFLAGS += $(shell pkg-config --libs mkl-static-lp64-gomp)
54+ CGO_CXXFLAGS += -fiopenmp -fopenmp-targets=spir64
55+ CGO_CXXFLAGS += $(shell pkg-config --cflags mkl-static-lp64-gomp )
56+ endif
4257
43- # ifeq ($(BUILD_TYPE),sycl_f32)
44- # CMAKE_ARGS+=-DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DSD_SYCL=ON
45- # endif
58+ ifeq ($(BUILD_TYPE ) ,sycl_f32)
59+ CMAKE_ARGS+=-DGGML_SYCL=ON \
60+ -DCMAKE_C_COMPILER=icx \
61+ -DCMAKE_CXX_COMPILER=icpx \
62+ -DSD_SYCL=ON
63+ CC=icx
64+ CXX=icpx
65+ CGO_LDFLAGS += -fsycl -L${DNNLROOT}/lib -ldnnl ${MKLROOT}/lib/intel64/libmkl_sycl.a -fiopenmp -fopenmp-targets=spir64 -lOpenCL
66+ CGO_LDFLAGS += $(shell pkg-config --libs mkl-static-lp64-gomp)
67+ CGO_CXXFLAGS += -fiopenmp -fopenmp-targets=spir64
68+ CGO_CXXFLAGS += $(shell pkg-config --cflags mkl-static-lp64-gomp )
69+ endif
4670
4771# warnings
48- CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
72+ # CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
4973
5074# Find all .a archives in ARCHIVE_DIR
5175# (ggml can have different backends cpu, cuda, etc., each backend generates a .a archive)
@@ -86,11 +110,24 @@ endif
86110 $(MAKE) $(COMBINED_LIB)
87111
88112gosd.o :
113+ ifneq (,$(findstring sycl,$(BUILD_TYPE ) ) )
114+ +bash -c "source $(ONEAPI_VARS); \
115+ $(CXX) $(CXXFLAGS) gosd.cpp -o gosd.o -c"
116+ else
89117 $(CXX) $(CXXFLAGS) gosd.cpp -o gosd.o -c
118+ endif
90119
91120libsd.a : gosd.o
92121 cp $(INCLUDE_PATH ) /build/libstable-diffusion.a ./libsd.a
93122 $(AR ) rcs libsd.a gosd.o
94123
124+ stablediffusion-ggml :
125+ CGO_LDFLAGS=" $( CGO_LDFLAGS) " C_INCLUDE_PATH=" $( INCLUDE_PATH) " LIBRARY_PATH=" $( LIBRARY_PATH) " \
126+ CC=" $( CC) " CXX=" $( CXX) " CGO_CXXFLAGS=" $( CGO_CXXFLAGS) " \
127+ $(GOCMD ) build -ldflags " $( LD_FLAGS) " -tags " $( GO_TAGS) " -o ../../../../backend-assets/grpc/stablediffusion-ggml ./
128+ ifneq ($(UPX ) ,)
129+ $(UPX) ../../../../backend-assets/grpc/stablediffusion-ggml
130+ endif
131+
95132clean :
96- rm -rf gosd.o libsd.a build $(COMBINED_LIB )
133+ rm -rf gosd.o libsd.a build $(COMBINED_LIB )
0 commit comments